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

Missing STORED columns in SEARCH INDEX causes exception #118

Closed
gurminder71 opened this issue Jun 2, 2024 · 1 comment · Fixed by #136 or #135
Closed

Missing STORED columns in SEARCH INDEX causes exception #118

gurminder71 opened this issue Jun 2, 2024 · 1 comment · Fixed by #136 or #135

Comments

@gurminder71
Copy link
Contributor

The STORED columns are optional. If those columns are missing, it causes exception because of getChildByType(original.children, ASTstored_column_list.class).getStoredColumns().

Fix is:

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 24ce51b..8bba4d7 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
@@ -205,22 +205,22 @@ public class ASTcreate_search_index_statement extends SimpleNode
     // 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.
-    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));
-    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));
+    Map<String, ASTstored_column> originalStoredColumns = new LinkedHashMap<>();
+    ASTstored_column_list originalStoredColumnList = getOptionalChildByType(original.children, ASTstored_column_list.class);
+    if (originalStoredColumnList != null) {
+      originalStoredColumns = originalStoredColumnList.getStoredColumns().stream().
+          collect(
+              Collectors.toMap(
+                  ASTstored_column::toString, Function.identity(), (x, y) -> y, LinkedHashMap::new));
+    }
+    Map<String, ASTstored_column> newStoredColumns  = new LinkedHashMap<>();;
+    ASTstored_column_list newStoredColumnList = getOptionalChildByType(other.children, ASTstored_column_list.class);
+    if (newStoredColumnList != null) {
+      newStoredColumns = newStoredColumnList.getStoredColumns().stream()
+          .collect(
+              Collectors.toMap(
+                  ASTstored_column::toString, Function.identity(), (x, y) -> y, LinkedHashMap::new));
+    }
@nielm
Copy link
Collaborator

nielm commented Jun 19, 2024

Sorry for the bug - and the delay! Fixed in 1.22.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants