-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathjson_fdw.h
More file actions
129 lines (102 loc) · 3.37 KB
/
json_fdw.h
File metadata and controls
129 lines (102 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*-------------------------------------------------------------------------
*
* json_fdw.h
*
* Type and function declarations for JSON foreign data wrapper.
*
* Copyright (c) 2013, Citus Data, Inc.
*
* $Id$
*
*-------------------------------------------------------------------------
*/
#ifndef JSON_FDW_H
#define JSON_FDW_H
#include "fmgr.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_foreign_table.h"
#include "utils/hsearch.h"
#include "nodes/pg_list.h"
#include "utils/rel.h"
#include "curlapi.h"
/* Defines for valid option names and default values */
#define OPTION_NAME_FILENAME "filename"
#define OPTION_NAME_MAX_ERROR_COUNT "max_error_count"
#define DEFAULT_MAX_ERROR_COUNT 0
#define OPTION_NAME_HTTP_POST_VARS "http_post_vars"
#define OPTION_NAME_ROM_URL "rom_url"
#define OPTION_NAME_ROM_PATH "rom_path"
#define JSON_TUPLE_COST_MULTIPLIER 10
#define ERROR_BUFFER_SIZE 1024
#define READ_BUFFER_SIZE 4096
#define GZIP_FILE_EXTENSION ".gz"
#define HDFS_BLOCK_PREFIX "blk_"
#define HDFS_BLOCK_PREFIX_LENGTH 4
/*
* JsonValidOption keeps an option name and a context. When an option is passed
* into json_fdw objects (server and foreign table), we compare this option's
* name and context against those of valid options.
*/
typedef struct JsonValidOption
{
const char *optionName;
Oid optionContextId;
} JsonValidOption;
/*
* JsonFdwOptions holds the option values to be used when reading and parsing
* the json file. To resolve these values, we first check foreign table's
* options, and if not present, we then fall back to the default values
* specified above.
*/
typedef struct JsonFdwOptions
{
char const *filename;
int32 maxErrorCount;
char const *pHttpPostVars;
char const *pRomUrl;
char const *pRomPath;
} JsonFdwOptions;
/*
* JsonFdwExecState keeps foreign data wrapper specific execution state that we
* create and hold onto when executing the query.
*/
typedef struct JsonFdwExecState
{
char const *filename; // on disk file name of json content
FILE *filePointer; // file pointer to on disk content
void *gzFilePointer; // gz file pointe to on disk content
uint32 maxErrorCount;
uint32 errorCount;
uint32 currentLineNumber;
HTAB *columnMappingHash;
cfr_t *pCfr; // curl fetch result
} JsonFdwExecState;
typedef struct _jfmes_t
{
Relation rel; // relcache entry for the foriegn table
int p_nums; // number of parameters to transmit
FmgrInfo *p_flinfo; // output conversion functions for them
List *retrieved_attrs; // list of target attribute members
List *retrieved_names; // list of target attribute names
List *table_options;
char const *pUrl; // put url
MemoryContext temp_cxt; // context for per-tuple temp data
} jfmes_t; // Json Fdw Modify Exec State Type
/*
* ColumnMapping reprents a hash table entry that maps a column name to column
* related information. We construct these hash table entries to speed up the
* conversion from JSON documents to PostgreSQL tuples; and each hash entry maps
* the column name to the column's tuple index and its type-related information.
*/
typedef struct ColumnMapping
{
char columnName[NAMEDATALEN];
uint32 columnIndex;
Oid columnTypeId;
int32 columnTypeMod;
Oid columnArrayTypeId;
} ColumnMapping;
/* Function declarations for foreign data wrapper */
extern Datum json_fdw_handler(PG_FUNCTION_ARGS);
extern Datum json_fdw_validator(PG_FUNCTION_ARGS);
#endif /* JSON_FDW_H */