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

Commit 60f13d2

Browse files
feodorNikita Glukhov
authored and
Nikita Glukhov
committed
completely remove anon union in jsonpath
1 parent f29a84d commit 60f13d2

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -351,30 +351,30 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
351351
break;
352352
case jpiIndexArray:
353353
appendStringInfoChar(buf, '[');
354-
for(i = 0; i< v->array.nelems; i++)
354+
for(i = 0; i< v->content.array.nelems; i++)
355355
{
356356
if (i)
357357
appendStringInfoChar(buf, ',');
358-
appendStringInfo(buf, "%d", v->array.elems[i]);
358+
appendStringInfo(buf, "%d", v->content.array.elems[i]);
359359
}
360360
appendStringInfoChar(buf, ']');
361361
break;
362362
case jpiAny:
363363
if (inKey)
364364
appendStringInfoChar(buf, '.');
365365

366-
if (v->anybounds.first == 0 &&
367-
v->anybounds.last == PG_UINT32_MAX)
366+
if (v->content.anybounds.first == 0 &&
367+
v->content.anybounds.last == PG_UINT32_MAX)
368368
appendBinaryStringInfo(buf, "**", 2);
369-
else if (v->anybounds.first == 0)
370-
appendStringInfo(buf, "**{,%u}", v->anybounds.last);
371-
else if (v->anybounds.last == PG_UINT32_MAX)
372-
appendStringInfo(buf, "**{%u,}", v->anybounds.first);
373-
else if (v->anybounds.first == v->anybounds.last)
374-
appendStringInfo(buf, "**{%u}", v->anybounds.first);
369+
else if (v->content.anybounds.first == 0)
370+
appendStringInfo(buf, "**{,%u}", v->content.anybounds.last);
371+
else if (v->content.anybounds.last == PG_UINT32_MAX)
372+
appendStringInfo(buf, "**{%u,}", v->content.anybounds.first);
373+
else if (v->content.anybounds.first == v->content.anybounds.last)
374+
appendStringInfo(buf, "**{%u}", v->content.anybounds.first);
375375
else
376-
appendStringInfo(buf, "**{%u,%u}", v->anybounds.first,
377-
v->anybounds.last);
376+
appendStringInfo(buf, "**{%u,%u}", v->content.anybounds.first,
377+
v->content.anybounds.last);
378378
break;
379379
default:
380380
elog(ERROR, "Unknown jsonpath item type: %d", v->type);
@@ -452,11 +452,11 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
452452
case jpiKey:
453453
case jpiString:
454454
case jpiVariable:
455-
read_int32(v->value.datalen, base, pos);
455+
read_int32(v->content.value.datalen, base, pos);
456456
/* follow next */
457457
case jpiNumeric:
458458
case jpiBool:
459-
v->value.data = base + pos;
459+
v->content.value.data = base + pos;
460460
break;
461461
case jpiAnd:
462462
case jpiOr:
@@ -471,24 +471,24 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
471471
case jpiGreater:
472472
case jpiLessOrEqual:
473473
case jpiGreaterOrEqual:
474-
read_int32(v->args.left, base, pos);
475-
read_int32(v->args.right, base, pos);
474+
read_int32(v->content.args.left, base, pos);
475+
read_int32(v->content.args.right, base, pos);
476476
break;
477477
case jpiNot:
478478
case jpiExists:
479479
case jpiIsUnknown:
480480
case jpiPlus:
481481
case jpiMinus:
482482
case jpiFilter:
483-
read_int32(v->arg, base, pos);
483+
read_int32(v->content.arg, base, pos);
484484
break;
485485
case jpiIndexArray:
486-
read_int32(v->array.nelems, base, pos);
487-
read_int32_n(v->array.elems, base, pos, v->array.nelems);
486+
read_int32(v->content.array.nelems, base, pos);
487+
read_int32_n(v->content.array.elems, base, pos, v->content.array.nelems);
488488
break;
489489
case jpiAny:
490-
read_int32(v->anybounds.first, base, pos);
491-
read_int32(v->anybounds.last, base, pos);
490+
read_int32(v->content.anybounds.first, base, pos);
491+
read_int32(v->content.anybounds.last, base, pos);
492492
break;
493493
default:
494494
elog(ERROR, "Unknown jsonpath item type: %d", v->type);
@@ -507,7 +507,7 @@ jspGetArg(JsonPathItem *v, JsonPathItem *a)
507507
v->type == jpiMinus
508508
);
509509

