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

Commit e019de8

Browse files
feodorNikita Glukhov
authored and
Nikita Glukhov
committed
make beauty
1 parent 75f6ba8 commit e019de8

File tree

3 files changed

+85
-85
lines changed

3 files changed

+85
-85
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,26 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
4444
(errcode(ERRCODE_SYNTAX_ERROR),
4545
errmsg("scalar could not be a part of path")));
4646
case jpiKey:
47-
appendBinaryStringInfo(buf, (char*)&item->string.len, sizeof(item->string.len));
48-
appendBinaryStringInfo(buf, item->string.val, item->string.len);
47+
appendBinaryStringInfo(buf, (char*)&item->value.string.len,
48+
sizeof(item->value.string.len));
49+
appendBinaryStringInfo(buf, item->value.string.val, item->value.string.len);
4950
appendStringInfoChar(buf, '\0');
5051
break;
5152
case jpiNumeric:
5253
if (item->next != NULL)
5354
ereport(ERROR,
5455
(errcode(ERRCODE_SYNTAX_ERROR),
5556
errmsg("scalar could not be a part of path")));
56-
appendBinaryStringInfo(buf, (char*)item->numeric, VARSIZE(item->numeric));
57+
appendBinaryStringInfo(buf, (char*)item->value.numeric,
58+
VARSIZE(item->value.numeric));
5759
break;
5860
case jpiBool:
5961
if (item->next != NULL)
6062
ereport(ERROR,
6163
(errcode(ERRCODE_SYNTAX_ERROR),
6264
errmsg("scalar could not be a part of path")));
63-
appendBinaryStringInfo(buf, (char*)&item->boolean, sizeof(item->boolean));
65+
appendBinaryStringInfo(buf, (char*)&item->value.boolean,
66+
sizeof(item->value.boolean));
6467
break;
6568
case jpiAnd:
6669
case jpiOr:
@@ -83,9 +86,9 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
8386
right = buf->len;
8487
appendBinaryStringInfo(buf, (char*)&right /* fake value */, sizeof(right));
8588

86-
chld = flattenJsonPathParseItem(buf, item->args.left, forbiddenRoot);
89+
chld = flattenJsonPathParseItem(buf, item->value.args.left, forbiddenRoot);
8790
*(int32*)(buf->data + left) = chld;
88-
chld = flattenJsonPathParseItem(buf, item->args.right, forbiddenRoot);
91+
chld = flattenJsonPathParseItem(buf, item->value.args.right, forbiddenRoot);
8992
*(int32*)(buf->data + right) = chld;
9093
}
9194
break;
@@ -101,7 +104,7 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
101104
arg = buf->len;
102105
appendBinaryStringInfo(buf, (char*)&arg /* fake value */, sizeof(arg));
103106

104-
chld = flattenJsonPathParseItem(buf, item->arg,
107+
chld = flattenJsonPathParseItem(buf, item->value.arg,
105108
item->type == jpiFilter ||
106109
forbiddenRoot);
107110
*(int32*)(buf->data + arg) = chld;
@@ -130,19 +133,20 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
130133
break;
131134
case jpiIndexArray:
132135
appendBinaryStringInfo(buf,
133-
(char*)&item->array.nelems,
134-
sizeof(item->array.nelems));
136+
(char*)&item->value.array.nelems,
137+
sizeof(item->value.array.nelems));
135138
appendBinaryStringInfo(buf,
136-
(char*)item->array.elems,
137-
item->array.nelems * sizeof(item->array.elems[0]));
139+
(char*)item->value.array.elems,
140+
item->value.array.nelems *
141+
sizeof(item->value.array.elems[0]));
138142
break;
139143
case jpiAny:
140144
appendBinaryStringInfo(buf,
141-
(char*)&item->anybounds.first,
142-
sizeof(item->anybounds.first));
145+
(char*)&item->value.anybounds.first,
146+
sizeof(item->value.anybounds.first));
143147
appendBinaryStringInfo(buf,
144-
(char*)&item->anybounds.last,
145-
sizeof(item->anybounds.last));
148+
(char*)&item->value.anybounds.last,
149+
sizeof(item->value.anybounds.last));
146150
break;
147151
default:
148152
elog(ERROR, "Unknown jsonpath item type: %d", item->type);

