Skip to content

Commit

Permalink
Fixed case sensitivity on label usage of reserved keyword (apache#1040)
Browse files Browse the repository at this point in the history
Fixed the case when a label was assigned a name of a
reserved keyword, resulting in the label being lowercase
regardless of the user input.

Signed-off-by: Panagiotis Foliadis<[email protected]>
  • Loading branch information
panosfol authored and MuhammadTahaNaveed committed Aug 24, 2023
1 parent 4a01811 commit f48285f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
33 changes: 32 additions & 1 deletion regress/expected/cypher_create.out
Original file line number Diff line number Diff line change
Expand Up @@ -765,13 +765,41 @@ $$) as (a agtype);
ERROR: variable e already exists
LINE 3: CREATE (p)-[e:new]->(a)
^
-- Validate usage of keywords as labels is supported and case sensitive
SELECT * FROM cypher('cypher_create', $$
CREATE (a:CREATE)
RETURN a
$$) as (a agtype);
a
-----------------------------------------------------------------------
{"id": 5348024557502465, "label": "CREATE", "properties": {}}::vertex
(1 row)

SELECT * FROM cypher('cypher_create', $$
CREATE (a:create)
RETURN a
$$) as (a agtype);
a
-----------------------------------------------------------------------
{"id": 5629499534213121, "label": "create", "properties": {}}::vertex
(1 row)

SELECT * FROM cypher('cypher_create', $$
CREATE (a:CrEaTe)
RETURN a
$$) as (a agtype);
a
-----------------------------------------------------------------------
{"id": 5910974510923777, "label": "CrEaTe", "properties": {}}::vertex
(1 row)

--
-- Clean up
--
DROP TABLE simple_path;
DROP FUNCTION create_test;
SELECT drop_graph('cypher_create', true);
NOTICE: drop cascades to 16 other objects
NOTICE: drop cascades to 19 other objects
DETAIL: drop cascades to table cypher_create._ag_label_vertex
drop cascades to table cypher_create._ag_label_edge
drop cascades to table cypher_create.v
Expand All @@ -788,6 +816,9 @@ drop cascades to table cypher_create."Part"
drop cascades to table cypher_create.new
drop cascades to table cypher_create.node
drop cascades to table cypher_create.n1
drop cascades to table cypher_create."CREATE"
drop cascades to table cypher_create."create"
drop cascades to table cypher_create."CrEaTe"
NOTICE: graph "cypher_create" has been dropped
drop_graph
------------
Expand Down
18 changes: 18 additions & 0 deletions regress/sql/cypher_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,24 @@ SELECT * FROM cypher('cypher_create', $$
CREATE (p)-[e:new]->(a)
$$) as (a agtype);


-- Validate usage of keywords as labels is supported and case sensitive

SELECT * FROM cypher('cypher_create', $$
CREATE (a:CREATE)
RETURN a
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE (a:create)
RETURN a
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE (a:CrEaTe)
RETURN a
$$) as (a agtype);

--
-- Clean up
--
Expand Down
3 changes: 3 additions & 0 deletions src/backend/parser/cypher_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ int cypher_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, ag_scanner_t scanner)
* case sensitivity
*/
lvalp->keyword = GetScanKeyword(kwnum, &CypherKeyword);
ident = pstrdup(token.value.s);
truncate_identifier(ident, strlen(ident), true);
lvalp->string = ident;
*llocp = token.location;
return CypherKeywordTokens[kwnum];
}
Expand Down

0 comments on commit f48285f

Please sign in to comment.