@@ -441,9 +441,6 @@ checkEquality(JsonbValue *jb1, JsonbValue *jb2, bool not)
441
441
return jperError ;
442
442
}
443
443
444
- if (jb1 -> type == jbvBinary )
445
- return jperError ;
446
-
447
444
switch (jb1 -> type )
448
445
{
449
446
case jbvNull :
@@ -494,8 +491,14 @@ checkEquality(JsonbValue *jb1, JsonbValue *jb2, bool not)
494
491
jb2 -> val .datetime .value ));
495
492
break ;
496
493
}
494
+
495
+ case jbvBinary :
496
+ case jbvObject :
497
+ case jbvArray :
498
+ return jperError ;
499
+
497
500
default :
498
- elog (ERROR ,"1Wrong state" );
501
+ elog (ERROR , "Unknown jsonb value type %d" , jb1 -> type );
499
502
}
500
503
501
504
return (not ^ eq ) ? jperOk : jperNotFound ;
@@ -1167,6 +1170,10 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1167
1170
if (JsonbType (jb ) == jbvObject )
1168
1171
{
1169
1172
JsonbValue * v , key ;
1173
+ JsonbValue obj ;
1174
+
1175
+ if (jb -> type == jbvObject )
1176
+ jb = JsonbWrapInBinary (jb , & obj );
1170
1177
1171
1178
key .type = jbvString ;
1172
1179
key .val .string .val = jspGetString (jsp , & key .val .string .len );
@@ -1216,18 +1223,16 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1216
1223
case jpiAnyArray :
1217
1224
if (JsonbType (jb ) == jbvArray )
1218
1225
{
1219
- JsonbIterator * it ;
1220
- int32 r ;
1221
- JsonbValue v ;
1222
-
1223
1226
hasNext = jspGetNext (jsp , & elem );
1224
- it = JsonbIteratorInit (jb -> val .binary .data );
1225
1227
1226
- while (( r = JsonbIteratorNext ( & it , & v , true)) != WJB_DONE )
1228
+ if ( jb -> type == jbvArray )
1227
1229
{
1228
- if (r == WJB_ELEM )
1230
+ JsonbValue * el = jb -> val .array .elems ;
1231
+ JsonbValue * last_el = el + jb -> val .array .nElems ;
1232
+
1233
+ for (; el < last_el ; el ++ )
1229
1234
{
1230
- res = recursiveExecuteNext (cxt , jsp , & elem , & v , found , true);
1235
+ res = recursiveExecuteNext (cxt , jsp , & elem , el , found , true);
1231
1236
1232
1237
if (jperIsError (res ))
1233
1238
break ;
@@ -1236,6 +1241,28 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1236
1241
break ;
1237
1242
}
1238
1243
}
1244
+ else
1245
+ {
1246
+ JsonbValue v ;
1247
+ JsonbIterator * it ;
1248
+ JsonbIteratorToken r ;
1249
+
1250
+ it = JsonbIteratorInit (jb -> val .binary .data );
1251
+
1252
+ while ((r = JsonbIteratorNext (& it , & v , true)) != WJB_DONE )
1253
+ {
1254
+ if (r == WJB_ELEM )
1255
+ {
1256
+ res = recursiveExecuteNext (cxt , jsp , & elem , & v , found , true);
1257
+
1258
+ if (jperIsError (res ))
1259
+ break ;
1260
+
1261
+ if (res == jperOk && !found )
1262
+ break ;
1263
+ }
1264
+ }
1265
+ }
1239
1266
}
1240
1267
else
1241
1268
res = jperMakeError (ERRCODE_JSON_ARRAY_NOT_FOUND );
@@ -1247,6 +1274,7 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1247
1274
int innermostArraySize = cxt -> innermostArraySize ;
1248
1275
int i ;
1249
1276
int size = JsonbArraySize (jb );
1277
+ bool binary = jb -> type == jbvBinary ;
1250
1278
1251
1279
cxt -> innermostArraySize = size ; /* for LAST evaluation */
1252
1280
@@ -1295,14 +1323,16 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1295
1323
1296
1324
for (index = index_from ; index <= index_to ; index ++ )
1297
1325
{
1298
- JsonbValue * v =
1326
+ JsonbValue * v = binary ?
1299
1327
getIthJsonbValueFromContainer (jb -> val .binary .data ,
1300
- (uint32 ) index );
1328
+ (uint32 ) index ) :
1329
+ & jb -> val .array .elems [index ];
1301
1330
1302
1331
if (v == NULL )
1303
1332
continue ;
1304
1333
1305
- res = recursiveExecuteNext (cxt , jsp , & elem , v , found , false);
1334
+ res = recursiveExecuteNext (cxt , jsp , & elem , v , found ,
1335
+ !binary );
1306
1336
1307
1337
if (jperIsError (res ))
1308
1338
break ;
@@ -1360,6 +1390,10 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1360
1390
JsonbIterator * it ;
1361
1391
int32 r ;
1362
1392
JsonbValue v ;
1393
+ JsonbValue bin ;
1394
+
1395
+ if (jb -> type == jbvObject )
1396
+ jb = JsonbWrapInBinary (jb , & bin );
1363
1397
1364
1398
hasNext = jspGetNext (jsp , & elem );
1365
1399
it = JsonbIteratorInit (jb -> val .binary .data );
@@ -1409,25 +1443,30 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1409
1443
res = recursiveExecuteNext (cxt , jsp , NULL , jb , found , true);
1410
1444
break ;
1411
1445
case jpiAny :
1412
- {
1413
- bool hasNext = jspGetNext (jsp , & elem );
1414
-
1415
- /* first try without any intermediate steps */
1416
- if (jsp -> content .anybounds .first == 0 )
1417
1446
{
1418
- res = recursiveExecuteNext ( cxt , jsp , & elem , jb , found , true) ;
1447
+ JsonbValue jbvbuf ;
1419
1448
1420
- if (res == jperOk && !found )
1421
- break ;
1422
- }
1449
+ hasNext = jspGetNext (jsp , & elem );
1423
1450
1424
- if (jb -> type == jbvBinary )
1425
- res = recursiveAny (cxt , hasNext ? & elem : NULL , jb , found ,
1426
- 1 ,
1427
- jsp -> content .anybounds .first ,
1428
- jsp -> content .anybounds .last );
1429
- break ;
1430
- }
1451
+ /* first try without any intermediate steps */
1452
+ if (jsp -> content .anybounds .first == 0 )
1453
+ {
1454
+ res = recursiveExecuteNext (cxt , jsp , & elem , jb , found , true);
1455
+
1456
+ if (res == jperOk && !found )
1457
+ break ;
1458
+ }
1459
+
1460
+ if (jb -> type == jbvArray || jb -> type == jbvObject )
1461
+ jb = JsonbWrapInBinary (jb , & jbvbuf );
1462
+
1463
+ if (jb -> type == jbvBinary )
1464
+ res = recursiveAny (cxt , hasNext ? & elem : NULL , jb , found ,
1465
+ 1 ,
1466
+ jsp -> content .anybounds .first ,
1467
+ jsp -> content .anybounds .last );
1468
+ break ;
1469
+ }
1431
1470
case jpiExists :
1432
1471
jspGetArg (jsp , & elem );
1433
1472
res = recursiveExecute (cxt , & elem , jb , NULL );
@@ -1688,6 +1727,7 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1688
1727
else
1689
1728
{
1690
1729
int32 r ;
1730
+ JsonbValue bin ;
1691
1731
JsonbValue key ;
1692
1732
JsonbValue val ;
1693
1733
JsonbValue obj ;
@@ -1698,7 +1738,9 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1698
1738
1699
1739
hasNext = jspGetNext (jsp , & elem );
1700
1740
1701
- if (!JsonContainerSize (jb -> val .binary .data ))
1741
+ if (jb -> type == jbvBinary
1742
+ ? !JsonContainerSize (jb -> val .binary .data )
1743
+ : !jb -> val .object .nPairs )
1702
1744
{
1703
1745
res = jperNotFound ;
1704
1746
break ;
@@ -1715,6 +1757,9 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1715
1757
valstr .val .string .val = "value" ;
1716
1758
valstr .val .string .len = 5 ;
1717
1759
1760
+ if (jb -> type == jbvObject )
1761
+ jb = JsonbWrapInBinary (jb , & bin );
1762
+
1718
1763
it = JsonbIteratorInit (jb -> val .binary .data );
1719
1764
1720
1765
while ((r = JsonbIteratorNext (& it , & key , true)) != WJB_DONE )
@@ -1774,24 +1819,43 @@ recursiveExecuteUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1774
1819
{
1775
1820
if (cxt -> lax && JsonbType (jb ) == jbvArray )
1776
1821
{
1777
- JsonbValue v ;
1778
- JsonbIterator * it ;
1779
- JsonbIteratorToken tok ;
1780
1822
JsonPathExecResult res = jperNotFound ;
1781
1823
1782
- it = JsonbIteratorInit (jb -> val .binary .data );
1783
-
1784
- while ((tok = JsonbIteratorNext (& it , & v , true)) != WJB_DONE )
1824
+ if (jb -> type == jbvArray )
1785
1825
{
1786
- if (tok == WJB_ELEM )
1826
+ JsonbValue * elem = jb -> val .array .elems ;
1827
+ JsonbValue * last = elem + jb -> val .array .nElems ;
1828
+
1829
+ for (; elem < last ; elem ++ )
1787
1830
{
1788
- res = recursiveExecuteNoUnwrap (cxt , jsp , & v , found );
1831
+ res = recursiveExecuteNoUnwrap (cxt , jsp , elem , found );
1832
+
1789
1833
if (jperIsError (res ))
1790
1834
break ;
1791
1835
if (res == jperOk && !found )
1792
1836
break ;
1793
1837
}
1794
1838
}
1839
+ else
1840
+ {
1841
+ JsonbValue v ;
1842
+ JsonbIterator * it ;
1843
+ JsonbIteratorToken tok ;
1844
+
1845
+ it = JsonbIteratorInit (jb -> val .binary .data );
1846
+
1847
+ while ((tok = JsonbIteratorNext (& it , & v , true)) != WJB_DONE )
1848
+ {
1849
+ if (tok == WJB_ELEM )
1850
+ {
1851
+ res = recursiveExecuteNoUnwrap (cxt , jsp , & v , found );
1852
+ if (jperIsError (res ))
1853
+ break ;
1854
+ if (res == jperOk && !found )
1855
+ break ;
1856
+ }
1857
+ }
1858
+ }
1795
1859
1796
1860
return res ;
1797
1861
}
@@ -2139,10 +2203,15 @@ wrapItemsInArray(const JsonValueList *items)
2139
2203
2140
2204
while ((jbv = JsonValueListNext (items , & it )))
2141
2205
{
2206
+ JsonbValue bin ;
2207
+
2142
2208
if (jbv -> type == jbvBinary &&
2143
2209
JsonContainerIsScalar (jbv -> val .binary .data ))
2144
2210
JsonbExtractScalar (jbv -> val .binary .data , jbv );
2145
2211
2212
+ if (jbv -> type == jbvObject || jbv -> type == jbvArray )
2213
+ jbv = JsonbWrapInBinary (jbv , & bin );
2214
+
2146
2215
pushJsonbValue (& ps , WJB_ELEM , jbv );
2147
2216
}
2148
2217
0 commit comments