|
42 | 42 | #define JB_PATH_CREATE_OR_INSERT \ |
43 | 43 | (JB_PATH_INSERT_BEFORE | JB_PATH_INSERT_AFTER | JB_PATH_CREATE) |
44 | 44 |
|
45 | | -/* semantic action functions for json_object_keys */ |
46 | | -static void okeys_object_field_start(void *state, char *fname, bool isnull); |
47 | | -static void okeys_array_start(void *state); |
48 | | -static void okeys_scalar(void *state, char *token, JsonTokenType tokentype); |
49 | | - |
50 | | -/* semantic action functions for json_get* functions */ |
51 | | -static void get_object_start(void *state); |
52 | | -static void get_object_end(void *state); |
53 | | -static void get_object_field_start(void *state, char *fname, bool isnull); |
54 | | -static void get_object_field_end(void *state, char *fname, bool isnull); |
55 | | -static void get_array_start(void *state); |
56 | | -static void get_array_end(void *state); |
57 | | -static void get_array_element_start(void *state, bool isnull); |
58 | | -static void get_array_element_end(void *state, bool isnull); |
59 | | -static void get_scalar(void *state, char *token, JsonTokenType tokentype); |
60 | | - |
61 | | -/* common worker function for json getter functions */ |
62 | | -static Datum get_path_all(FunctionCallInfo fcinfo, bool as_text); |
63 | | -static text *get_worker(text *json, char **tpath, int *ipath, int npath, |
64 | | - bool normalize_results); |
65 | | -static Datum get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text); |
66 | | - |
67 | | -/* semantic action functions for json_array_length */ |
68 | | -static void alen_object_start(void *state); |
69 | | -static void alen_scalar(void *state, char *token, JsonTokenType tokentype); |
70 | | -static void alen_array_element_start(void *state, bool isnull); |
71 | | - |
72 | | -/* common workers for json{b}_each* functions */ |
73 | | -static Datum each_worker(FunctionCallInfo fcinfo, bool as_text); |
74 | | -static Datum each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, |
75 | | - bool as_text); |
76 | | - |
77 | | -/* semantic action functions for json_each */ |
78 | | -static void each_object_field_start(void *state, char *fname, bool isnull); |
79 | | -static void each_object_field_end(void *state, char *fname, bool isnull); |
80 | | -static void each_array_start(void *state); |
81 | | -static void each_scalar(void *state, char *token, JsonTokenType tokentype); |
82 | | - |
83 | | -/* common workers for json{b}_array_elements_* functions */ |
84 | | -static Datum elements_worker(FunctionCallInfo fcinfo, const char *funcname, |
85 | | - bool as_text); |
86 | | -static Datum elements_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, |
87 | | - bool as_text); |
88 | | - |
89 | | -/* semantic action functions for json_array_elements */ |
90 | | -static void elements_object_start(void *state); |
91 | | -static void elements_array_element_start(void *state, bool isnull); |
92 | | -static void elements_array_element_end(void *state, bool isnull); |
93 | | -static void elements_scalar(void *state, char *token, JsonTokenType tokentype); |
94 | | - |
95 | | -/* turn a json object into a hash table */ |
96 | | -static HTAB *get_json_object_as_hash(text *json, const char *funcname); |
97 | | - |
98 | | -/* common worker for populate_record and to_record */ |
99 | | -static Datum populate_record_worker(FunctionCallInfo fcinfo, const char *funcname, |
100 | | - bool have_record_arg); |
101 | | - |
102 | | -/* semantic action functions for get_json_object_as_hash */ |
103 | | -static void hash_object_field_start(void *state, char *fname, bool isnull); |
104 | | -static void hash_object_field_end(void *state, char *fname, bool isnull); |
105 | | -static void hash_array_start(void *state); |
106 | | -static void hash_scalar(void *state, char *token, JsonTokenType tokentype); |
107 | | - |
108 | | -/* semantic action functions for populate_recordset */ |
109 | | -static void populate_recordset_object_field_start(void *state, char *fname, bool isnull); |
110 | | -static void populate_recordset_object_field_end(void *state, char *fname, bool isnull); |
111 | | -static void populate_recordset_scalar(void *state, char *token, JsonTokenType tokentype); |
112 | | -static void populate_recordset_object_start(void *state); |
113 | | -static void populate_recordset_object_end(void *state); |
114 | | -static void populate_recordset_array_start(void *state); |
115 | | -static void populate_recordset_array_element_start(void *state, bool isnull); |
116 | | - |
117 | | -/* semantic action functions for json_strip_nulls */ |
118 | | -static void sn_object_start(void *state); |
119 | | -static void sn_object_end(void *state); |
120 | | -static void sn_array_start(void *state); |
121 | | -static void sn_array_end(void *state); |
122 | | -static void sn_object_field_start(void *state, char *fname, bool isnull); |
123 | | -static void sn_array_element_start(void *state, bool isnull); |
124 | | -static void sn_scalar(void *state, char *token, JsonTokenType tokentype); |
125 | | - |
126 | | -/* worker function for populate_recordset and to_recordset */ |
127 | | -static Datum populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname, |
128 | | - bool have_record_arg); |
129 | | - |
130 | | -/* Worker that takes care of common setup for us */ |
131 | | -static JsonbValue *findJsonbValueFromContainerLen(JsonbContainer *container, |
132 | | - uint32 flags, |
133 | | - char *key, |
134 | | - uint32 keylen); |
135 | | - |
136 | | -/* functions supporting jsonb_delete, jsonb_set and jsonb_concat */ |
137 | | -static JsonbValue *IteratorConcat(JsonbIterator **it1, JsonbIterator **it2, |
138 | | - JsonbParseState **state); |
139 | | -static JsonbValue *setPath(JsonbIterator **it, Datum *path_elems, |
140 | | - bool *path_nulls, int path_len, |
141 | | - JsonbParseState **st, int level, Jsonb *newval, |
142 | | - int op_type); |
143 | | -static void setPathObject(JsonbIterator **it, Datum *path_elems, |
144 | | - bool *path_nulls, int path_len, JsonbParseState **st, |
145 | | - int level, |
146 | | - Jsonb *newval, uint32 npairs, int op_type); |
147 | | -static void setPathArray(JsonbIterator **it, Datum *path_elems, |
148 | | - bool *path_nulls, int path_len, JsonbParseState **st, |
149 | | - int level, Jsonb *newval, uint32 nelems, int op_type); |
150 | | -static void addJsonbToParseState(JsonbParseState **jbps, Jsonb *jb); |
151 | | - |
152 | 45 | /* state for json_object_keys */ |
153 | 46 | typedef struct OkeysState |
154 | 47 | { |
@@ -267,10 +160,118 @@ typedef struct StripnullState |
267 | 160 | bool skip_next_null; |
268 | 161 | } StripnullState; |
269 | 162 |
|
| 163 | +/* semantic action functions for json_object_keys */ |
| 164 | +static void okeys_object_field_start(void *state, char *fname, bool isnull); |
| 165 | +static void okeys_array_start(void *state); |
| 166 | +static void okeys_scalar(void *state, char *token, JsonTokenType tokentype); |
| 167 | + |
| 168 | +/* semantic action functions for json_get* functions */ |
| 169 | +static void get_object_start(void *state); |
| 170 | +static void get_object_end(void *state); |
| 171 | +static void get_object_field_start(void *state, char *fname, bool isnull); |
| 172 | +static void get_object_field_end(void *state, char *fname, bool isnull); |
| 173 | +static void get_array_start(void *state); |
| 174 | +static void get_array_end(void *state); |
| 175 | +static void get_array_element_start(void *state, bool isnull); |
| 176 | +static void get_array_element_end(void *state, bool isnull); |
| 177 | +static void get_scalar(void *state, char *token, JsonTokenType tokentype); |
| 178 | + |
| 179 | +/* common worker function for json getter functions */ |
| 180 | +static Datum get_path_all(FunctionCallInfo fcinfo, bool as_text); |
| 181 | +static text *get_worker(text *json, char **tpath, int *ipath, int npath, |
| 182 | + bool normalize_results); |
| 183 | +static Datum get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text); |
| 184 | + |
| 185 | +/* semantic action functions for json_array_length */ |
| 186 | +static void alen_object_start(void *state); |
| 187 | +static void alen_scalar(void *state, char *token, JsonTokenType tokentype); |
| 188 | +static void alen_array_element_start(void *state, bool isnull); |
| 189 | + |
| 190 | +/* common workers for json{b}_each* functions */ |
| 191 | +static Datum each_worker(FunctionCallInfo fcinfo, bool as_text); |
| 192 | +static Datum each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, |
| 193 | + bool as_text); |
| 194 | + |
| 195 | +/* semantic action functions for json_each */ |
| 196 | +static void each_object_field_start(void *state, char *fname, bool isnull); |
| 197 | +static void each_object_field_end(void *state, char *fname, bool isnull); |
| 198 | +static void each_array_start(void *state); |
| 199 | +static void each_scalar(void *state, char *token, JsonTokenType tokentype); |
| 200 | + |
| 201 | +/* common workers for json{b}_array_elements_* functions */ |
| 202 | +static Datum elements_worker(FunctionCallInfo fcinfo, const char *funcname, |
| 203 | + bool as_text); |
| 204 | +static Datum elements_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, |
| 205 | + bool as_text); |
| 206 | + |
| 207 | +/* semantic action functions for json_array_elements */ |
| 208 | +static void elements_object_start(void *state); |
| 209 | +static void elements_array_element_start(void *state, bool isnull); |
| 210 | +static void elements_array_element_end(void *state, bool isnull); |
| 211 | +static void elements_scalar(void *state, char *token, JsonTokenType tokentype); |
| 212 | + |
| 213 | +/* turn a json object into a hash table */ |
| 214 | +static HTAB *get_json_object_as_hash(text *json, const char *funcname); |
| 215 | + |
| 216 | +/* common worker for populate_record and to_record */ |
| 217 | +static Datum populate_record_worker(FunctionCallInfo fcinfo, const char *funcname, |
| 218 | + bool have_record_arg); |
| 219 | + |
| 220 | +/* semantic action functions for get_json_object_as_hash */ |
| 221 | +static void hash_object_field_start(void *state, char *fname, bool isnull); |
| 222 | +static void hash_object_field_end(void *state, char *fname, bool isnull); |
| 223 | +static void hash_array_start(void *state); |
| 224 | +static void hash_scalar(void *state, char *token, JsonTokenType tokentype); |
| 225 | + |
| 226 | +/* semantic action functions for populate_recordset */ |
| 227 | +static void populate_recordset_object_field_start(void *state, char *fname, bool isnull); |
| 228 | +static void populate_recordset_object_field_end(void *state, char *fname, bool isnull); |
| 229 | +static void populate_recordset_scalar(void *state, char *token, JsonTokenType tokentype); |
| 230 | +static void populate_recordset_object_start(void *state); |
| 231 | +static void populate_recordset_object_end(void *state); |
| 232 | +static void populate_recordset_array_start(void *state); |
| 233 | +static void populate_recordset_array_element_start(void *state, bool isnull); |
| 234 | + |
| 235 | +/* semantic action functions for json_strip_nulls */ |
| 236 | +static void sn_object_start(void *state); |
| 237 | +static void sn_object_end(void *state); |
| 238 | +static void sn_array_start(void *state); |
| 239 | +static void sn_array_end(void *state); |
| 240 | +static void sn_object_field_start(void *state, char *fname, bool isnull); |
| 241 | +static void sn_array_element_start(void *state, bool isnull); |
| 242 | +static void sn_scalar(void *state, char *token, JsonTokenType tokentype); |
| 243 | + |
270 | 244 | /* Turn a jsonb object into a record */ |
271 | 245 | static void make_row_from_rec_and_jsonb(Jsonb *element, |
272 | 246 | PopulateRecordsetState *state); |
273 | 247 |
|
| 248 | +/* worker function for populate_recordset and to_recordset */ |
| 249 | +static Datum populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname, |
| 250 | + bool have_record_arg); |
| 251 | + |
| 252 | +/* Worker that takes care of common setup for us */ |
| 253 | +static JsonbValue *findJsonbValueFromContainerLen(JsonbContainer *container, |
| 254 | + uint32 flags, |
| 255 | + char *key, |
| 256 | + uint32 keylen); |
| 257 | + |
| 258 | +/* functions supporting jsonb_delete, jsonb_set and jsonb_concat */ |
| 259 | +static JsonbValue *IteratorConcat(JsonbIterator **it1, JsonbIterator **it2, |
| 260 | + JsonbParseState **state); |
| 261 | +static JsonbValue *setPath(JsonbIterator **it, Datum *path_elems, |
| 262 | + bool *path_nulls, int path_len, |
| 263 | + JsonbParseState **st, int level, Jsonb *newval, |
| 264 | + int op_type); |
| 265 | +static void setPathObject(JsonbIterator **it, Datum *path_elems, |
| 266 | + bool *path_nulls, int path_len, JsonbParseState **st, |
| 267 | + int level, |
| 268 | + Jsonb *newval, uint32 npairs, int op_type); |
| 269 | +static void setPathArray(JsonbIterator **it, Datum *path_elems, |
| 270 | + bool *path_nulls, int path_len, JsonbParseState **st, |
| 271 | + int level, Jsonb *newval, uint32 nelems, int op_type); |
| 272 | +static void addJsonbToParseState(JsonbParseState **jbps, Jsonb *jb); |
| 273 | + |
| 274 | + |
274 | 275 | /* |
275 | 276 | * SQL function json_object_keys |
276 | 277 | * |
|
0 commit comments