@@ -121,6 +121,9 @@ JsonValueListGetList(JsonValueList *jvl)
121
121
return jvl -> list ;
122
122
}
123
123
124
+ /*
125
+ * Get the next item from the sequence advancing iterator.
126
+ */
124
127
static inline JsonbValue *
125
128
JsonValueListNext (const JsonValueList * jvl , JsonValueListIterator * it )
126
129
{
@@ -149,6 +152,9 @@ JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
149
152
return lfirst (it -> lcell );
150
153
}
151
154
155
+ /*
156
+ * Initialize a binary JsonbValue with the given jsonb container.
157
+ */
152
158
static inline JsonbValue *
153
159
JsonbInitBinary (JsonbValue * jbv , Jsonb * jb )
154
160
{
@@ -159,6 +165,10 @@ JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
159
165
return jbv ;
160
166
}
161
167
168
+ /*
169
+ * Transform a JsonbValue into a binary JsonbValue by encoding it to a
170
+ * binary jsonb container.
171
+ */
162
172
static inline JsonbValue *
163
173
JsonbWrapInBinary (JsonbValue * jbv , JsonbValue * out )
164
174
{
@@ -366,6 +376,9 @@ JsonbType(JsonbValue *jb)
366
376
return type ;
367
377
}
368
378
379
+ /*
380
+ * Get the type name of a SQL/JSON item.
381
+ */
369
382
static const char *
370
383
JsonbTypeName (JsonbValue * jb )
371
384
{
@@ -423,6 +436,9 @@ JsonbTypeName(JsonbValue *jb)
423
436
}
424
437
}
425
438
439
+ /*
440
+ * Returns the size of an array item, or -1 if item is not an array.
441
+ */
426
442
static int
427
443
JsonbArraySize (JsonbValue * jb )
428
444
{
@@ -440,6 +456,9 @@ JsonbArraySize(JsonbValue *jb)
440
456
return -1 ;
441
457
}
442
458
459
+ /*
460
+ * Compare two numerics.
461
+ */
443
462
static int
444
463
compareNumeric (Numeric a , Numeric b )
445
464
{
@@ -452,6 +471,10 @@ compareNumeric(Numeric a, Numeric b)
452
471
);
453
472
}
454
473
474
+ /*
475
+ * Cross-type comparison of two datetime SQL/JSON items. If items are
476
+ * uncomparable, 'error' flag is set.
477
+ */
455
478
static int
456
479
compareDatetime (Datum val1 , Oid typid1 , Datum val2 , Oid typid2 , bool * error )
457
480
{
@@ -564,6 +587,9 @@ compareDatetime(Datum val1, Oid typid1, Datum val2, Oid typid2, bool *error)
564
587
return DatumGetInt32 (DirectFunctionCall2 (cmpfunc , val1 , val2 ));
565
588
}
566
589
590
+ /*
591
+ * Check equality of two SLQ/JSON items of the same type.
592
+ */
567
593
static inline JsonPathBool
568
594
checkEquality (JsonbValue * jb1 , JsonbValue * jb2 , bool not )
569
595
{
@@ -621,6 +647,9 @@ checkEquality(JsonbValue *jb1, JsonbValue *jb2, bool not)
621
647
return (not ^ eq ) ? jpbTrue : jpbFalse ;
622
648
}
623
649
650
+ /*
651
+ * Compare two SLQ/JSON items using comparison operation 'op'.
652
+ */
624
653
static JsonPathBool
625
654
makeCompare (int32 op , JsonbValue * jb1 , JsonbValue * jb2 )
626
655
{
@@ -709,6 +738,9 @@ copyJsonbValue(JsonbValue *src)
709
738
return dst ;
710
739
}
711
740
741
+ /*
742
+ * Execute next jsonpath item if it does exist.
743
+ */
712
744
static inline JsonPathExecResult
713
745
recursiveExecuteNext (JsonPathExecContext * cxt ,
714
746
JsonPathItem * cur , JsonPathItem * next ,
@@ -736,6 +768,10 @@ recursiveExecuteNext(JsonPathExecContext *cxt,
736
768
return jperOk ;
737
769
}
738
770
771
+ /*
772
+ * Execute jsonpath expression and automatically unwrap each array item from
773
+ * the resulting sequence in lax mode.
774
+ */
739
775
static inline JsonPathExecResult
740
776
recursiveExecuteAndUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
741
777
JsonbValue * jb , JsonValueList * found )
@@ -783,6 +819,12 @@ recursiveExecuteAndUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
783
819
return recursiveExecute (cxt , jsp , jb , found );
784
820
}
785
821
822
+ /*
823
+ * Execute comparison expression. True is returned only if found any pair of
824
+ * items from the left and right operand's sequences which is satisfying
825
+ * condition. In strict mode all pairs should be comparable, otherwise an error
826
+ * is returned.
827
+ */
786
828
static JsonPathBool
787
829
executeComparison (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb )
788
830
{
@@ -860,6 +902,10 @@ executeComparison(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb)
860
902
return jpbFalse ;
861
903
}
862
904
905
+ /*
906
+ * Execute binary arithemitc expression on singleton numeric operands.
907
+ * Array operands are automatically unwrapped in lax mode.
908
+ */
863
909
static JsonPathExecResult
864
910
executeBinaryArithmExpr (JsonPathExecContext * cxt , JsonPathItem * jsp ,
865
911
JsonbValue * jb , JsonValueList * found )
@@ -969,6 +1015,10 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
969
1015
return recursiveExecuteNext (cxt , jsp , & elem , lval , found , false);
970
1016
}
971
1017
1018
+ /*
1019
+ * Execute unary arithmetic expression for each numeric item in its operand's
1020
+ * sequence. Array operand is automatically unwrapped in lax mode.
1021
+ */
972
1022
static JsonPathExecResult
973
1023
executeUnaryArithmExpr (JsonPathExecContext * cxt , JsonPathItem * jsp ,
974
1024
JsonbValue * jb , JsonValueList * found )
@@ -1103,6 +1153,10 @@ recursiveAny(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
1103
1153
return res ;
1104
1154
}
1105
1155
1156
+ /*
1157
+ * Execute array subscript expression and convert resulting numeric item to the
1158
+ * integer type with truncation.
1159
+ */
1106
1160
static JsonPathExecResult
1107
1161
getArrayIndex (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb ,
1108
1162
int32 * index )
@@ -2244,6 +2298,9 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
2244
2298
return res ;
2245
2299
}
2246
2300
2301
+ /*
2302
+ * Unwrap current array item and execute jsonpath for each of its elements.
2303
+ */
2247
2304
static JsonPathExecResult
2248
2305
recursiveExecuteUnwrapArray (JsonPathExecContext * cxt , JsonPathItem * jsp ,
2249
2306
JsonbValue * jb , JsonValueList * found )
@@ -2289,6 +2346,9 @@ recursiveExecuteUnwrapArray(JsonPathExecContext *cxt, JsonPathItem *jsp,
2289
2346
return res ;
2290
2347
}
2291
2348
2349
+ /*
2350
+ * Execute jsonpath with unwrapping of current item if it is an array.
2351
+ */
2292
2352
static inline JsonPathExecResult
2293
2353
recursiveExecuteUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
2294
2354
JsonbValue * jb , JsonValueList * found )
@@ -2341,6 +2401,9 @@ wrapItem(JsonbValue *jbv)
2341
2401
return JsonbWrapInBinary (jbv , NULL );
2342
2402
}
2343
2403
2404
+ /*
2405
+ * Execute jsonpath with automatic unwrapping of current item in lax mode.
2406
+ */
2344
2407
static inline JsonPathExecResult
2345
2408
recursiveExecute (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb ,
2346
2409
JsonValueList * found )
0 commit comments