Skip to content

Commit 6108f0a

Browse files
committed
Fix Grammar Issues Around CREATE
Get those utils out of cypher_stmt and out on their own
1 parent 4aad1ac commit 6108f0a

File tree

4 files changed

+101
-145
lines changed

4 files changed

+101
-145
lines changed

regress/expected/cypher_order.out.diff

Whitespace-only changes.

regress/sql/cypher_match.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ OPTIONAL MATCH (n:opt_match_v)-[r]->(p), (m:opt_match_v)-[s]->(q) WHERE id(n) <>
264264
MATCH (n:opt_match_v), (m:opt_match_v)
265265
WHERE id(n) <> id(m)
266266
OPTIONAL MATCH (n)-[r]->(p), (m)-[s]->(q)
267-
RETURN n.name AS n, type(r)
267+
RETURN n.name AS n, type(r),
268268
m.name AS m, type(s)
269269
ORDER BY n, p, m, q;
270270

src/backend/parser/cypher_clause.c

+5
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,11 @@ static Query *transform_cypher_clause_with_where(cypher_parsestate *cpstate, tra
22542254
}
22552255

22562256
static Query *transform_cypher_match(cypher_parsestate *cpstate, cypher_clause *clause) {
2257+
if (clause->next == NULL)
2258+
ereport(ERROR,
2259+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2260+
errmsg("MATCH cannot be the last clause in a cypher statement")));
2261+
22572262
return transform_cypher_clause_with_where(cpstate, transform_cypher_match_pattern, clause);
22582263
}
22592264

src/backend/parser/cypher_gram.y

+95-144
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@
117117

118118
/* query */
119119
%type <node> stmt
120-
%type <list> single_query query_part_init query_part_last cypher_stmt
121-
reading_clause_list updating_clause_list_0 updating_clause_list_1
120+
%type <list> single_query cypher_stmt
122121
use drop
123-
%type <node> reading_clause updating_clause
122+
123+
%type <node> util_stmt
124+
%type <node> clause
124125

125126
/* RETURN and WITH clause */
126127
%type <node> empty_grouping_set cube_clause rollup_clause group_item having_opt return return_item sort_item skip_opt limit_opt with
@@ -299,6 +300,10 @@ stmt:
299300

300301
extra->result = $1;
301302
}
303+
| util_stmt semicolon_opt
304+
{
305+
extra->result = list_make1($1);
306+
}
302307
;
303308

304309
cypher_stmt:
@@ -324,6 +329,73 @@ cypher_stmt:
324329
}
325330
;
326331

332+
util_stmt:
333+
CREATE GRAPH IDENTIFIER
334+
{
335+
336+
cypher_create_graph *n;
337+
n = make_ag_node(cypher_create_graph);
338+
n->graph_name = $3;
339+
340+
$$ = (Node *)n;
341+
}
342+
| CREATE EXTENSION IDENTIFIER create_extension_opt_list
343+
{
344+
CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
345+
346+
n->extname = $3;
347+
n->if_not_exists = false;
348+
n->options = $4;
349+
350+
$$ = (Node *) n;
351+
}
352+
| CREATE EXTENSION IF NOT EXISTS IDENTIFIER create_extension_opt_list
353+
{
354+
CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
355+
356+
n->extname = $6;
357+
n->if_not_exists = true;
358+
n->options = $7;
359+
360+
$$ = (Node *) n;
361+
}
362+
| CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
363+
OptInherit OptPartitionSpec table_access_method_clause OptWith
364+
//OnCommitOption OptTableSpace
365+
{
366+
CreateStmt *n = makeNode(CreateStmt);
367+
/*
368+
$4->relpersistence = $2;
369+
n->relation = $4;
370+
n->tableElts = $6;
371+
n->inhRelations = $8;
372+
n->partspec = $9;
373+
n->ofTypename = NULL;
374+
n->constraints = NIL;
375+
n->accessMethod = $10;
376+
n->options = $11;
377+
n->oncommit = $12;
378+
n->tablespacename = $13;
379+
n->if_not_exists = false;
380+
*/
381+
$4->relpersistence = $2;
382+
n->relation = $4;
383+
n->tableElts = $6;
384+
n->inhRelations = $8;
385+
n->partspec = $9;
386+
n->ofTypename = NULL;
387+
n->constraints = NIL;
388+
n->accessMethod = $10;
389+
n->options = $11;
390+
n->oncommit = ONCOMMIT_NOOP;
391+
n->tablespacename = NULL;
392+
n->if_not_exists = false;
393+
394+
$$ = (Node *)n;
395+
}
396+
| use { $$ = linitial($1); }
397+
| drop { $$ = linitial($1); }
398+
;
327399
call_stmt:
328400
CALL expr_func_norm AS var_name where_opt
329401
{
@@ -451,18 +523,25 @@ all_or_distinct:
451523
* reading_clause* ( updating_clause+ | updating_clause* return )
452524
*/
453525
single_query:
454-
query_part_init query_part_last
455-
{
456-
$$ = list_concat($1, $2);
457-
}
458-
| use
459-
{
460-
$$ = $1;
461-
}
462-
| drop
463-
{
464-
$$ = $1;
465-
}
526+
clause {
527+
$$ = list_make1($1);
528+
}
529+
| single_query clause {
530+
$$ = lappend($1, $2);
531+
}
532+
;
533+
534+
clause:
535+
create
536+
| set
537+
| remove
538+
| match
539+
| with
540+
| delete
541+
| merge
542+
| call_stmt
543+
| return
544+
| unwind
466545
;
467546

468547
use:
@@ -485,72 +564,6 @@ drop:
485564
$$ = list_make1(n);
486565
}
487566

488-
query_part_init:
489-
/* empty */
490-
{
491-
$$ = NIL;
492-
}
493-
| query_part_init reading_clause_list updating_clause_list_0 with
494-
{
495-
$$ = lappend(list_concat(list_concat($1, $2), $3), $4);
496-
}
497-
;
498-
499-
query_part_last:
500-
reading_clause_list updating_clause_list_1
501-
{
502-
$$ = list_concat($1, $2);
503-
}
504-
| reading_clause_list updating_clause_list_0 return
505-
{
506-
$$ = lappend(list_concat($1, $2), $3);
507-
}
508-
;
509-
510-
reading_clause_list:
511-
/* empty */
512-
{
513-
$$ = NIL;
514-
}
515-
| reading_clause_list reading_clause
516-
{
517-
$$ = lappend($1, $2);
518-
}
519-
;
520-
521-
reading_clause:
522-
match
523-
| unwind
524-
;
525-
526-
updating_clause_list_0:
527-
/* empty */
528-
{
529-
$$ = NIL;
530-
}
531-
| updating_clause_list_1
532-
;
533-
534-
updating_clause_list_1:
535-
updating_clause
536-
{
537-
$$ = list_make1($1);
538-
}
539-
| updating_clause_list_1 updating_clause
540-
{
541-
$$ = lappend($1, $2);
542-
}
543-
;
544-
545-
updating_clause:
546-
create
547-
| set
548-
| remove
549-
| delete
550-
| merge
551-
| call_stmt
552-
;
553-
554567
cypher_varlen_opt:
555568
'*' cypher_range_opt
556569
{
@@ -1003,69 +1016,7 @@ create:
10031016

10041017
$$ = (Node *)n;
10051018
}
1006-
| CREATE GRAPH IDENTIFIER
1007-
{
1008-
1009-
cypher_create_graph *n;
1010-
n = make_ag_node(cypher_create_graph);
1011-
n->graph_name = $3;
1012-
1013-
$$ = (Node *)n;
1014-
}
1015-
| CREATE EXTENSION IDENTIFIER create_extension_opt_list
1016-
{
1017-
CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
1018-
1019-
n->extname = $3;
1020-
n->if_not_exists = false;
1021-
n->options = $4;
1022-
1023-
$$ = (Node *) n;
1024-
}
1025-
| CREATE EXTENSION IF NOT EXISTS IDENTIFIER create_extension_opt_list
1026-
{
1027-
CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
1028-
1029-
n->extname = $6;
1030-
n->if_not_exists = true;
1031-
n->options = $7;
1032-
1033-
$$ = (Node *) n;
1034-
}
1035-
| CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
1036-
OptInherit OptPartitionSpec table_access_method_clause OptWith
1037-
//OnCommitOption OptTableSpace
1038-
{
1039-
CreateStmt *n = makeNode(CreateStmt);
1040-
/*
1041-
$4->relpersistence = $2;
1042-
n->relation = $4;
1043-
n->tableElts = $6;
1044-
n->inhRelations = $8;
1045-
n->partspec = $9;
1046-
n->ofTypename = NULL;
1047-
n->constraints = NIL;
1048-
n->accessMethod = $10;
1049-
n->options = $11;
1050-
n->oncommit = $12;
1051-
n->tablespacename = $13;
1052-
n->if_not_exists = false;
1053-
*/
1054-
$4->relpersistence = $2;
1055-
n->relation = $4;
1056-
n->tableElts = $6;
1057-
n->inhRelations = $8;
1058-
n->partspec = $9;
1059-
n->ofTypename = NULL;
1060-
n->constraints = NIL;
1061-
n->accessMethod = $10;
1062-
n->options = $11;
1063-
n->oncommit = ONCOMMIT_NOOP;
1064-
n->tablespacename = NULL;
1065-
n->if_not_exists = false;
1066-
1067-
$$ = (Node *)n;
1068-
}
1019+
10691020
;
10701021

10711022

0 commit comments

Comments
 (0)