src/backend/utils/adt/jsonpath_gram.y

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ makeItemString(string *s)
5555
else
5656
{
5757
v = makeItemType(jpiString);
58-
v->string.val = s->val;
59-
v->string.len = s->len;
58+
v->value.string.val = s->val;
59+
v->value.string.len = s->len;
6060
}
6161

6262
return v;
@@ -68,8 +68,8 @@ makeItemVariable(string *s)
6868
JsonPathParseItem *v;
6969

7070
v = makeItemType(jpiVariable);
71-
v->string.val = s->val;
72-
v->string.len = s->len;
71+
v->value.string.val = s->val;
72+
v->value.string.len = s->len;
7373

7474
return v;
7575
}
@@ -91,7 +91,8 @@ makeItemNumeric(string *s)
9191
JsonPathParseItem *v;
9292

9393
v = makeItemType(jpiNumeric);
94-
v->numeric = DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(s->val), 0, -1));
94+
v->value.numeric =
95+
DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(s->val), 0, -1));
9596

9697
return v;
9798
}
@@ -100,7 +101,7 @@ static JsonPathParseItem*
100101
makeItemBool(bool val) {
101102
JsonPathParseItem *v = makeItemType(jpiBool);
102103

103-
v->boolean = val;
104+
v->value.boolean = val;
104105

105106
return v;
106107
}
@@ -110,8 +111,8 @@ makeItemBinary(int type, JsonPathParseItem* la, JsonPathParseItem *ra)
110111
{
111112
JsonPathParseItem *v = makeItemType(type);
112113

113-
v->args.left = la;
114-
v->args.right = ra;
114+
v->value.args.left = la;
115+
v->value.args.right = ra;
115116

116117
return v;
117118
}
@@ -127,15 +128,15 @@ makeItemUnary(int type, JsonPathParseItem* a)
127128
if (type == jpiMinus && a->type == jpiNumeric && !a->next)
128129
{
129130
v = makeItemType(jpiNumeric);
130-
v->numeric =
131+
v->value.numeric =
131132
DatumGetNumeric(DirectFunctionCall1(numeric_uminus,
132-
NumericGetDatum(a->numeric)));
133+
NumericGetDatum(a->value.numeric)));
133134
return v;
134135
}
135136

136137
v = makeItemType(type);
137138

138-
v->arg = a;
139+
v->value.arg = a;
139140

140141
return v;
141142
}
@@ -169,12 +170,12 @@ makeIndexArray(List *list)
169170
int i = 0;
170171

171172
Assert(list_length(list) > 0);
172-
v->array.nelems = list_length(list);
173+
v->value.array.nelems = list_length(list);
173174

174-
v->array.elems = palloc(sizeof(v->array.elems[0]) * v->array.nelems);
175+
v->value.array.elems = palloc(sizeof(v->value.array.elems[0]) * v->value.array.nelems);
175176

176177
foreach(cell, list)
177-
v->array.elems[i++] = lfirst_int(cell);
178+
v->value.array.elems[i++] = lfirst_int(cell);
178179

179180
return v;
180181
}
@@ -184,8 +185,8 @@ makeAny(int first, int last)
184185
{
185186
JsonPathParseItem *v = makeItemType(jpiAny);
186187

187-
v->anybounds.first = (first > 0) ? first : 0;
188-
v->anybounds.last = (last >= 0) ? last : PG_UINT32_MAX;
188+
v->value.anybounds.first = (first > 0) ? first : 0;
189+
v->value.anybounds.last = (last >= 0) ? last : PG_UINT32_MAX;
189190

190191
return v;
191192
}
@@ -202,7 +203,7 @@ makeAny(int first, int last)
202203
%union {
203204
string str;
204205
List *elems; /* list of JsonPathParseItem */
205-
List *indexs;
206+
List *indexs; /* list of integers */
206207
JsonPathParseItem *value;
207208
int optype;
208209
}
@@ -213,11 +214,10 @@ makeAny(int first, int last)
213214
%token <str> LESS_P LESSEQUAL_P EQUAL_P NOTEQUAL_P GREATEREQUAL_P GREATER_P
214215
%token <str> ANY_P
215216

