@@ -132,6 +132,9 @@ JsonValueListGetList(JsonValueList *jvl)
132
132
return jvl -> list ;
133
133
}
134
134
135
+ /*
136
+ * Get the next item from the sequence advancing iterator.
137
+ */
135
138
static inline JsonbValue *
136
139
JsonValueListNext (const JsonValueList * jvl , JsonValueListIterator * it )
137
140
{
@@ -160,6 +163,9 @@ JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
160
163
return lfirst (it -> lcell );
161
164
}
162
165
166
+ /*
167
+ * Initialize a binary JsonbValue with the given jsonb container.
168
+ */
163
169
static inline JsonbValue *
164
170
JsonbInitBinary (JsonbValue * jbv , Jsonb * jb )
165
171
{
@@ -170,6 +176,10 @@ JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
170
176
return jbv ;
171
177
}
172
178
179
+ /*
180
+ * Transform a JsonbValue into a binary JsonbValue by encoding it to a
181
+ * binary jsonb container.
182
+ */
173
183
static inline JsonbValue *
174
184
JsonbWrapInBinary (JsonbValue * jbv , JsonbValue * out )
175
185
{
@@ -358,6 +368,9 @@ JsonbType(JsonbValue *jb)
358
368
return type ;
359
369
}
360
370
371
+ /*
372
+ * Get the type name of a SQL/JSON item.
373
+ */
361
374
static const char *
362
375
JsonbTypeName (JsonbValue * jb )
363
376
{
@@ -415,6 +428,9 @@ JsonbTypeName(JsonbValue *jb)
415
428
}
416
429
}
417
430
431
+ /*
432
+ * Returns the size of an array item, or -1 if item is not an array.
433
+ */
418
434
static int
419
435
JsonbArraySize (JsonbValue * jb )
420
436
{
@@ -432,6 +448,9 @@ JsonbArraySize(JsonbValue *jb)
432
448
return -1 ;
433
449
}
434
450
451
+ /*
452
+ * Compare two numerics.
453
+ */
435
454
static int
436
455
compareNumeric (Numeric a , Numeric b )
437
456
{
@@ -444,6 +463,10 @@ compareNumeric(Numeric a, Numeric b)
444
463
);
445
464
}
446
465
466
+ /*
467
+ * Cross-type comparison of two datetime SQL/JSON items. If items are
468
+ * uncomparable, 'error' flag is set.
469
+ */
447
470
static int
448
471
compareDatetime (Datum val1 , Oid typid1 , Datum val2 , Oid typid2 , bool * error )
449
472
{
@@ -556,6 +579,9 @@ compareDatetime(Datum val1, Oid typid1, Datum val2, Oid typid2, bool *error)
556
579
return DatumGetInt32 (DirectFunctionCall2 (cmpfunc , val1 , val2 ));
557
580
}
558
581
582
+ /*
583
+ * Check equality of two SLQ/JSON items of the same type.
584
+ */
559
585
static inline JsonPathBool
560
586
checkEquality (JsonbValue * jb1 , JsonbValue * jb2 , bool not )
561
587
{
@@ -613,6 +639,9 @@ checkEquality(JsonbValue *jb1, JsonbValue *jb2, bool not)
613
639
return (not ^ eq ) ? jpbTrue : jpbFalse ;
614
640
}
615
641
642
+ /*
643
+ * Compare two SLQ/JSON items using comparison operation 'op'.
644
+ */
616
645
static JsonPathBool
617
646
makeCompare (int32 op , JsonbValue * jb1 , JsonbValue * jb2 )
618
647
{
@@ -701,6 +730,9 @@ copyJsonbValue(JsonbValue *src)
701
730
return dst ;
702
731
}
703
732
733
+ /*
734
+ * Execute next jsonpath item if it does exist.
735
+ */
704
736
static inline JsonPathExecResult
705
737
recursiveExecuteNext (JsonPathExecContext * cxt ,
706
738
JsonPathItem * cur , JsonPathItem * next ,
@@ -728,6 +760,10 @@ recursiveExecuteNext(JsonPathExecContext *cxt,
728
760
return jperOk ;
729
761
}
730
762
763
+ /*
764
+ * Execute jsonpath expression and automatically unwrap each array item from
765
+ * the resulting sequence in lax mode.
766
+ */
731
767
static inline JsonPathExecResult
732
768
recursiveExecuteAndUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
733
769
JsonbValue * jb , JsonValueList * found )
@@ -775,6 +811,12 @@ recursiveExecuteAndUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
775
811
return recursiveExecute (cxt , jsp , jb , found );
776
812
}
777
813
814
+ /*
815
+ * Execute comparison expression. True is returned only if found any pair of
816
+ * items from the left and right operand's sequences which is satisfying
817
+ * condition. In strict mode all pairs should be comparable, otherwise an error
818
+ * is returned.
819
+ */
778
820
static JsonPathBool
779
821
executeComparison (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb )
780
822
{
@@ -852,6 +894,10 @@ executeComparison(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb)
852
894
return jpbFalse ;
853
895
}
854
896
897
+ /*
898
+ * Execute binary arithemitc expression on singleton numeric operands.
899
+ * Array operands are automatically unwrapped in lax mode.
900
+ */
855
901
static JsonPathExecResult
856
902
executeBinaryArithmExpr (JsonPathExecContext * cxt , JsonPathItem * jsp ,
857
903
JsonbValue * jb , JsonValueList * found )
@@ -961,6 +1007,10 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
961
1007
return recursiveExecuteNext (cxt , jsp , & elem , lval , found , false);
962
1008
}
963
1009
1010
+ /*
1011
+ * Execute unary arithmetic expression for each numeric item in its operand's
1012
+ * sequence. Array operand is automatically unwrapped in lax mode.
1013
+ */
964
1014
static JsonPathExecResult
965
1015
executeUnaryArithmExpr (JsonPathExecContext * cxt , JsonPathItem * jsp ,
966
1016
JsonbValue * jb , JsonValueList * found )
@@ -1095,6 +1145,10 @@ recursiveAny(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
1095
1145
return res ;
1096
1146
}
1097
1147
1148
+ /*
1149
+ * Execute array subscript expression and convert resulting numeric item to the
1150
+ * integer type with truncation.
1151
+ */
1098
1152
static JsonPathExecResult
1099
1153
getArrayIndex (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb ,
1100
1154
int32 * index )
@@ -2136,6 +2190,9 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
2136
2190
return res ;
2137
2191
}
2138
2192
2193
+ /*
2194
+ * Unwrap current array item and execute jsonpath for each of its elements.
2195
+ */
2139
2196
static JsonPathExecResult
2140
2197
recursiveExecuteUnwrapArray (JsonPathExecContext * cxt , JsonPathItem * jsp ,
2141
2198
JsonbValue * jb , JsonValueList * found )
@@ -2181,6 +2238,9 @@ recursiveExecuteUnwrapArray(JsonPathExecContext *cxt, JsonPathItem *jsp,
2181
2238
return res ;
2182
2239
}
2183
2240
2241
+ /*
2242
+ * Execute jsonpath with unwrapping of current item if it is an array.
2243
+ */
2184
2244
static inline JsonPathExecResult
2185
2245
recursiveExecuteUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
2186
2246
JsonbValue * jb , JsonValueList * found )
@@ -2233,6 +2293,9 @@ wrapItem(JsonbValue *jbv)
2233
2293
return JsonbWrapInBinary (jbv , NULL );
2234
2294
}
2235
2295
2296
+ /*
2297
+ * Execute jsonpath with automatic unwrapping of current item in lax mode.
2298
+ */
2236
2299
static inline JsonPathExecResult
2237
2300
recursiveExecute (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb ,
2238
2301
JsonValueList * found )
0 commit comments