PostgreSQL Source Code git master
Loading...
Searching...
No Matches
parse_graphtable.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "catalog/pg_propgraph_label.h"
#include "catalog/pg_propgraph_property.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_collate.h"
#include "parser/parse_expr.h"
#include "parser/parse_graphtable.h"
#include "parser/parse_node.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/relcache.h"
#include "utils/syscache.h"
Include dependency graph for parse_graphtable.c:

Go to the source code of this file.

Functions

static const charget_gep_kind_name (GraphElementPatternKind gepkind)
 
NodetransformGraphTablePropertyRef (ParseState *pstate, ColumnRef *cref)
 
static NodetransformLabelExpr (GraphTableParseState *gpstate, Node *labelexpr)
 
static NodetransformGraphElementPattern (ParseState *pstate, GraphElementPattern *gep)
 
static NodetransformPathTerm (ParseState *pstate, List *path_term)
 
static NodetransformPathPatternList (ParseState *pstate, List *path_pattern)
 
NodetransformGraphPattern (ParseState *pstate, GraphPattern *graph_pattern)
 

Function Documentation

◆ get_gep_kind_name()

static const char * get_gep_kind_name ( GraphElementPatternKind  gepkind)
static

Definition at line 40 of file parse_graphtable.c.

41{
42 switch (gepkind)
43 {
44 case VERTEX_PATTERN:
45 return "vertex";
47 return "edge pointing left";
49 return "edge pointing right";
51 return "edge pointing any direction";
52 case PAREN_EXPR:
53 return "nested path pattern";
54 }
55
56 /*
57 * When a GraphElementPattern is constructed by the parser, it will set a
58 * value from the GraphElementPatternKind enum. But we may get here if the
59 * GraphElementPatternKind value stored in a catalog is corrupted.
60 */
61 return "unknown";
62}
@ EDGE_PATTERN_RIGHT
@ VERTEX_PATTERN
@ EDGE_PATTERN_LEFT
@ PAREN_EXPR
@ EDGE_PATTERN_ANY
static int fb(int x)

References EDGE_PATTERN_ANY, EDGE_PATTERN_LEFT, EDGE_PATTERN_RIGHT, fb(), PAREN_EXPR, and VERTEX_PATTERN.

Referenced by transformGraphElementPattern().

◆ transformGraphElementPattern()

static Node * transformGraphElementPattern ( ParseState pstate,
GraphElementPattern gep 
)
static

Definition at line 224 of file parse_graphtable.c.

225{
227
228 if (gep->kind != VERTEX_PATTERN && !IS_EDGE_PATTERN(gep->kind))
231 errmsg("unsupported element pattern kind: \"%s\"", get_gep_kind_name(gep->kind)));
232
233 if (gep->quantifier)
236 errmsg("element pattern quantifier is not supported")));
237
238 if (gep->variable)
239 gpstate->variables = lappend(gpstate->variables, makeString(pstrdup(gep->variable)));
240
241 gep->labelexpr = transformLabelExpr(gpstate, gep->labelexpr);
242
243 gep->whereClause = transformExpr(pstate, gep->whereClause, EXPR_KIND_WHERE);
244 assign_expr_collations(pstate, gep->whereClause);
245
246 return (Node *) gep;
247}
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
List * lappend(List *list, void *datum)
Definition list.c:339
char * pstrdup(const char *in)
Definition mcxt.c:1781
static char * errmsg
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition parse_expr.c:121
static const char * get_gep_kind_name(GraphElementPatternKind gepkind)
static Node * transformLabelExpr(GraphTableParseState *gpstate, Node *labelexpr)
@ EXPR_KIND_WHERE
Definition parse_node.h:46
#define IS_EDGE_PATTERN(kind)
Definition nodes.h:135
GraphTableParseState * p_graph_table_pstate
Definition parse_node.h:238
String * makeString(char *str)
Definition value.c:63

