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

Commit 372dd39

Browse files
author
Nikita Glukhov
committed
Add some jsonpath comments
1 parent 670aa77 commit 372dd39

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
@@ -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+
*/
124127
static inline JsonbValue *
125128
JsonValueListNext(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+
*/
152158
static inline JsonbValue *
153159
JsonbInitBinary(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+
*/
162172
static inline JsonbValue *
163173
JsonbWrapInBinary(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+
*/
369382
static const char *
370383
JsonbTypeName(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+
*/
426442
static int
427443
JsonbArraySize(JsonbValue *jb)
428444
{
@@ -440,6 +456,9 @@ JsonbArraySize(JsonbValue *jb)
440456
return -1;
441457
}
442458

459+
/*
460+
* Compare two numerics.
461+
*/
443462
static int
444463
compareNumeric(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+
*/
455478
static int
456479
compareDatetime(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+
*/
567593
static inline JsonPathBool
568594
checkEquality(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+
*/
624653
static JsonPathBool
625654
makeCompare(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+
*/
712744
static inline JsonPathExecResult
713745
recursiveExecuteNext(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+
*/
739775
static inline JsonPathExecResult
740776
recursiveExecuteAndUnwrap(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+
*/
786828
static JsonPathBool
787829
executeComparison(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+
*/
863909
static JsonPathExecResult
864910
executeBinaryArithmExpr(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+
*/
9721022
static JsonPathExecResult
9731023
executeUnaryArithmExpr(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+
*/
11061160
static JsonPathExecResult
11071161
getArrayIndex(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+
*/
22472304
static JsonPathExecResult
22482305
recursiveExecuteUnwrapArray(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+
*/
22922352
static inline JsonPathExecResult
22932353
recursiveExecuteUnwrap(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+
*/
23442407
static inline JsonPathExecResult
23452408
recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
23462409
JsonValueList *found)

0 commit comments

Comments
 (0)