Skip to content

Commit da7da8e

Browse files
authored
fix: do not capitalize reserved words for object names (#191)
Tables which were named using reserved words were having their names normalized - ie capitalized. Fix and add tests.
1 parent 3ee6d2d commit da7da8e

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_change_stream_statement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ASTcreate_change_stream_statement(DdlParser p, int id) {
2828
}
2929

3030
public String getName() {
31-
return AstTreeUtils.getChildByType(children, ASTname.class).toString();
31+
return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class), false);
3232
}
3333

3434
public ASTchange_stream_for_clause getForClause() {

src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_index_statement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ASTcreate_index_statement(DdlParser p, int id) {
3838
}
3939

4040
public String getIndexName() {
41-
return AstTreeUtils.getChildByType(children, ASTname.class).toString();
41+
return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class), false);
4242
}
4343

4444
@Override

src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_search_index_statement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public ASTcreate_search_index_statement(DdlParser p, int id) {
5050
}
5151

5252
public String getName() {
53-
return AstTreeUtils.tokensToString(getChildByType(children, ASTname.class));
53+
return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class), false);
5454
}
5555

5656
private void validateChildren() {

src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_table_statement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ASTcreate_table_statement(DdlParser p, int id) {
4444
}
4545

4646
public String getTableName() {
47-
return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class));
47+
return AstTreeUtils.tokensToString(AstTreeUtils.getChildByType(children, ASTname.class), false);
4848
}
4949

5050
public Map<String, ASTcolumn_def> getColumns() {

src/test/resources/ddlParserValidation.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,26 @@ CREATE SEARCH INDEX AlbumsIndex
151151
ON Albums ( AlbumTitle_Tokens )
152152
OPTIONS (sort_order_sharding=TRUE)
153153

154+
== Test 14 create table with reserved word word name
155+
156+
CREATE TABLE usage (
157+
intcol INT64,
158+
structcol1 STRUCT < col1 INT64, col2 INT64 >,
159+
structcol2 STRUCT <>
160+
) PRIMARY KEY (intcol ASC)
161+
162+
== Test 15 create index with reserved word word name
163+
164+
CREATE INDEX IF NOT EXISTS usage ON usage_table ( mycol ASC )
165+
166+
== Test 16 create search index with reserved word name
167+
168+
CREATE SEARCH INDEX usage
169+
ON usage_table ( some_token )
170+
OPTIONS (sort_order_sharding=TRUE)
171+
172+
== Test 16 change stream with reserved word name
173+
174+
CREATE CHANGE STREAM usage FOR table1
175+
154176
==

0 commit comments

Comments
 (0)