Skip to content

Commit

Permalink
fix: do not capitalize reserved words for object names (#191)
Browse files Browse the repository at this point in the history
Tables which were named using reserved words were having their names normalized - ie capitalized.

Fix and add tests.
  • Loading branch information
nielm authored Dec 4, 2024
1 parent 3ee6d2d commit da7da8e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ASTcolumn_def> getColumns() {
Expand Down
22 changes: 22 additions & 0 deletions src/test/resources/ddlParserValidation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

==

0 comments on commit da7da8e

Please sign in to comment.