Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle cases where there are no stored columns in search indexes #136

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,31 @@ private void generateAlterStatementsFor(
// Look for differences in storedColumnList
// Easiest is to use Maps.difference, but first we need some maps, and we need to preserve order
// so convert the keyParts to String, and then add to a LinkedHashMap.
ASTstored_column_list origStoredColList =
getOptionalChildByType(original.children, ASTstored_column_list.class);
Map<String, ASTstored_column> originalStoredColumns =
getChildByType(original.children, ASTstored_column_list.class).getStoredColumns().stream()
.collect(
Collectors.toMap(
ASTstored_column::toString,
Function.identity(),
(x, y) -> y,
LinkedHashMap::new));
origStoredColList == null
? Map.of()
: origStoredColList.getStoredColumns().stream()
.collect(
Collectors.toMap(
ASTstored_column::toString,
Function.identity(),
(x, y) -> y,
LinkedHashMap::new));

ASTstored_column_list newStoredColList =
getOptionalChildByType(other.children, ASTstored_column_list.class);
Map<String, ASTstored_column> newStoredColumns =
getChildByType(other.children, ASTstored_column_list.class).getStoredColumns().stream()
.collect(
Collectors.toMap(
ASTstored_column::toString,
Function.identity(),
(x, y) -> y,
LinkedHashMap::new));
newStoredColList == null
? Map.of()
: newStoredColList.getStoredColumns().stream()
.collect(
Collectors.toMap(
ASTstored_column::toString,
Function.identity(),
(x, y) -> y,
LinkedHashMap::new));
MapDifference<String, ASTstored_column> storedColDiff =
Maps.difference(originalStoredColumns, newStoredColumns);

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/ddlParserValidation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,6 @@ OPTIONS (sort_order_sharding=TRUE)

CREATE SEARCH INDEX AlbumsIndex
ON Albums ( AlbumTitle_Tokens ASC )
OPTIONS (sort_order_sharding=TRUE)

==
14 changes: 14 additions & 0 deletions src/test/resources/expectedDdlDiff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,18 @@ ALTER TABLE test1 ADD COLUMN col3 INT64
ALTER SEARCH INDEX AlbumsIndex ADD COLUMN col3 ASC
ALTER SEARCH INDEX AlbumsIndex ADD STORED COLUMN scol3

== TEST 58 Add col to search index - no stored columns

ALTER SEARCH INDEX AlbumsIndex ADD COLUMN col3 ASC

== TEST 59 Add stored col to search index

ALTER SEARCH INDEX AlbumsIndex ADD STORED COLUMN scol1

== TEST 60 Remove stored cols from search index

ALTER SEARCH INDEX AlbumsIndex DROP STORED COLUMN scol1

==


17 changes: 17 additions & 0 deletions src/test/resources/newDdl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,21 @@ CREATE SEARCH INDEX AlbumsIndex
ON Albums (col1, col3)
STORING (scol1, scol3);

== TEST 58 Add col to search index - no stored columns

CREATE SEARCH INDEX AlbumsIndex
ON Albums (col1, col2, col3)

== TEST 59 Add stored col to search index

CREATE SEARCH INDEX AlbumsIndex
ON Albums (col1, col2)
STORING (scol1);

== TEST 60 Remove stored cols from search index

CREATE SEARCH INDEX AlbumsIndex
ON Albums (col1, col2)

==

19 changes: 19 additions & 0 deletions src/test/resources/originalDdl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,25 @@ CREATE SEARCH INDEX AlbumsIndex
ON Albums (col1, col2)
STORING (scol1, scol2);

== TEST 58 Add col to search index - no stored columns

CREATE SEARCH INDEX AlbumsIndex
ON Albums (col1, col2)

== TEST 59 Add stored col to search index

CREATE SEARCH INDEX AlbumsIndex
ON Albums (col1, col2)

== TEST 60 Remove stored cols from search index

CREATE SEARCH INDEX AlbumsIndex
ON Albums (col1, col2)
STORING (scol1)

==