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

Commit e3b5393

Browse files
author
Nikita Glukhov
committed
Add some jsonpath comments
1 parent 08294cb commit e3b5393

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ JsonValueListGetList(JsonValueList *jvl)
132132
return jvl->list;
133133
}
134134

135+
/*
136+
* Get the next item from the sequence advancing iterator.
137+
*/
135138
static inline JsonbValue *
136139
JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
137140
{
@@ -160,6 +163,9 @@ JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
160163
return lfirst(it->lcell);
161164
}
162165

166+
/*
167+
* Initialize a binary JsonbValue with the given jsonb container.
168+
*/
163169
static inline JsonbValue *
164170
JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
165171
{
@@ -170,6 +176,10 @@ JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
170176
return jbv;
171177
}
172178

179+
/*
180+
* Transform a JsonbValue into a binary JsonbValue by encoding it to a
181+
* binary jsonb container.
182+
*/
173183
static inline JsonbValue *
174184
JsonbWrapInBinary(JsonbValue *jbv, JsonbValue *out)
175185
{
@@ -358,6 +368,9 @@ JsonbType(JsonbValue *jb)
358368
return type;
359369
}
360370

371+
/*
372+
* Get the type name of a SQL/JSON item.
373+
*/
361374
static const char *
362375
JsonbTypeName(JsonbValue *jb)
363376
{
@@ -415,6 +428,9 @@ JsonbTypeName(JsonbValue *jb)
415428
}
416429
}
417430

431+
/*
432+
* Returns the size of an array item, or -1 if item is not an array.
433+
*/
418434
static int
419435
JsonbArraySize(JsonbValue *jb)
420436
{
@@ -432,6 +448,9 @@ JsonbArraySize(JsonbValue *jb)
432448
return -1;
433449
}
434450

451+
/*
452+
* Compare two numerics.
453+
*/
435454
static int
436455
compareNumeric(Numeric a, Numeric b)
437456
{
@@ -444,6 +463,10 @@ compareNumeric(Numeric a, Numeric b)
444463
);
445464
}
446465

466+
/*
467+
* Cross-type comparison of two datetime SQL/JSON items. If items are
468+
* uncomparable, 'error' flag is set.
469+
*/
447470
static int
448471
compareDatetime(Datum val1, Oid typid1, Datum val2, Oid typid2, bool *error)
449472
{
@@ -556,6 +579,9 @@ compareDatetime(Datum val1, Oid typid1, Datum val2, Oid typid2, bool *error)
556579
return DatumGetInt32(DirectFunctionCall2(cmpfunc, val1, val2));
557580
}
558581

582+
/*
583+
* Check equality of two SLQ/JSON items of the same type.
584+
*/
559585
static inline JsonPathBool
560586
checkEquality(JsonbValue *jb1, JsonbValue *jb2, bool not)
561587
{
@@ -613,6 +639,9 @@ checkEquality(JsonbValue *jb1, JsonbValue *jb2, bool not)
613639
return (not ^ eq) ? jpbTrue : jpbFalse;
614640
}
615641

642+
/*
643+
* Compare two SLQ/JSON items using comparison operation 'op'.
644+
*/
616645
static JsonPathBool
617646
makeCompare(int32 op, JsonbValue *jb1, JsonbValue *jb2)
618647
{
@@ -701,6 +730,9 @@ copyJsonbValue(JsonbValue *src)
701730
return dst;
702731
}
703732

733+
/*
734+
* Execute next jsonpath item if it does exist.
735+
*/
704736
static inline JsonPathExecResult
705737
recursiveExecuteNext(JsonPathExecContext *cxt,
706738
JsonPathItem *cur, JsonPathItem *next,
@@ -728,6 +760,10 @@ recursiveExecuteNext(JsonPathExecContext *cxt,
728760
return jperOk;
729761
}
730762

763+
/*
764+
* Execute jsonpath expression and automatically unwrap each array item from
765+
* the resulting sequence in lax mode.
766+
*/
731767
static inline JsonPathExecResult
732768
recursiveExecuteAndUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
733769
JsonbValue *jb, JsonValueList *found)
@@ -775,6 +811,12 @@ recursiveExecuteAndUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
775811
return recursiveExecute(cxt, jsp, jb, found);
776812
}
777813

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+
*/
778820
static JsonPathBool
779821
executeComparison(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb)
780822
{
@@ -852,6 +894,10 @@ executeComparison(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb)
852894
return jpbFalse;
853895
}
854896

897+
/*
898+
* Execute binary arithemitc expression on singleton numeric operands.
899+
* Array operands are automatically unwrapped in lax mode.
900+
*/
855901
static JsonPathExecResult
856902
executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
857903
JsonbValue *jb, JsonValueList *found)
@@ -961,6 +1007,10 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
9611007
return recursiveExecuteNext(cxt, jsp, &elem, lval, found, false);
9621008
}
9631009

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+
*/
9641014
static JsonPathExecResult
9651015
executeUnaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
9661016
JsonbValue *jb, JsonValueList *found)
@@ -1095,6 +1145,10 @@ recursiveAny(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
10951145
return res;
10961146
}
10971147

1148+
/*
1149+
* Execute array subscript expression and convert resulting numeric item to the
1150+
* integer type with truncation.
1151+
*/
10981152
static JsonPathExecResult
10991153
getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
11001154
int32 *index)
@@ -2136,6 +2190,9 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
21362190
return res;
21372191
}
21382192

2193+
/*
2194+
* Unwrap current array item and execute jsonpath for each of its elements.
2195+
*/
21392196
static JsonPathExecResult
21402197
recursiveExecuteUnwrapArray(JsonPathExecContext *cxt, JsonPathItem *jsp,
21412198
JsonbValue *jb, JsonValueList *found)
@@ -2181,6 +2238,9 @@ recursiveExecuteUnwrapArray(JsonPathExecContext *cxt, JsonPathItem *jsp,
21812238
return res;
21822239
}
21832240

2241+
/*
2242+
* Execute jsonpath with unwrapping of current item if it is an array.
2243+
*/
21842244
static inline JsonPathExecResult
21852245
recursiveExecuteUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
21862246
JsonbValue *jb, JsonValueList *found)
@@ -2233,6 +2293,9 @@ wrapItem(JsonbValue *jbv)
22332293
return JsonbWrapInBinary(jbv, NULL);
22342294
}
22352295

2296+
/*
2297+
* Execute jsonpath with automatic unwrapping of current item in lax mode.
2298+
*/
22362299
static inline JsonPathExecResult
22372300
recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
22382301
JsonValueList *found)

0 commit comments

Comments
 (0)