From f6612751dcb1781f0eb5ba836768dfa9fa474ab6 Mon Sep 17 00:00:00 2001 From: Niel Markwick Date: Wed, 4 Dec 2024 16:25:23 +0100 Subject: [PATCH] fix: do not capitalize reserved words for object names --- .../ASTcreate_change_stream_statement.java | 2 +- .../parser/ASTcreate_index_statement.java | 2 +- .../ASTcreate_search_index_statement.java | 2 +- .../parser/ASTcreate_table_statement.java | 2 +- src/test/resources/ddlParserValidation.txt | 22 +++++++++++++++++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_change_stream_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_change_stream_statement.java index 2cfba13..4337a66 100644 --- a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_change_stream_statement.java +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_change_stream_statement.java @@ -28,7 +28,7 @@ public ASTcreate_change_stream_statement(DdlParser p, int id) { } public String getName() { - return AstTreeUtils.getChildByType(children, ASTname.class).toString(); + return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class), false); } public ASTchange_stream_for_clause getForClause() { diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_index_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_index_statement.java index 274fb78..65513b1 100644 --- a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_index_statement.java +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_index_statement.java @@ -38,7 +38,7 @@ public ASTcreate_index_statement(DdlParser p, int id) { } public String getIndexName() { - return AstTreeUtils.getChildByType(children, ASTname.class).toString(); + return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class), false); } @Override diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_search_index_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_search_index_statement.java index da0b262..6fd7747 100644 --- a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_search_index_statement.java +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_search_index_statement.java @@ -50,7 +50,7 @@ public ASTcreate_search_index_statement(DdlParser p, int id) { } public String getName() { - return AstTreeUtils.tokensToString(getChildByType(children, ASTname.class)); + return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class), false); } private void validateChildren() { diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_table_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_table_statement.java index c2381ce..821c856 100644 --- a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_table_statement.java +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_table_statement.java @@ -44,7 +44,7 @@ public ASTcreate_table_statement(DdlParser p, int id) { } public String getTableName() { - return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class)); + return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class), false); } public Map getColumns() { diff --git a/src/test/resources/ddlParserValidation.txt b/src/test/resources/ddlParserValidation.txt index 6295ddd..a4648f7 100644 --- a/src/test/resources/ddlParserValidation.txt +++ b/src/test/resources/ddlParserValidation.txt @@ -151,4 +151,26 @@ CREATE SEARCH INDEX AlbumsIndex ON Albums ( AlbumTitle_Tokens ) OPTIONS (sort_order_sharding=TRUE) +== Test 14 create table with reserved word word name + +CREATE TABLE usage ( + intcol INT64, + structcol1 STRUCT < col1 INT64, col2 INT64 >, + structcol2 STRUCT <> +) PRIMARY KEY (intcol ASC) + +== Test 15 create index with reserved word word name + +CREATE INDEX IF NOT EXISTS usage ON usage_table ( mycol ASC ) + +== Test 16 create search index with reserved word name + +CREATE SEARCH INDEX usage +ON usage_table ( some_token ) +OPTIONS (sort_order_sharding=TRUE) + +== Test 16 change stream with reserved word name + +CREATE CHANGE STREAM usage FOR table1 + ==