510-
jspInitByBuffer(a, v->base, v->arg);
510+
jspInitByBuffer(a, v->base, v->content.arg);
511511
}
512512

513513
bool
@@ -554,7 +554,7 @@ jspGetLeftArg(JsonPathItem *v, JsonPathItem *a)
554554
v->type == jpiMod
555555
);
556556

557-
jspInitByBuffer(a, v->base, v->args.left);
557+
jspInitByBuffer(a, v->base, v->content.args.left);
558558
}
559559

560560
void
@@ -576,23 +576,23 @@ jspGetRightArg(JsonPathItem *v, JsonPathItem *a)
576576
v->type == jpiMod
577577
);
578578

579-
jspInitByBuffer(a, v->base, v->args.right);
579+
jspInitByBuffer(a, v->base, v->content.args.right);
580580
}
581581

582582
bool
583583
jspGetBool(JsonPathItem *v)
584584
{
585585
Assert(v->type == jpiBool);
586586

587-
return (bool)*v->value.data;
587+
return (bool)*v->content.value.data;
588588
}
589589

590590
Numeric
591591
jspGetNumeric(JsonPathItem *v)
592592
{
593593
Assert(v->type == jpiNumeric);
594594

595-
return (Numeric)v->value.data;
595+
return (Numeric)v->content.value.data;
596596
}
597597

598598
char*
@@ -605,6 +605,6 @@ jspGetString(JsonPathItem *v, int32 *len)
605605
);
606606

607607
if (len)
608-
*len = v->value.datalen;
609-
return v->value.data;
608+
*len = v->content.value.datalen;
609+
return v->content.value.data;
610610
}

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,11 @@ recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
743743

744744
hasNext = jspGetNext(jsp, &elem);
745745

746-
for(i=0; i<jsp->array.nelems; i++)
746+
for(i=0; i<jsp->content.array.nelems; i++)
747747
{
748748
/* TODO for future: array index can be expression */
749749
v = getIthJsonbValueFromContainer(jb->val.binary.data,
750-
jsp->array.elems[i]);
750+
jsp->content.array.elems[i]);
751751

752752
if (v == NULL)
753753
continue;
@@ -859,7 +859,7 @@ recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
859859
bool hasNext = jspGetNext(jsp, &elem);
860860

861861
/* first try without any intermediate steps */
862-
if (jsp->anybounds.first == 0)
862+
if (jsp->content.anybounds.first == 0)
863863
{
864864
if (hasNext)
865865
{
@@ -879,8 +879,8 @@ recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
879879
if (jb->type == jbvBinary)
880880
res = recursiveAny(cxt, hasNext ? &elem : NULL, jb, found,
881881
1,
882-
jsp->anybounds.first,
883-
jsp->anybounds.last);
882+
jsp->content.anybounds.first,
883+
jsp->content.anybounds.last);
884884
break;
885885
}
886886
case jpiExists:

src/include/utils/jsonpath.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ typedef enum JsonPathItemType {
8282

8383
typedef struct JsonPathItem {
8484
JsonPathItemType type;
85+
86+
/* position form base to next node */
8587
int32 nextPos;
88+
89+
/*
90+
* pointer into JsonPath value to current node, all
91+
* positions of current are relative to this base
92+
*/
8693
char *base;
8794

8895
union {
@@ -111,7 +118,7 @@ typedef struct JsonPathItem {
111118
char *data; /* for bool, numeric and string/key */
112119
int32 datalen; /* filled only for string/key */
113120
} value;
114-
};
121+
} content;
115122
} JsonPathItem;
116123

117124
extern void jspInit(JsonPathItem *v, JsonPath *js);

0 commit comments

Comments
 (0)