216-
%type <value> result jsonpath scalar_value path_primary expr pexpr
217-
array_accessor any_path accessor_op key
218-
predicate delimited_predicate
217+
%type <value> result scalar_value path_primary expr pexpr array_accessor
218+
any_path accessor_op key predicate delimited_predicate
219219

220-
%type <elems> accessor_expr /* path absolute_path relative_path */
220+
%type <elems> accessor_expr
221221

222222
%type <indexs> index_elem index_list
223223

@@ -235,7 +235,7 @@ makeAny(int first, int last)
235235
%%
236236

237237
result:
238-
jsonpath { *result = $1; }
238+
expr { *result = $1; }
239239
| /* EMPTY */ { *result = NULL; }
240240
;
241241

@@ -249,10 +249,6 @@ scalar_value:
249249
| VARIABLE_P { $$ = makeItemVariable(&$1); }
250250
;
251251

252-
jsonpath:
253-
expr
254-
;
255-
256252
comp_op:
257253
EQUAL_P { $$ = jpiEqual; }
258254
| NOTEQUAL_P { $$ = jpiNotEqual; }
@@ -269,16 +265,18 @@ delimited_predicate:
269265

270266
predicate:
271267
delimited_predicate { $$ = $1; }
272-
| pexpr comp_op pexpr { $$ = makeItemBinary($2, $1, $3); }
273-
// | expr LIKE_REGEX pattern { $$ = ...; }
274-
// | expr STARTS WITH STRING_P { $$ = ...; }
275-
// | expr STARTS WITH '$' STRING_P { $$ = ...; }
276-
// | expr STARTS WITH '$' STRING_P { $$ = ...; }
277-
// | '.' any_key right_expr { $$ = makeItemList(list_make2($2, $3)); }
278-
| '(' predicate ')' IS_P UNKNOWN_P { $$ = makeItemUnary(jpiIsUnknown, $2); }
268+
| pexpr comp_op pexpr { $$ = makeItemBinary($2, $1, $3); }
279269
| predicate AND_P predicate { $$ = makeItemBinary(jpiAnd, $1, $3); }
280270
| predicate OR_P predicate { $$ = makeItemBinary(jpiOr, $1, $3); }
281271
| NOT_P delimited_predicate { $$ = makeItemUnary(jpiNot, $2); }
272+
| '(' predicate ')' IS_P UNKNOWN_P { $$ = makeItemUnary(jpiIsUnknown, $2); }
273+
/*
274+
Left for the future
275+
| pexpr LIKE_REGEX pattern { $$ = ...; }
276+
| pexpr STARTS WITH STRING_P { $$ = ...; }
277+
| pexpr STARTS WITH '$' STRING_P { $$ = ...; }
278+
| pexpr STARTS WITH '$' STRING_P { $$ = ...; }
279+
*/
282280
;
283281

284282
path_primary:
@@ -363,23 +361,5 @@ key:
363361
| UNKNOWN_P { $$ = makeItemKey(&$1); }
364362
| EXISTS_P { $$ = makeItemKey(&$1); }
365363
;
366-
/*
367-
absolute_path:
368-
'$' { $$ = list_make1(makeItemType(jpiRoot)); }
369-
| '$' path { $$ = lcons(makeItemType(jpiRoot), $2); }
370-
;
371-
372-
relative_path:
373-
key { $$ = list_make1(makeItemType(jpiCurrent), $1); }
374-
| key path { $$ = lcons(makeItemType(jpiCurrent), lcons($1, $2)); }
375-
| '@' { $$ = list_make1(makeItemType(jpiCurrent)); }
376-
| '@' path { $$ = lcons(makeItemType(jpiCurrent), $2); }
377-
;
378-
379-
path:
380-
accessor_op { $$ = list_make($1); }
381-
| path accessor_op { $$ = lappend($1, $2); }
382-
;
383-
*/
384364
%%
385365

0 commit comments

Comments
 (0)