MCPcopy Create free account
hub / github.com/apache/cloudberry / jsonPathFromCstring

Function jsonPathFromCstring

src/backend/utils/adt/jsonpath.c:167–194  ·  view source on GitHub ↗

* Converts C-string to a jsonpath value. * * Uses jsonpath parser to turn string into an AST, then * flattenJsonPathParseItem() does second pass turning AST into binary * representation of jsonpath. */

Source from the content-addressed store, hash-verified

165 * representation of jsonpath.
166 */
167static Datum
168jsonPathFromCstring(char *in, int len)
169{
170 JsonPathParseResult *jsonpath = parsejsonpath(in, len);
171 JsonPath *res;
172 StringInfoData buf;
173
174 initStringInfo(&buf);
175 enlargeStringInfo(&buf, 4 * len /* estimation */ );
176
177 appendStringInfoSpaces(&buf, JSONPATH_HDRSZ);
178
179 if (!jsonpath)
180 ereport(ERROR,
181 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
182 errmsg("invalid input syntax for type %s: \"%s\"", "jsonpath",
183 in)));
184
185 flattenJsonPathParseItem(&buf, jsonpath->expr, 0, false);
186
187 res = (JsonPath *) buf.data;
188 SET_VARSIZE(res, buf.len);
189 res->header = JSONPATH_VERSION;
190 if (jsonpath->lax)
191 res->header |= JSONPATH_LAX;
192
193 PG_RETURN_JSONPATH_P(res);
194}
195
196/*
197 * Converts jsonpath value to a C-string.

Callers 2

jsonpath_inFunction · 0.85
jsonpath_recvFunction · 0.85

Calls 6

initStringInfoFunction · 0.85
enlargeStringInfoFunction · 0.85
appendStringInfoSpacesFunction · 0.85
flattenJsonPathParseItemFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected