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

Commit f034fcd

Browse files
author
Nikita Glukhov
committed
Implement JSON_TABLE DEFAULT PLAN clause
1 parent e44ded0 commit f034fcd

File tree

14 files changed

+361
-37
lines changed

14 files changed

+361
-37
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,7 @@ _copyJsonTable(const JsonTable *from)
26302630
COPY_NODE_FIELD(columns);
26312631
COPY_NODE_FIELD(on_error);
26322632
COPY_NODE_FIELD(alias);
2633+
COPY_SCALAR_FIELD(join_type);
26332634
COPY_SCALAR_FIELD(location);
26342635

26352636
return newnode;
@@ -2668,6 +2669,8 @@ _copyJsonTableParentNode(const JsonTableParentNode *from)
26682669

26692670
COPY_NODE_FIELD(path);
26702671
COPY_NODE_FIELD(child);
2672+
COPY_SCALAR_FIELD(outerJoin);
2673+
COPY_SCALAR_FIELD(unionJoin);
26712674
COPY_SCALAR_FIELD(colMin);
26722675
COPY_SCALAR_FIELD(colMax);
26732676

@@ -2684,6 +2687,7 @@ _copyJsonTableSiblingNode(const JsonTableSiblingNode *from)
26842687

26852688
COPY_NODE_FIELD(larg);
26862689
COPY_NODE_FIELD(rarg);
2690+
COPY_SCALAR_FIELD(cross);
26872691

26882692
return newnode;
26892693
}

