Skip to content

Commit

Permalink
fix: handle cases where there are no stored columns in search indexes (
Browse files Browse the repository at this point in the history
  • Loading branch information
nielm authored Jun 19, 2024
1 parent 9b8bb81 commit caf211a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 14 deletions.
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)

==





0 comments on commit caf211a

Please sign in to comment.