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

Commit 7d54629

Browse files
feodorNikita Glukhov
authored and
Nikita Glukhov
committed
completely remove anon union in jsonpath
1 parent e162076 commit 7d54629

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
@@ -357,30 +357,30 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
357357
break;
358358
case jpiIndexArray:
359359
appendStringInfoChar(buf, '[');
360-
for(i = 0; i< v->array.nelems; i++)
360+
for(i = 0; i< v->content.array.nelems; i++)
361361
{
362362
if (i)
363363
appendStringInfoChar(buf, ',');
364-
appendStringInfo(buf, "%d", v->array.elems[i]);
364+
appendStringInfo(buf, "%d", v->content.array.elems[i]);
365365
}
366366
appendStringInfoChar(buf, ']');
367367
break;
368368
case jpiAny:
369369
if (inKey)
370370
appendStringInfoChar(buf, '.');
371371

372-
if (v->anybounds.first == 0 &&
373-
v->anybounds.last == PG_UINT32_MAX)
372+
if (v->content.anybounds.first == 0 &&
373+
v->content.anybounds.last == PG_UINT32_MAX)
374374
appendBinaryStringInfo(buf, "**", 2);
375-
else if (v->anybounds.first == 0)
376-
appendStringInfo(buf, "**{,%u}", v->anybounds.last);
377-
else if (v->anybounds.last == PG_UINT32_MAX)
378-
appendStringInfo(buf, "**{%u,}", v->anybounds.first);
379-
else if (v->anybounds.first == v->anybounds.last)
380-
appendStringInfo(buf, "**{%u}", v->anybounds.first);
375+
else if (v->content.anybounds.first == 0)
376+
appendStringInfo(buf, "**{,%u}", v->content.anybounds.last);
377+
else if (v->content.anybounds.last == PG_UINT32_MAX)
378+
appendStringInfo(buf, "**{%u,}", v->content.anybounds.first);
379+
else if (v->content.anybounds.first == v->content.anybounds.last)
380+
appendStringInfo(buf, "**{%u}", v->content.anybounds.first);
381381
else
382-
appendStringInfo(buf, "**{%u,%u}", v->anybounds.first,
383-
v->anybounds.last);
382+
appendStringInfo(buf, "**{%u,%u}", v->content.anybounds.first,
383+
v->content.anybounds.last);
384384
break;
385385
default:
386386
elog(ERROR, "Unknown jsonpath item type: %d", v->type);
@@ -458,11 +458,11 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
458458
case jpiKey:
459459
case jpiString:
460460
case jpiVariable:
461-
read_int32(v->value.datalen, base, pos);
461+
read_int32(v->content.value.datalen, base, pos);
462462
/* follow next */
463463
case jpiNumeric:
464464
case jpiBool:
465-
v->value.data = base + pos;
465+
v->content.value.data = base + pos;
466466
break;
467467
case jpiAnd:
468468
case jpiOr:
@@ -477,24 +477,24 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
477477
case jpiGreater:
478478
case jpiLessOrEqual:
479479
case jpiGreaterOrEqual:
480-
read_int32(v->args.left, base, pos);
481-
read_int32(v->args.right, base, pos);
480+
read_int32(v->content.args.left, base, pos);
481+
read_int32(v->content.args.right, base, pos);
482482
break;
483483
case jpiNot:
484484
case jpiExists:
485485
case jpiIsUnknown:
486486
case jpiPlus:
487487
case jpiMinus:
488488
case jpiFilter:
489-
read_int32(v->arg, base, pos);
489+
read_int32(v->content.arg, base, pos);
490490
break;
491491
case jpiIndexArray:
492-
read_int32(v->array.nelems, base, pos);
493-
read_int32_n(v->array.elems, base, pos, v->array.nelems);
492+
read_int32(v->content.array.nelems, base, pos);
493+
read_int32_n(v->content.array.elems, base, pos, v->content.array.nelems);
494494
break;
495495
case jpiAny:
496-
read_int32(v->anybounds.first, base, pos);
497-
read_int32(v->anybounds.last, base, pos);
496+
read_int32(v->content.anybounds.first, base, pos);
497+
read_int32(v->content.anybounds.last, base, pos);
498498
break;
499499
default:
500500
elog(ERROR, "Unknown jsonpath item type: %d", v->type);
@@ -513,7 +513,7 @@ jspGetArg(JsonPathItem *v, JsonPathItem *a)
513513
v->type == jpiMinus
514514
);
515515

516-
jspInitByBuffer(a, v->base, v->arg);
516+
jspInitByBuffer(a, v->base, v->content.arg);
517517
}
518518

519519
bool
@@ -560,7 +560,7 @@ jspGetLeftArg(JsonPathItem *v, JsonPathItem *a)
560560
v->type == jpiMod
561561
);
562562

563-
jspInitByBuffer(a, v->base, v->args.left);
563+
jspInitByBuffer(a, v->base, v->content.args.left);
564564
}
565565

566566
void
@@ -582,23 +582,23 @@ jspGetRightArg(JsonPathItem *v, JsonPathItem *a)
582582
v->type == jpiMod
583583
);
584584

585-
jspInitByBuffer(a, v->base, v->args.right);
585+
jspInitByBuffer(a, v->base, v->content.args.right);
586586
}
587587

588588
bool
589589
jspGetBool(JsonPathItem *v)
590590
{
591591
Assert(v->type == jpiBool);
592592

593-
return (bool)*v->value.data;
593+
return (bool)*v->content.value.data;
594594
}
595595

596596
Numeric
597597
jspGetNumeric(JsonPathItem *v)
598598
{
599599
Assert(v->type == jpiNumeric);
600600

601-
return (Numeric)v->value.data;
601+
return (Numeric)v->content.value.data;
602602
}
603603

604604
char*
@@ -611,6 +611,6 @@ jspGetString(JsonPathItem *v, int32 *len)
611611
);
612612

613613
if (len)
614-
*len = v->value.datalen;
615-
return v->value.data;
614+
*len = v->content.value.datalen;
615+
return v->content.value.data;
616616
}

src/backend/utils/adt/jsonpath_exec.c

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

752752
hasNext = jspGetNext(jsp, &elem);
753753

754-
for(i=0; i<jsp->array.nelems; i++)
754+
for(i=0; i<jsp->content.array.nelems; i++)
755755
{
756756
/* TODO for future: array index can be expression */
757757
v = getIthJsonbValueFromContainer(jb->val.binary.data,
758-
jsp->array.elems[i]);
758+
jsp->content.array.elems[i]);
759759

760760
if (v == NULL)
761761
continue;
@@ -867,7 +867,7 @@ recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
867867
bool hasNext = jspGetNext(jsp, &elem);
868868

869869
/* first try without any intermediate steps */
870-
if (jsp->anybounds.first == 0)
870+
if (jsp->content.anybounds.first == 0)
871871
{
872872
if (hasNext)
873873
{
@@ -887,8 +887,8 @@ recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
887887
if (jb->type == jbvBinary)
888888
res = recursiveAny(cxt, hasNext ? &elem : NULL, jb, found,
889889
1,
890-
jsp->anybounds.first,
891-
jsp->anybounds.last);
890+
jsp->content.anybounds.first,
891+
jsp->content.anybounds.last);
892892
break;
893893
}
894894
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)