Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e5450ba

Browse files
author
Nikita Glukhov
committed
Add jsonpath JsonbInitBinary()
1 parent 9843bef commit e5450ba

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
149149
return lfirst(it->lcell);
150150
}
151151

152+
static inline JsonbValue *
153+
JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
154+
{
155+
jbv->type = jbvBinary;
156+
jbv->val.binary.data = &jb->root;
157+
jbv->val.binary.len = VARSIZE_ANY_EXHDR(jb);
158+
159+
return jbv;
160+
}
161+
152162
/********************Execute functions for JsonPath***************************/
153163

154164
/*
@@ -251,11 +261,7 @@ computeJsonPathVariable(JsonPathItem *variable, List *vars, JsonbValue *value)
251261
if (JB_ROOT_IS_SCALAR(jb))
252262
JsonbExtractScalar(&jb->root, value);
253263
else
254-
{
255-
value->type = jbvBinary;
256-
value->val.binary.data = &jb->root;
257-
value->val.binary.len = VARSIZE_ANY_EXHDR(jb);
258-
}
264+
JsonbInitBinary(value, jb);
259265
}
260266
break;
261267
default:
@@ -1896,8 +1902,7 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
18961902

18971903
jsonb = JsonbValueToJsonb(keyval);
18981904

1899-
obj.val.binary.data = &jsonb->root;
1900-
obj.val.binary.len = VARSIZE(jsonb) - VARHDRSZ;
1905+
JsonbInitBinary(&obj, jsonb);
19011906

19021907
res = recursiveExecuteNext(cxt, jsp, &elem, &obj, found, true);
19031908

@@ -2026,15 +2031,11 @@ executeJsonPath(JsonPath *path, List *vars, Jsonb *json, JsonValueList *foundJso
20262031
JsonPathItem jsp;
20272032
JsonbValue jbv;
20282033

2029-
jbv.type = jbvBinary;
2030-
jbv.val.binary.data = &json->root;
2031-
jbv.val.binary.len = VARSIZE_ANY_EXHDR(json);
2032-
20332034
jspInit(&jsp, path);
20342035

20352036
cxt.vars = vars;
20362037
cxt.lax = (path->header & JSONPATH_LAX) != 0;
2037-
cxt.root = &jbv;
2038+
cxt.root = JsonbInitBinary(&jbv, json);
20382039
cxt.innermostArraySize = -1;
20392040

20402041
if (!cxt.lax && !foundJson)

0 commit comments

Comments
 (0)