Skip to content

Commit ceb864a

Browse files
author
Nikita Glukhov
committed
Add nodes JsonFormat and JsonRetuning
1 parent 59f8c5c commit ceb864a

File tree

6 files changed

+45
-29
lines changed

6 files changed

+45
-29
lines changed

src/backend/nodes/makefuncs.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,28 @@ makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
816816
return v;
817817
}
818818

819+
/*
820+
* makeJsonFormat -
821+
* creates a JsonFormat node
822+
*/
823+
JsonFormat *
824+
makeJsonFormat(JsonFormatType type, JsonEncoding encoding, int location)
825+
{
826+
JsonFormat *jf = makeNode(JsonFormat);
827+
828+
jf->format = type;
829+
jf->encoding = encoding;
830+
jf->location = location;
831+
832+
return jf;
833+
}
834+
819835
/*
820836
* makeJsonValueExpr -
821837
* creates a JsonValueExpr node
822838
*/
823839
JsonValueExpr *
824-
makeJsonValueExpr(Expr *expr, JsonFormat format)
840+
makeJsonValueExpr(Expr *expr, JsonFormat *format)
825841
{
826842
JsonValueExpr *jve = makeNode(JsonValueExpr);
827843

src/backend/parser/gram.y

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
220220
JoinType jtype;
221221
DropBehavior dbehavior;
222222
OnCommitAction oncommit;
223-
JsonFormat jsformat;
224223
List *list;
225224
Node *node;
226225
Value *value;
@@ -600,15 +599,14 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
600599
%type <list> hash_partbound
601600
%type <defelt> hash_partbound_elem
602601

603-
%type <node> json_value_expr
602+
%type <node> json_format_clause_opt
603+
json_representation
604+
json_value_expr
604605
json_output_clause_opt
605606

606607
%type <ival> json_encoding
607608
json_encoding_clause_opt
608609

609-
%type <jsformat> json_format_clause_opt
610-
json_representation
611-
612610
/*
613611
* Non-keyword token types. These are hard-wired into the "flex" lexer.
614612
* They must be listed first so that their numeric codes do not depend on
@@ -14662,18 +14660,14 @@ json_format_clause_opt:
1466214660
}
1466314661
| /* EMPTY */
1466414662
{
14665-
$$.type = JS_FORMAT_DEFAULT;
14666-
$$.encoding = JS_ENC_DEFAULT;
14667-
$$.location = -1;
14663+
$$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
1466814664
}
1466914665
;
1467014666

1467114667
json_representation:
1467214668
JSON json_encoding_clause_opt
1467314669
{
14674-
$$.type = JS_FORMAT_JSON;
14675-
$$.encoding = $2;
14676-
$$.location = @1;
14670+
$$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, $2, @1);
1467714671
}
1467814672
/* | implementation_defined_JSON_representation_option (BSON, AVRO etc) */
1467914673
;

src/include/nodes/makefuncs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ extern GroupingSet *makeGroupingSet(GroupingSetKind kind, List *content, int loc
105105

106106
extern VacuumRelation *makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols);
107107

108-
extern JsonValueExpr *makeJsonValueExpr(Expr *expr, JsonFormat format);
108+
extern JsonFormat *makeJsonFormat(JsonFormatType type, JsonEncoding encoding,
109+
int location);
110+
extern JsonValueExpr *makeJsonValueExpr(Expr *expr, JsonFormat *format);
109111
extern JsonEncoding makeJsonEncoding(char *name);
110112

111113
#endif /* MAKEFUNC_H */

src/include/nodes/nodes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ typedef enum NodeTag
198198
T_FromExpr,
199199
T_OnConflictExpr,
200200
T_IntoClause,
201+
T_JsonFormat,
202+
T_JsonReturning,
203+
T_JsonValueExpr,
201204

202205
/*
203206
* TAGS FOR EXPRESSION STATE NODES (execnodes.h)
@@ -481,7 +484,6 @@ typedef enum NodeTag
481484
T_PartitionRangeDatum,
482485
T_PartitionCmd,
483486
T_VacuumRelation,
484-
T_JsonValueExpr,
485487
T_JsonOutput,
486488

487489
/*

src/include/nodes/parsenodes.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,17 +1499,6 @@ typedef struct JsonOutput
14991499
JsonReturning returning; /* RETURNING FORMAT clause and type Oids */
15001500
} JsonOutput;
15011501

1502-
/*
1503-
* JsonValueExpr -
1504-
* representation of JSON value expression (expr [FORMAT json_format])
1505-
*/
1506-
typedef struct JsonValueExpr
1507-
{
1508-
NodeTag type;
1509-
Expr *expr; /* raw expression */
1510-
JsonFormat format; /* FORMAT clause, if specified */
1511-
} JsonValueExpr;
1512-
15131502

15141503
/*****************************************************************************
15151504
* Raw Grammar Output Statements

src/include/nodes/primnodes.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,9 +1218,10 @@ typedef enum JsonFormatType
12181218
*/
12191219
typedef struct JsonFormat
12201220
{
1221-
JsonFormatType type; /* format type */
1222-
JsonEncoding encoding; /* JSON encoding */
1223-
int location; /* token location, or -1 if unknown */
1221+
NodeTag type;
1222+
JsonFormatType format; /* format type */
1223+
JsonEncoding encoding; /* JSON encoding */
1224+
int location; /* token location, or -1 if unknown */
12241225
} JsonFormat;
12251226

12261227
/*
@@ -1229,11 +1230,23 @@ typedef struct JsonFormat
12291230
*/
12301231
typedef struct JsonReturning
12311232
{
1232-
JsonFormat format; /* output JSON format */
1233+
NodeTag type;
1234+
JsonFormat *format; /* output JSON format */
12331235
Oid typid; /* target type Oid */
12341236
int32 typmod; /* target type modifier */
12351237
} JsonReturning;
12361238

1239+
/*
1240+
* JsonValueExpr -
1241+
* representation of JSON value expression (expr [FORMAT json_format])
1242+
*/
1243+
typedef struct JsonValueExpr
1244+
{
1245+
NodeTag type;
1246+
Expr *expr; /* raw expression */
1247+
JsonFormat *format; /* FORMAT clause, if specified */
1248+
} JsonValueExpr;
1249+
12371250
/* ----------------
12381251
* NullTest
12391252
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy