Skip to content

Commit cb9c994

Browse files
committed
Clean Util Grammar Rule Stmts
Make it look more Postgres like.
1 parent 6108f0a commit cb9c994

File tree

2 files changed

+41
-51
lines changed

2 files changed

+41
-51
lines changed

regress/expected/cypher_match.out

+12-19
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,11 @@ ERROR: operator does not exist: postgraph.graphid = postgraph.graphid
244244
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
245245
-- Property Constraint in EXISTS
246246
MATCH (u) WHERE EXISTS((u)-[]->({id: "middle"})) RETURN u;
247-
ERROR: operator does not exist: postgraph.gtype @> postgraph.gtype
248-
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
247+
ERROR: MATCH cannot be the last clause in a cypher statement
249248
MATCH (u) WHERE EXISTS((u)-[]->({id: "not a valid id"})) RETURN u;
250-
ERROR: operator does not exist: postgraph.gtype @> postgraph.gtype
251-
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
249+
ERROR: MATCH cannot be the last clause in a cypher statement
252250
MATCH (u) WHERE EXISTS((u)-[]->({id: NULL})) RETURN u;
253-
ERROR: operator does not exist: postgraph.gtype @> postgraph.gtype
254-
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
251+
ERROR: MATCH cannot be the last clause in a cypher statement
255252
-- Exists checks for a loop. There shouldn't be any.
256253
MATCH (u)-[e]->(v) WHERE EXISTS((u)-[e]->(u)) RETURN u, e, v;
257254
ERROR: operator does not exist: postgraph.graphid = postgraph.graphid
@@ -331,8 +328,7 @@ MATCH (u) RETURN case WHEN EXISTS(MATCH (u)-[]->() RETURN 1) THEN 1 ELSE 2 END;
331328
ERROR: operator does not exist: postgraph.graphid = postgraph.graphid
332329
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
333330
MATCH (u) RETURN case WHEN EXISTS((u)-[]->()) THEN 1 ELSE 2 END;
334-
ERROR: operator does not exist: postgraph.graphid = postgraph.graphid
335-
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
331+
ERROR: MATCH cannot be the last clause in a cypher statement
336332
/*
337333
EXPLAIN
338334
SELECT *
@@ -446,12 +442,13 @@ LINE 1: ORDER BY n, p, m, q;
446442
MATCH (n:opt_match_v), (m:opt_match_v)
447443
WHERE id(n) <> id(m)
448444
OPTIONAL MATCH (n)-[r]->(p), (m)-[s]->(q)
449-
RETURN n.name AS n, type(r)
445+
RETURN n.name AS n, type(r),
450446
m.name AS m, type(s)
451447
ORDER BY n, p, m, q;
452-
ERROR: syntax error at or near "m"
453-
LINE 5: m.name AS m, type(s)
454-
^
448+
ERROR: operator is not unique: postgraph.gtype <> postgraph.gtype
449+
LINE 2: WHERE id(n) <> id(m)
450+
^
451+
HINT: Could not choose a best candidate operator. You might need to add explicit type casts.
455452
CREATE (u {name: "orphan"}) CREATE (u1 {name: "F"})-[u2:e1]->(u3 {name: "T"}) RETURN u1, u2, u3;
456453
u1 | u2 | u3
457454
-------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------
@@ -460,12 +457,10 @@ CREATE (u {name: "orphan"}) CREATE (u1 {name: "F"})-[u2:e1]->(u3 {name: "T"}) RE
460457

461458
-- Querying NOT EXISTS syntax
462459
MATCH (f),(t) WHERE NOT EXISTS((f)-[]->(t)) RETURN f.name, t.name;
463-
ERROR: operator does not exist: postgraph.graphid = postgraph.graphid
464-
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
460+
ERROR: MATCH cannot be the last clause in a cypher statement
465461
-- Querying EXISTS syntax
466462
MATCH (f),(t) WHERE EXISTS((f)-[]->(t)) RETURN f.name, t.name;
467-
ERROR: operator does not exist: postgraph.graphid = postgraph.graphid
468-
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
463+
ERROR: MATCH cannot be the last clause in a cypher statement
469464
--
470465
-- Constraints and WHERE clause together
471466
--
@@ -485,9 +480,7 @@ HINT: No operator matches the given name and argument types. You might need to
485480
--
486481
-- need a following RETURN clause
487482
MATCH (n:v);
488-
ERROR: syntax error at or near ";"
489-
LINE 1: MATCH (n:v);
490-
^
483+
ERROR: MATCH cannot be the last clause in a cypher statement
491484
--Invalid Variables
492485
MATCH (a)-[]-()-[]-(a:v1) RETURN a;
493486
ERROR: variable a already exists

src/backend/parser/cypher_gram.y

+29-32
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@
118118
/* query */
119119
%type <node> stmt
120120
%type <list> single_query cypher_stmt
121-
use drop
121+
122122

123-
%type <node> util_stmt
123+
%type <node> CreateExtensionStmt CreateGraphStmt CreateTableStmt
124+
DropGraphStmt
125+
UseGraphStmt
124126
%type <node> clause
125127

126128
/* RETURN and WITH clause */
@@ -282,28 +284,17 @@ doNegateFloat(Value *v);
282284
stmt:
283285
cypher_stmt semicolon_opt
284286
{
285-
/*
286-
* If there is no transition for the lookahead token and the
287-
* clauses can be reduced to single_query, the parsing is
288-
* considered successful although it actually isn't.
289-
*
290-
* For example, when `MATCH ... CREATE ... MATCH ... ;` query is
291-
* being parsed, there is no transition for the second `MATCH ...`
292-
* because the query is wrong but `MATCH .. CREATE ...` is correct
293-
* so it will be reduced to query_part_last anyway even if there
294-
* are more tokens to read.
295-
*
296-
* Throw syntax error in this case.
297-
*/
287+
298288
//if (yychar != YYEOF)
299289
//yyerror(&yylloc, scanner, extra, "syntax error");
300290

301291
extra->result = $1;
302292
}
303-
| util_stmt semicolon_opt
304-
{
305-
extra->result = list_make1($1);
306-
}
293+
| CreateGraphStmt semicolon_opt { extra->result = list_make1($1); }
294+
| CreateExtensionStmt semicolon_opt { extra->result = list_make1($1); }
295+
| CreateTableStmt semicolon_opt { extra->result = list_make1($1); }
296+
| DropGraphStmt semicolon_opt { extra->result = list_make1($1); }
297+
| UseGraphStmt semicolon_opt { extra->result = list_make1($1); }
307298
;
308299

309300
cypher_stmt:
@@ -329,7 +320,7 @@ cypher_stmt:
329320
}
330321
;
331322

332-
util_stmt:
323+
CreateGraphStmt:
333324
CREATE GRAPH IDENTIFIER
334325
{
335326

@@ -338,8 +329,11 @@ util_stmt:
338329
n->graph_name = $3;
339330

340331
$$ = (Node *)n;
341-
}
342-
| CREATE EXTENSION IDENTIFIER create_extension_opt_list
332+
}
333+
;
334+
335+
CreateExtensionStmt:
336+
CREATE EXTENSION IDENTIFIER create_extension_opt_list
343337
{
344338
CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
345339

@@ -359,7 +353,10 @@ util_stmt:
359353

360354
$$ = (Node *) n;
361355
}
362-
| CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
356+
;
357+
358+
CreateTableStmt:
359+
CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
363360
OptInherit OptPartitionSpec table_access_method_clause OptWith
364361
//OnCommitOption OptTableSpace
365362
{
@@ -392,10 +389,9 @@ util_stmt:
392389
n->if_not_exists = false;
393390

394391
$$ = (Node *)n;
395-
}
396-
| use { $$ = linitial($1); }
397-
| drop { $$ = linitial($1); }
398-
;
392+
}
393+
394+
399395
call_stmt:
400396
CALL expr_func_norm AS var_name where_opt
401397
{
@@ -544,25 +540,26 @@ clause:
544540
| unwind
545541
;
546542

547-
use:
543+
544+
UseGraphStmt:
548545
USE GRAPH IDENTIFIER
549546
{
550547
cypher_use_graph *n = make_ag_node(cypher_use_graph);
551548
n->graph_name = $3;
552549

553-
$$ = list_make1(n);
550+
$$ = n;
554551
};
555552

556-
drop:
553+
DropGraphStmt:
557554
DROP GRAPH IDENTIFIER CASCADE
558555
{
559556

560557
cypher_drop_graph *n = make_ag_node(cypher_drop_graph);
561558
n->graph_name = $3;
562559
n->cascade = true;
563560

564-
$$ = list_make1(n);
565-
}
561+
$$ = n;
562+
};
566563

567564
cypher_varlen_opt:
568565
'*' cypher_range_opt

0 commit comments

Comments
 (0)