References assign_expr_collations(), ereport, errcode(), errmsg, ERROR, EXPR_KIND_WHERE, fb(), get_gep_kind_name(), IS_EDGE_PATTERN, lappend(), makeString(), ParseState::p_graph_table_pstate, pstrdup(), transformExpr(), transformLabelExpr(), and VERTEX_PATTERN.

Referenced by transformPathTerm().

◆ transformGraphPattern()

Node * transformGraphPattern ( ParseState pstate,
GraphPattern graph_pattern 
)

Definition at line 299 of file parse_graphtable.c.

300{
301 List *path_pattern_list = castNode(List,
302 transformPathPatternList(pstate, graph_pattern->path_pattern_list));
303
304 graph_pattern->path_pattern_list = path_pattern_list;
305 graph_pattern->whereClause = transformExpr(pstate, graph_pattern->whereClause, EXPR_KIND_WHERE);
306 assign_expr_collations(pstate, graph_pattern->whereClause);
307
308 return (Node *) graph_pattern;
309}
#define castNode(_type_, nodeptr)
Definition nodes.h:182
static Node * transformPathPatternList(ParseState *pstate, List *path_pattern)
Node * whereClause
List * path_pattern_list
Definition pg_list.h:54

References assign_expr_collations(), castNode, EXPR_KIND_WHERE, GraphPattern::path_pattern_list, transformExpr(), transformPathPatternList(), and GraphPattern::whereClause.

Referenced by transformRangeGraphTable().

◆ transformGraphTablePropertyRef()

Node * transformGraphTablePropertyRef ( ParseState pstate,
ColumnRef cref 
)

Definition at line 79 of file parse_graphtable.c.

80{
82
83 if (!gpstate)
84 return NULL;
85
86 if (list_length(cref->fields) == 2)
87 {
88 Node *field1 = linitial(cref->fields);
89 Node *field2 = lsecond(cref->fields);
90 char *elvarname;
91 char *propname;
92
93 if (IsA(field1, A_Star) || IsA(field2, A_Star))
94 {
98 errmsg("\"*\" is not supported here"),
99 parser_errposition(pstate, cref->location));
100 else
103 errmsg("\"*\" not allowed here"),
104 parser_errposition(pstate, cref->location));
105 }
106
107 elvarname = strVal(field1);
109
110 if (list_member(gpstate->variables, field1))
111 {
115
120 errmsg("property \"%s\" does not exist", propname));
122
123 gpr->location = cref->location;
124 gpr->elvarname = elvarname;
125 gpr->propid = pgpform->oid;
126 gpr->typeId = pgpform->pgptypid;
127 gpr->typmod = pgpform->pgptypmod;
128 gpr->collation = pgpform->pgpcollation;
129
131
132 return (Node *) gpr;
133 }
134 }
135
136 return NULL;
137}
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
bool list_member(const List *list, const void *datum)
Definition list.c:661
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define makeNode(_type_)
Definition nodes.h:161
int parser_errposition(ParseState *pstate, int location)
Definition parse_node.c:106
@ EXPR_KIND_SELECT_TARGET
Definition parse_node.h:54
static int list_length(const List *l)
Definition pg_list.h:152
#define linitial(l)
Definition pg_list.h:178
#define lsecond(l)
Definition pg_list.h:183
END_CATALOG_STRUCT typedef FormData_pg_propgraph_property * Form_pg_propgraph_property
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
static Datum CStringGetDatum(const char *X)
Definition postgres.h:370
ParseExprKind p_expr_kind
Definition parse_node.h:228
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:230
#define strVal(v)
Definition value.h:82

References CStringGetDatum(), ereport, errcode(), errmsg, ERROR, EXPR_KIND_SELECT_TARGET, fb(), Form_pg_propgraph_property, GETSTRUCT(), HeapTupleIsValid, IsA, linitial, list_length(), list_member(), lsecond, makeNode, ObjectIdGetDatum(), ParseState::p_expr_kind, ParseState::p_graph_table_pstate, parser_errposition(), ReleaseSysCache(), SearchSysCache2(), and strVal.