src/backend/nodes/equalfuncs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ _equalJsonTableParentNode(const JsonTableParentNode *a, const JsonTableParentNod
145145
{
146146
COMPARE_NODE_FIELD(path);
147147
COMPARE_NODE_FIELD(child);
148+
COMPARE_SCALAR_FIELD(outerJoin);
149+
COMPARE_SCALAR_FIELD(unionJoin);
148150
COMPARE_SCALAR_FIELD(colMin);
149151
COMPARE_SCALAR_FIELD(colMax);
150152

@@ -156,6 +158,7 @@ _equalJsonTableSiblingNode(const JsonTableSiblingNode *a, const JsonTableSibling
156158
{
157159
COMPARE_NODE_FIELD(larg);
158160
COMPARE_NODE_FIELD(rarg);
161+
COMPARE_SCALAR_FIELD(cross);
159162

160163
return true;
161164
}

src/backend/nodes/outfuncs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,8 @@ _outJsonTableParentNode(StringInfo str, const JsonTableParentNode *node)
18331833

18341834
WRITE_NODE_FIELD(path);
18351835
WRITE_NODE_FIELD(child);
1836+
WRITE_BOOL_FIELD(outerJoin);
1837+
WRITE_BOOL_FIELD(unionJoin);
18361838
WRITE_INT_FIELD(colMin);
18371839
WRITE_INT_FIELD(colMax);
18381840
}
@@ -1844,6 +1846,7 @@ _outJsonTableSiblingNode(StringInfo str, const JsonTableSiblingNode *node)
18441846

18451847
WRITE_NODE_FIELD(larg);
18461848
WRITE_NODE_FIELD(rarg);
1849+
WRITE_BOOL_FIELD(cross);
18471850
}
18481851

18491852
/*****************************************************************************

src/backend/nodes/readfuncs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,8 @@ _readJsonTableParentNode(void)
14581458

14591459
READ_NODE_FIELD(path);
14601460
READ_NODE_FIELD(child);
1461+
READ_BOOL_FIELD(outerJoin);
1462+
READ_BOOL_FIELD(unionJoin);
14611463
READ_INT_FIELD(colMin);
14621464
READ_INT_FIELD(colMax);
14631465

@@ -1471,6 +1473,7 @@ _readJsonTableSiblingNode(void)
14711473

14721474
READ_NODE_FIELD(larg);
14731475
READ_NODE_FIELD(rarg);
1476+
READ_BOOL_FIELD(cross);
14741477

14751478
READ_DONE();
14761479
}

src/backend/parser/gram.y

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,11 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
656656

657657
%type <ival> json_encoding
658658
json_encoding_clause_opt
659+
json_table_plan_clause_opt
660+
json_table_default_plan
661+
json_table_default_plan_choices
662+
json_table_default_plan_inner_outer
663+
json_table_default_plan_union_cross
659664
json_wrapper_clause_opt
660665
json_wrapper_behavior
661666
json_conditional_or_unconditional_opt
@@ -769,7 +774,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
769774
ORDER ORDINALITY OTHERS OUT_P OUTER_P
770775
OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
771776

772-
PARALLEL PARSER PARTIAL PARTITION PASSING PASSWORD PATH PLACING PLANS POLICY
777+
PARALLEL PARSER PARTIAL PARTITION PASSING PASSWORD PATH PLACING PLAN PLANS POLICY
773778
POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
774779
PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
775780

@@ -15130,13 +15135,15 @@ json_table:
1513015135
JSON_TABLE '('
1513115136
json_api_common_syntax
1513215137
json_table_columns_clause
15138+
json_table_plan_clause_opt
1513315139
json_table_error_clause_opt
1513415140
')'
1513515141
{
1513615142
JsonTable *n = makeNode(JsonTable);
1513715143
n->common = (JsonCommon *) $3;
1513815144
n->columns = $4;
15139-
n->on_error = $5;
15145+
n->join_type = $5;
15146+
n->on_error = $6;
1514015147
n->location = @1;
1514115148
$$ = (Node *) n;
1514215149
}
@@ -15273,6 +15280,34 @@ path_opt:
1527315280
| /* EMPTY */ { }
1527415281
;
1527515282

15283+
json_table_plan_clause_opt:
15284+
json_table_default_plan { $$ = $1; }
15285+
| /* EMPTY */ { $$ = JSTP_OUTER | JSTP_UNION; }
15286+
;
15287+
15288+
json_table_default_plan:
15289+
PLAN DEFAULT '(' json_table_default_plan_choices ')' { $$ = $4; }
15290+
;
15291+
15292+
json_table_default_plan_choices:
15293+
json_table_default_plan_inner_outer { $$ = $1 | JSTP_UNION; }
15294+
| json_table_default_plan_inner_outer ','
15295+
json_table_default_plan_union_cross { $$ = $1 | $3; }
15296+
| json_table_default_plan_union_cross { $$ = $1 | JSTP_OUTER; }
15297+
| json_table_default_plan_union_cross ','
15298+
json_table_default_plan_inner_outer { $$ = $1 | $3; }
15299+
;
15300+
15301+
json_table_default_plan_inner_outer:
15302+
INNER_P { $$ = JSTP_INNER; }
15303+
| OUTER_P { $$ = JSTP_OUTER; }
15304+
;
15305+
15306+
json_table_default_plan_union_cross:
15307+
UNION { $$ = JSTP_UNION; }
15308+
| CROSS { $$ = JSTP_CROSS; }
15309+
;
15310+
1527615311
json_returning_clause_opt:
1527715312
RETURNING Typename
1527815313
{
@@ -16088,6 +16123,7 @@ unreserved_keyword:
1608816123
| PASSING
1608916124
| PASSWORD
1609016125
| PATH
16126+
| PLAN
1609116127
| PLANS
1609216128
| POLICY
1609316129
| PRECEDING

src/backend/parser/parse_jsontable.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,29 +174,31 @@ transformNestedJsonTableColumn(JsonTableContext *cxt, JsonTableColumn *jtc)
174174
}
175175

176176
static Node *
177-
makeJsonTableSiblingJoin(Node *lnode, Node *rnode)
177+
makeJsonTableSiblingJoin(bool cross, Node *lnode, Node *rnode)
178178
{
179179
JsonTableSiblingNode *join = makeNode(JsonTableSiblingNode);
180180

181181
join->larg = lnode;
182182
join->rarg = rnode;
183+
join->cross = cross;
183184

184185
return (Node *) join;
185186
}
186187

187188
/*
188189
* Recursively transform child (nested) JSON_TABLE columns.
189190
*
190-
* Child columns are transformed into a binary tree of union-joined
191+
* Child columns are transformed into a binary tree of union/cross-joined
191192
* JsonTableSiblingNodes.
192193
*/
193194
static Node *
194195
transformJsonTableChildColumns(JsonTableContext *cxt, List *columns)
195196
{
196197
Node *res = NULL;
197198
ListCell *lc;
199+
bool cross = cxt->table->join_type & JSTP_CROSS;
198200

199-
/* transform all nested columns into union join */
201+
/* transform all nested columns into union/cros join */
200202
foreach(lc, columns)
201203
{
202204
JsonTableColumn *jtc = castNode(JsonTableColumn, lfirst(lc));
@@ -208,7 +210,7 @@ transformJsonTableChildColumns(JsonTableContext *cxt, List *columns)
208210
node = transformNestedJsonTableColumn(cxt, jtc);
209211

210212
/* join transformed node with previous sibling nodes */
211-
res = res ? makeJsonTableSiblingJoin(res, node) : node;
213+
res = res ? makeJsonTableSiblingJoin(cross, res, node) : node;
212214
}
213215

214216
return res;
@@ -386,6 +388,9 @@ transformJsonTableColumns(JsonTableContext *cxt, List *columns, char *pathSpec,
386388
/* transform recursively nested columns */
387389
node->child = transformJsonTableChildColumns(cxt, columns);
388390

391+
node->outerJoin = cxt->table->join_type & JSTP_OUTER;
392+
node->unionJoin = cxt->table->join_type & JSTP_UNION;
393+
389394
return node;
390395
}
391396

0 commit comments

Comments
 (0)