@@ -121,6 +121,9 @@ JsonValueListGetList(JsonValueList *jvl)
121121 return jvl -> list ;
122122}
123123
124+ /*
125+ * Get the next item from the sequence advancing iterator.
126+ */
124127static inline JsonbValue *
125128JsonValueListNext (const JsonValueList * jvl , JsonValueListIterator * it )
126129{
@@ -149,6 +152,9 @@ JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
149152 return lfirst (it -> lcell );
150153}
151154
155+ /*
156+ * Initialize a binary JsonbValue with the given jsonb container.
157+ */
152158static inline JsonbValue *
153159JsonbInitBinary (JsonbValue * jbv , Jsonb * jb )
154160{
@@ -159,6 +165,10 @@ JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
159165 return jbv ;
160166}
161167
168+ /*
169+ * Transform a JsonbValue into a binary JsonbValue by encoding it to a
170+ * binary jsonb container.
171+ */
162172static inline JsonbValue *
163173JsonbWrapInBinary (JsonbValue * jbv , JsonbValue * out )
164174{
@@ -366,6 +376,9 @@ JsonbType(JsonbValue *jb)
366376 return type ;
367377}
368378
379+ /*
380+ * Get the type name of a SQL/JSON item.
381+ */
369382static const char *
370383JsonbTypeName (JsonbValue * jb )
371384{
@@ -423,6 +436,9 @@ JsonbTypeName(JsonbValue *jb)
423436 }
424437}
425438
439+ /*
440+ * Returns the size of an array item, or -1 if item is not an array.
441+ */
426442static int
427443JsonbArraySize (JsonbValue * jb )
428444{
@@ -440,6 +456,9 @@ JsonbArraySize(JsonbValue *jb)
440456 return -1 ;
441457}
442458
459+ /*
460+ * Compare two numerics.
461+ */
443462static int
444463compareNumeric (Numeric a , Numeric b )
445464{
@@ -452,6 +471,10 @@ compareNumeric(Numeric a, Numeric b)
452471 );
453472}
454473
474+ /*
475+ * Cross-type comparison of two datetime SQL/JSON items. If items are
476+ * uncomparable, 'error' flag is set.
477+ */
455478static int
456479compareDatetime (Datum val1 , Oid typid1 , Datum val2 , Oid typid2 , bool * error )
457480{
@@ -564,6 +587,9 @@ compareDatetime(Datum val1, Oid typid1, Datum val2, Oid typid2, bool *error)
564587 return DatumGetInt32 (DirectFunctionCall2 (cmpfunc , val1 , val2 ));
565588}
566589
590+ /*
591+ * Check equality of two SLQ/JSON items of the same type.
592+ */
567593static inline JsonPathBool
568594checkEquality (JsonbValue * jb1 , JsonbValue * jb2 , bool not )
569595{
@@ -621,6 +647,9 @@ checkEquality(JsonbValue *jb1, JsonbValue *jb2, bool not)
621647 return (not ^ eq ) ? jpbTrue : jpbFalse ;
622648}
623649
650+ /*
651+ * Compare two SLQ/JSON items using comparison operation 'op'.
652+ */
624653static JsonPathBool
625654makeCompare (int32 op , JsonbValue * jb1 , JsonbValue * jb2 )
626655{
@@ -709,6 +738,9 @@ copyJsonbValue(JsonbValue *src)
709738 return dst ;
710739}
711740
741+ /*
742+ * Execute next jsonpath item if it does exist.
743+ */
712744static inline JsonPathExecResult
713745recursiveExecuteNext (JsonPathExecContext * cxt ,
714746 JsonPathItem * cur , JsonPathItem * next ,
@@ -736,6 +768,10 @@ recursiveExecuteNext(JsonPathExecContext *cxt,
736768 return jperOk ;
737769}
738770
771+ /*
772+ * Execute jsonpath expression and automatically unwrap each array item from
773+ * the resulting sequence in lax mode.
774+ */
739775static inline JsonPathExecResult
740776recursiveExecuteAndUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
741777 JsonbValue * jb , JsonValueList * found )
@@ -783,6 +819,12 @@ recursiveExecuteAndUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
783819 return recursiveExecute (cxt , jsp , jb , found );
784820}
785821
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+ */
786828static JsonPathBool
787829executeComparison (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb )
788830{
@@ -860,6 +902,10 @@ executeComparison(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb)
860902 return jpbFalse ;
861903}
862904
905+ /*
906+ * Execute binary arithemitc expression on singleton numeric operands.
907+ * Array operands are automatically unwrapped in lax mode.
908+ */
863909static JsonPathExecResult
864910executeBinaryArithmExpr (JsonPathExecContext * cxt , JsonPathItem * jsp ,
865911 JsonbValue * jb , JsonValueList * found )
@@ -969,6 +1015,10 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
9691015 return recursiveExecuteNext (cxt , jsp , & elem , lval , found , false);
9701016}
9711017
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+ */
9721022static JsonPathExecResult
9731023executeUnaryArithmExpr (JsonPathExecContext * cxt , JsonPathItem * jsp ,
9741024 JsonbValue * jb , JsonValueList * found )
@@ -1103,6 +1153,10 @@ recursiveAny(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
11031153 return res ;
11041154}
11051155
1156+ /*
1157+ * Execute array subscript expression and convert resulting numeric item to the
1158+ * integer type with truncation.
1159+ */
11061160static JsonPathExecResult
11071161getArrayIndex (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb ,
11081162 int32 * index )
@@ -2244,6 +2298,9 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
22442298 return res ;
22452299}
22462300
2301+ /*
2302+ * Unwrap current array item and execute jsonpath for each of its elements.
2303+ */
22472304static JsonPathExecResult
22482305recursiveExecuteUnwrapArray (JsonPathExecContext * cxt , JsonPathItem * jsp ,
22492306 JsonbValue * jb , JsonValueList * found )
@@ -2289,6 +2346,9 @@ recursiveExecuteUnwrapArray(JsonPathExecContext *cxt, JsonPathItem *jsp,
22892346 return res ;
22902347}
22912348
2349+ /*
2350+ * Execute jsonpath with unwrapping of current item if it is an array.
2351+ */
22922352static inline JsonPathExecResult
22932353recursiveExecuteUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
22942354 JsonbValue * jb , JsonValueList * found )
@@ -2341,6 +2401,9 @@ wrapItem(JsonbValue *jbv)
23412401 return JsonbWrapInBinary (jbv , NULL );
23422402}
23432403
2404+ /*
2405+ * Execute jsonpath with automatic unwrapping of current item in lax mode.
2406+ */
23442407static inline JsonPathExecResult
23452408recursiveExecute (JsonPathExecContext * cxt , JsonPathItem * jsp , JsonbValue * jb ,
23462409 JsonValueList * found )
0 commit comments