From 87f6b4ad2d85a243b106c933c3f8830e5f64451f Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 21 Nov 2023 07:25:41 +0100 Subject: [PATCH 6/6] Get rid of JsonCommon --- src/backend/nodes/nodeFuncs.c | 18 ++---- src/backend/parser/gram.y | 95 ++++++++++---------------------- src/backend/parser/parse_expr.c | 8 +-- src/include/nodes/parsenodes.h | 18 +----- src/tools/pgindent/typedefs.list | 1 - 5 files changed, 40 insertions(+), 100 deletions(-) diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index 7cad662e28..b6cd8c38d2 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -4081,18 +4081,6 @@ raw_expression_tree_walker_impl(Node *node, return WALK(((JsonIsPredicate *) node)->expr); case T_JsonArgument: return WALK(((JsonArgument *) node)->val); - case T_JsonCommon: - { - JsonCommon *jc = (JsonCommon *) node; - - if (WALK(jc->expr)) - return true; - if (WALK(jc->pathspec)) - return true; - if (WALK(jc->passing)) - return true; - } - break; case T_JsonBehavior: { JsonBehavior *jb = (JsonBehavior *) node; @@ -4106,7 +4094,11 @@ raw_expression_tree_walker_impl(Node *node, { JsonFuncExpr *jfe = (JsonFuncExpr *) node; - if (WALK(jfe->common)) + if (WALK(jfe->context_item)) + return true; + if (WALK(jfe->pathspec)) + return true; + if (WALK(jfe->passing)) return true; if (jfe->output && WALK(jfe->output)) return true; diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 99585308c8..4cdf086a42 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -650,7 +650,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); json_returning_clause_opt json_name_and_value json_aggregate_func - json_api_common_syntax json_argument json_behavior %type json_name_and_value_list @@ -658,6 +657,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); json_array_aggregate_order_by_clause_opt json_arguments json_behavior_clause_opt + json_passing_clause_opt %type json_encoding_clause_opt json_predicate_type_constraint json_wrapper_behavior @@ -15763,7 +15763,7 @@ func_expr_common_subexpr: $$ = (Node *) n; } | JSON_QUERY '(' - json_api_common_syntax + json_value_expr ',' a_expr json_passing_clause_opt json_returning_clause_opt json_wrapper_behavior json_quotes_clause_opt @@ -15773,31 +15773,35 @@ func_expr_common_subexpr: JsonFuncExpr *n = makeNode(JsonFuncExpr); n->op = JSON_QUERY_OP; - n->common = (JsonCommon *) $3; - n->output = (JsonOutput *) $4; - n->wrapper = $5; - n->quotes = $6; - n->behavior = $7; + n->context_item = (JsonValueExpr *) $3; + n->pathspec = $5; + n->passing = $6; + n->output = (JsonOutput *) $7; + n->wrapper = $8; + n->quotes = $9; + n->behavior = $10; n->location = @1; $$ = (Node *) n; } | JSON_EXISTS '(' - json_api_common_syntax + json_value_expr ',' a_expr json_passing_clause_opt json_returning_clause_opt json_behavior_clause_opt ')' { - JsonFuncExpr *p = makeNode(JsonFuncExpr); + JsonFuncExpr *n = makeNode(JsonFuncExpr); - p->op = JSON_EXISTS_OP; - p->common = (JsonCommon *) $3; - p->output = (JsonOutput *) $4; - p->behavior = $5; - p->location = @1; - $$ = (Node *) p; + n->op = JSON_EXISTS_OP; + n->context_item = (JsonValueExpr *) $3; + n->pathspec = $5; + n->passing = $6; + n->output = (JsonOutput *) $7; + n->behavior = $8; + n->location = @1; + $$ = (Node *) n; } | JSON_VALUE '(' - json_api_common_syntax + json_value_expr ',' a_expr json_passing_clause_opt json_returning_clause_opt json_behavior_clause_opt ')' @@ -15805,9 +15809,11 @@ func_expr_common_subexpr: JsonFuncExpr *n = makeNode(JsonFuncExpr); n->op = JSON_VALUE_OP; - n->common = (JsonCommon *) $3; - n->output = (JsonOutput *) $4; - n->behavior = $5; + n->context_item = (JsonValueExpr *) $3; + n->pathspec = $5; + n->passing = $6; + n->output = (JsonOutput *) $7; + n->behavior = $8; n->location = @1; $$ = (Node *) n; } @@ -16537,54 +16543,9 @@ opt_asymmetric: ASYMMETRIC ; /* SQL/JSON support */ -json_api_common_syntax: - json_value_expr ',' a_expr /* i.e. a json_path */ - { - JsonCommon *n = makeNode(JsonCommon); - - n->expr = (JsonValueExpr *) $1; - n->pathspec = $3; - n->pathname = NULL; - n->passing = NULL; - n->location = @1; - $$ = (Node *) n; - } - | json_value_expr ',' a_expr AS name - { - JsonCommon *n = makeNode(JsonCommon); - - n->expr = (JsonValueExpr *) $1; - n->pathspec = $3; - n->pathname = $5; - n->passing = NULL; - n->location = @1; - $$ = (Node *) n; - } - - | json_value_expr ',' a_expr /* i.e. a json_path */ - PASSING json_arguments - { - JsonCommon *n = makeNode(JsonCommon); - - n->expr = (JsonValueExpr *) $1; - n->pathspec = $3; - n->pathname = NULL; - n->passing = $5; - n->location = @1; - $$ = (Node *) n; - } - | json_value_expr ',' a_expr AS name - PASSING json_arguments - { - JsonCommon *n = makeNode(JsonCommon); - - n->expr = (JsonValueExpr *) $1; - n->pathspec = $3; - n->pathname = $5; - n->passing = $7; - n->location = @1; - $$ = (Node *) n; - } +json_passing_clause_opt: + PASSING json_arguments { $$ = $2; } + | /*EMPTY*/ { $$ = NIL; } ; json_arguments: diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 2f4d3cb118..af0843aa3c 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -4384,17 +4384,17 @@ transformJsonExprCommon(ParseState *pstate, JsonFuncExpr *func, jsexpr->location = func->location; jsexpr->op = func->op; jsexpr->formatted_expr = transformJsonValueExpr(pstate, constructName, - func->common->expr, + func->context_item, JS_FORMAT_JSON, InvalidOid, false); - jsexpr->format = func->common->expr->format; + jsexpr->format = func->context_item->format; /* Both set in the caller. */ jsexpr->result_coercion = NULL; jsexpr->omit_quotes = false; - pathspec = transformExprRecurse(pstate, func->common->pathspec); + pathspec = transformExprRecurse(pstate, func->pathspec); jsexpr->path_spec = coerce_to_target_type(pstate, pathspec, exprType(pathspec), @@ -4415,7 +4415,7 @@ transformJsonExprCommon(ParseState *pstate, JsonFuncExpr *func, transformJsonPassingArgs(pstate, constructName, exprType(jsexpr->formatted_expr) == JSONBOID ? JS_FORMAT_JSONB : JS_FORMAT_JSON, - func->common->passing, + func->passing, &jsexpr->passing_values, &jsexpr->passing_names); diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 0f977f935e..83acd17ad4 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1731,20 +1731,6 @@ typedef struct JsonArgument char *name; /* argument name */ } JsonArgument; -/* - * JsonCommon - - * representation of common syntax of functions using JSON path - */ -typedef struct JsonCommon -{ - NodeTag type; - JsonValueExpr *expr; /* context item expression */ - Node *pathspec; /* JSON path specification expression */ - char *pathname; /* path name, if any */ - List *passing; /* list of PASSING clause arguments, if any */ - int location; /* token location, or -1 if unknown */ -} JsonCommon; - /* * JsonFuncExpr - * untransformed representation of JSON function expressions @@ -1753,7 +1739,9 @@ typedef struct JsonFuncExpr { NodeTag type; JsonExprOp op; /* expression type */ - JsonCommon *common; /* common syntax */ + JsonValueExpr *context_item; /* context item expression */ + Node *pathspec; /* JSON path specification expression */ + List *passing; /* list of PASSING clause arguments, if any */ JsonOutput *output; /* output clause, if specified */ List *behavior; /* ON EMPTY / ERROR behavior, list of two JsonBehavior nodes */ JsonWrapper wrapper; /* array wrapper behavior (JSON_QUERY only) */ diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 9258576b4c..8186a42659 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -1263,7 +1263,6 @@ JsonBehavior JsonBehaviorType JsonCoercion JsonCoercionState -JsonCommon JsonConstructorExpr JsonConstructorExprState JsonConstructorType -- 2.42.1