Referenced by transformColumnRef().

◆ transformLabelExpr()

static Node * transformLabelExpr ( GraphTableParseState gpstate,
Node labelexpr 
)
static

Definition at line 151 of file parse_graphtable.c.

152{
153 Node *result;
154
155 if (labelexpr == NULL)
156 return NULL;
157
159
160 switch (nodeTag(labelexpr))
161 {
162 case T_ColumnRef:
163 {
164 ColumnRef *cref = (ColumnRef *) labelexpr;
165 const char *labelname;
166 Oid labelid;
168
169 Assert(list_length(cref->fields) == 1);
170 labelname = strVal(linitial(cref->fields));
171
173 if (!labelid)
176 errmsg("label \"%s\" does not exist in property graph \"%s\"", labelname, get_rel_name(gpstate->graphid)));
177
179 lref->labelid = labelid;
180 lref->location = cref->location;
181
182 result = (Node *) lref;
183 break;
184 }
185
186 case T_BoolExpr:
187 {
188 BoolExpr *be = (BoolExpr *) labelexpr;
189 ListCell *lc;
190 List *args = NIL;
191
192 foreach(lc, be->args)
193 {
194 Node *arg = (Node *) lfirst(lc);
195
197 args = lappend(args, arg);
198 }
199
200 result = (Node *) makeBoolExpr(be->boolop, args, be->location);
201 break;
202 }
203
204 default:
205 /* should not reach here */
206 elog(ERROR, "unsupported label expression node: %d", (int) nodeTag(labelexpr));
207 result = NULL; /* keep compiler quiet */
208 break;
209 }
210
211 return result;
212}
#define Assert(condition)
Definition c.h:942
Datum arg
Definition elog.c:1322
#define elog(elevel,...)
Definition elog.h:226
char * get_rel_name(Oid relid)
Definition lsyscache.c:2148
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition makefuncs.c:420
#define nodeTag(nodeptr)
Definition nodes.h:139
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
unsigned int Oid
void check_stack_depth(void)
Definition stack_depth.c:95
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition syscache.h:111

References arg, Assert, check_stack_depth(), CStringGetDatum(), elog, ereport, errcode(), errmsg, ERROR, fb(), get_rel_name(), GetSysCacheOid2, lappend(), lfirst, linitial, list_length(), makeBoolExpr(), makeNode, NIL, nodeTag, ObjectIdGetDatum(), strVal, and transformLabelExpr().

Referenced by transformGraphElementPattern(), and transformLabelExpr().

◆ transformPathPatternList()

static Node * transformPathPatternList ( ParseState pstate,
List path_pattern 
)
static

Definition at line 268 of file parse_graphtable.c.

269{
270 List *result = NIL;
271
272 /* Grammar doesn't allow empty path pattern list */
274
275 /*
276 * We do not support multiple path patterns in one GRAPH_TABLE clause
277 * right now. But we may do so in future.
278 */
279 if (list_length(path_pattern) != 1)
282 errmsg("multiple path patterns in one GRAPH_TABLE clause not supported")));
283
285 result = lappend(result, transformPathTerm(pstate, path_term));
286
287 return (Node *) result;
288}
static Node * transformPathTerm(ParseState *pstate, List *path_term)
#define foreach_node(type, var, lst)
Definition pg_list.h:496

References Assert, ereport, errcode(), errmsg, ERROR, fb(), foreach_node, lappend(), list_length(), NIL, and transformPathTerm().

Referenced by transformGraphPattern().

◆ transformPathTerm()

static Node * transformPathTerm ( ParseState pstate,
List path_term 
)
static

Definition at line 253 of file parse_graphtable.c.

254{
255 List *result = NIL;
256
258 result = lappend(result,
260
261 return (Node *) result;
262}
static Node * transformGraphElementPattern(ParseState *pstate, GraphElementPattern *gep)

References fb(), foreach_node, lappend(), NIL, and transformGraphElementPattern().

Referenced by transformPathPatternList().