adelapena commented on code in PR #3011:
URL: https://github.com/apache/cassandra/pull/3011#discussion_r1440340176


##########
src/java/org/apache/cassandra/index/sasi/plan/QueryController.java:
##########
@@ -92,11 +91,9 @@ public AbstractType<?> getKeyValidator()
 
     public ColumnIndex getIndex(RowFilter.Expression expression)
     {
-        Optional<Index> index = cfs.indexManager.getBestIndexFor(expression);
-        return index.isPresent() ? ((SASIIndex) index.get()).getIndex() : null;
+        return cfs.indexManager.getBestIndexFor(expression, 
SASIIndex.class).map(SASIIndex::getIndex).orElse(null);

Review Comment:
   Not related with the changes, but can we annotate the method as `@Nullable`?



##########
test/unit/org/apache/cassandra/index/SecondaryIndexManagerTest.java:
##########
@@ -56,6 +57,20 @@ public void after()
         TestingIndex.clear();
     }
 
+    @Test
+    public void createSasiAfterSai()
+    {
+        execute(format("CREATE TABLE %s.abc (id int PRIMARY KEY, val text)", 
KEYSPACE));
+        execute(format("CREATE INDEX ON %s.abc (val) USING 'sai'", KEYSPACE));
+        waitForTableIndexesQueryable(KEYSPACE, "abc");
+        execute(format("INSERT INTO %s.abc (id, val) VALUES (1, 'a')", 
KEYSPACE));
+        execute(format("SELECT * FROM %s.abc WHERE val = 'a'", KEYSPACE));
+        flush(KEYSPACE);
+        execute(format("CREATE CUSTOM INDEX on %s.abc (val) USING 
'org.apache.cassandra.index.sasi.SASIIndex'", KEYSPACE));
+        waitForTableIndexesQueryable(KEYSPACE, "abc");
+        execute(format("SELECT * FROM %s.abc WHERE val = 'a'", KEYSPACE));

Review Comment:
   I think this can be simplified to:
   ```suggestion
           createTable("CREATE TABLE %s (id int PRIMARY KEY, val text)");
           createIndex("CREATE INDEX ON %s (val) USING 'sai'");
           execute("INSERT INTO %s (id, val) VALUES (1, 'a')");
           execute("SELECT * FROM %s WHERE val = 'a'");
           flush();
           createIndex("CREATE INDEX ON %s (val) USING 
'org.apache.cassandra.index.sasi.SASIIndex'");
           execute("SELECT * FROM %s WHERE val = 'a'");
   ```



##########
src/java/org/apache/cassandra/index/sai/plan/QueryController.java:
##########
@@ -133,8 +132,7 @@ public List<DataRange> dataRanges()
 
     public StorageAttachedIndex indexFor(RowFilter.Expression expression)
     {
-        Set<StorageAttachedIndex> indexes = 
cfs.indexManager.getBestIndexFor(expression, StorageAttachedIndex.class);
-        return indexes.isEmpty() ? null : indexes.iterator().next();
+        return cfs.indexManager.getBestIndexFor(expression, 
StorageAttachedIndex.class).orElse(null);

Review Comment:
   Not related with the changes, but can we annotate the method as `@Nullable`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to