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

Commit 0a15a39

Browse files
author
Nikita Glukhov
committed
Remove auto-wrapping in jsonpath recursiveExecute()
1 parent a1f1013 commit 0a15a39

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,17 +1581,23 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
15811581
}
15821582
}
15831583
}
1584+
else if (jspAutoWrap(cxt))
1585+
res = recursiveExecuteNext(cxt, jsp, NULL, jb, found, true);
15841586
else if (!jspIgnoreStructuralErrors(cxt))
15851587
res = jperMakeError(ERRCODE_JSON_ARRAY_NOT_FOUND);
15861588
break;
15871589

15881590
case jpiIndexArray:
1589-
if (JsonbType(jb) == jbvArray)
1591+
if (JsonbType(jb) == jbvArray || jspAutoWrap(cxt))
15901592
{
15911593
int innermostArraySize = cxt->innermostArraySize;
15921594
int i;
15931595
int size = JsonbArraySize(jb);
15941596
bool binary = jb->type == jbvBinary;
1597+
bool singleton = size < 0;
1598+
1599+
if (singleton)
1600+
size = 1;
15951601

15961602
cxt->innermostArraySize = size; /* for LAST evaluation */
15971603

@@ -1640,16 +1646,32 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
16401646

16411647
for (index = index_from; index <= index_to; index++)
16421648
{
1643-
JsonbValue *v = binary ?
1644-
getIthJsonbValueFromContainer(jb->val.binary.data,
1645-
(uint32) index) :
1646-
&jb->val.array.elems[index];
1649+
JsonbValue *v;
1650+
bool copy;
1651+
1652+
if (singleton)
1653+
{
1654+
v = jb;
1655+
copy = true;
1656+
}
1657+
else if (binary)
1658+
{
1659+
v = getIthJsonbValueFromContainer(jb->val.binary.data,
1660+
(uint32) index);
16471661

1648-
if (v == NULL)
1649-
continue;
1662+
if (v == NULL)
1663+
continue;
1664+
1665+
copy = false;
1666+
}
1667+
else
1668+
{
1669+
v = &jb->val.array.elems[index];
1670+
copy = true;
1671+
}
16501672

16511673
res = recursiveExecuteNext(cxt, jsp, &elem, v, found,
1652-
!binary);
1674+
copy);
16531675

16541676
if (jperIsError(res))
16551677
break;
@@ -2285,11 +2307,6 @@ recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
22852307
case jpiKeyValue:
22862308
return recursiveExecuteUnwrap(cxt, jsp, jb, found);
22872309

2288-
case jpiAnyArray:
2289-
case jpiIndexArray:
2290-
jb = wrapItem(jb);
2291-
break;
2292-
22932310
default:
22942311
break;
22952312
}

0 commit comments

Comments
 (0)