You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "pranavshenoy (via GitHub)" <gi...@apache.org> on 2025/08/02 06:55:55 UTC

[PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

pranavshenoy opened a new pull request, #4290:
URL: https://github.com/apache/cassandra/pull/4290

   [CASSANDRA-17198](https://issues.apache.org/jira/browse/CASSANDRA-17198) Support for LIKE expression as PostFilter in SAI
   
   Since LIKE is filtered in post filter, ALLOW FILTERING is required. I tested it with some basic queries. Will do further manual testing + unit tests. It would be helpful for early reviews. 
   
   
   patch by Pranav Shenoy; reviewed by Caleb Rackliffe for CASSANDRA-17198
   
   
   


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2264367979


##########
src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java:
##########
@@ -206,11 +206,20 @@ public StatementRestrictions(ClientState state,
             else if (operator.requiresIndexing())
             {
                 Restriction restriction = relation.toRestriction(table, boundNames);
-
-                if (!type.allowUseOfSecondaryIndices() || !restriction.hasSupportingIndex(indexRegistry))
+                
+                if (!type.allowUseOfSecondaryIndices())
                     throw invalidRequest("%s restriction is only supported on properly " +
                                                         "indexed columns. %s is not valid.", operator, relation);
 
+                if (operator != Operator.LIKE)
+                {
+                    // LIKE can be used as post index query filter, but not as index restriction
+                    if (!restriction.hasSupportingIndex(indexRegistry))
+                        throw invalidRequest("%s restriction is only supported on properly " +
+                                                        "indexed columns. %s is not valid.", operator, relation);
+                }

Review Comment:
   I'm guessing this has been changed already in your not-yet-pushed work, but once LIKE doesn't return `true` from `requiresIndexing()`, seems like this change should no longer be necessary.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2334895850


##########
test/unit/org/apache/cassandra/index/sai/cql/UnindexedExpressionsTest.java:
##########
@@ -63,7 +63,7 @@ public void unsupportedOperatorsAreHandledTest() throws Throwable
         execute("INSERT INTO %s (pk, val1, val2) VALUES (4, 4, '44')");
 
         // The LIKE operator is rejected because it needs to be handled by an index
-        assertInvalidMessage("LIKE restriction is only supported on properly indexed columns",
+        assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",

Review Comment:
   nit: Can we just use `StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE` here?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2334968282


##########
src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java:
##########
@@ -345,11 +352,14 @@ public void addToRowFilter(RowFilter filter, IndexRegistry indexRegistry, QueryO
                 else if (operator == Operator.LIKE)
                 {
                     LikePattern pattern = LikePattern.parse(buffers.get(0));
-                    // there must be a suitable INDEX for LIKE_XXX expressions
+                    
                     RowFilter.SimpleExpression expression = filter.add(column, pattern.kind().operator(), pattern.value());
-                    indexRegistry.getBestIndexFor(expression, indexHints)
-                                 .orElseThrow(() -> invalidRequest("%s is only supported on properly indexed columns",
-                                                                   expression));
+                    Optional<Index> index = indexRegistry.getBestIndexFor(expression, indexHints);
+                    if(!index.isPresent() && !allowFiltering)
+                    {
+                        throw invalidRequest("%s is only supported on properly indexed columns or with ALLOW FILTERING",
+                                            expression);
+                    }

Review Comment:
   nit: I might just go single-line `if` here. It probably won't ever be multi-line...
   
   ```
   if (!index.isPresent() && !allowFiltering)
       throw invalidRequest("%s is only supported on properly indexed columns or with ALLOW FILTERING", expression);
   ```



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-17198 Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz closed pull request #4290: CASSANDRA-17198 Support for LIKE  expressions as PostFilter in SAI
URL: https://github.com/apache/cassandra/pull/4290


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2264374243


##########
src/java/org/apache/cassandra/utils/ByteBufferUtil.java:
##########
@@ -955,6 +955,18 @@ public static boolean contains(ByteBuffer buffer, ByteBuffer subBuffer)
         }
         return false;
     }
+    /**
+     * Check is the given buffer matches with the second buffer
+     *
+     * @param buffer1 The first buffer
+     * @param buffer2 The second buffer.
+     *
+     * @return true if both the buffers are equal, false otherwise.
+     */
+    public static boolean matches(ByteBuffer buffer1, ByteBuffer buffer2)
+    {
+        return buffer1.equals(buffer2);
+    }

Review Comment:
   nit: I'd probably just inline this in `Expression` rather than having a one-line utility method.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2334911661


##########
test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java:
##########
@@ -843,16 +844,16 @@ public void prepareStatementsWithLIKEClauses() throws Throwable
 
         // LIKE is not supported on indexes of non-literal values
         // this is rejected before binding, so the value isn't available in the error message
-        assertInvalidMessage("LIKE restriction is only supported on properly indexed columns. v3 LIKE ? is not valid",
+        assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",

Review Comment:
   nit: Can we use `StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE`?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "pranavshenoy (via GitHub)" <gi...@apache.org>.
pranavshenoy commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2337148330


##########
test/unit/org/apache/cassandra/cql3/restrictions/ClusteringColumnRestrictionsTest.java:
##########
@@ -1669,7 +1669,7 @@ private static Restriction newMultiEq(TableMetadata tableMetadata, int firstInde
         TupleType tupleType = new TupleType(types);
         return new SimpleRestriction(ColumnsExpression.multiColumns(columns, tableMetadata),
                                      Operator.EQ,
-                                     Terms.of(new MultiElements.Value(tupleType, asList(values))));
+                                     Terms.of(new MultiElements.Value(tupleType, asList(values))), false);

Review Comment:
   done



##########
test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java:
##########
@@ -843,16 +844,16 @@ public void prepareStatementsWithLIKEClauses() throws Throwable
 
         // LIKE is not supported on indexes of non-literal values
         // this is rejected before binding, so the value isn't available in the error message
-        assertInvalidMessage("LIKE restriction is only supported on properly indexed columns. v3 LIKE ? is not valid",
+        assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",

Review Comment:
   done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "pranavshenoy (via GitHub)" <gi...@apache.org>.
pranavshenoy commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2337150404


##########
src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java:
##########
@@ -345,11 +352,14 @@ public void addToRowFilter(RowFilter filter, IndexRegistry indexRegistry, QueryO
                 else if (operator == Operator.LIKE)
                 {
                     LikePattern pattern = LikePattern.parse(buffers.get(0));
-                    // there must be a suitable INDEX for LIKE_XXX expressions
+                    
                     RowFilter.SimpleExpression expression = filter.add(column, pattern.kind().operator(), pattern.value());
-                    indexRegistry.getBestIndexFor(expression, indexHints)
-                                 .orElseThrow(() -> invalidRequest("%s is only supported on properly indexed columns",
-                                                                   expression));
+                    Optional<Index> index = indexRegistry.getBestIndexFor(expression, indexHints);
+                    if(!index.isPresent() && !allowFiltering)
+                    {
+                        throw invalidRequest("%s is only supported on properly indexed columns or with ALLOW FILTERING",
+                                            expression);
+                    }

Review Comment:
   done



##########
src/java/org/apache/cassandra/cql3/Ordering.java:
##########
@@ -105,7 +105,7 @@ public SingleRestriction toRestriction()
         {
             return new SimpleRestriction(ColumnsExpression.singleColumn(columnMetadata, tableMetadata),
                                          Operator.ANN,
-                                         Terms.of(vectorValue));
+                                         Terms.of(vectorValue), false);

Review Comment:
   done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "pranavshenoy (via GitHub)" <gi...@apache.org>.
pranavshenoy commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2280673394


##########
src/java/org/apache/cassandra/utils/ByteBufferUtil.java:
##########
@@ -955,6 +955,18 @@ public static boolean contains(ByteBuffer buffer, ByteBuffer subBuffer)
         }
         return false;
     }
+    /**
+     * Check is the given buffer matches with the second buffer
+     *
+     * @param buffer1 The first buffer
+     * @param buffer2 The second buffer.
+     *
+     * @return true if both the buffers are equal, false otherwise.
+     */
+    public static boolean matches(ByteBuffer buffer1, ByteBuffer buffer2)
+    {
+        return buffer1.equals(buffer2);
+    }

Review Comment:
   done. Thanks



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2334906276


##########
test/unit/org/apache/cassandra/index/sai/cql/AllowFilteringTest.java:
##########
@@ -433,4 +433,83 @@ public void testAllowFilteringDuringIndexBuild() throws Throwable
         execute("SELECT * FROM %s WHERE v=0");
         execute("SELECT * FROM %s WHERE v=0 ALLOW FILTERING");
     }
+
+    @Test
+    public void testAllowFilteringWithLikePrefixPostFiltering()
+    {
+        createTable("CREATE TABLE %S (k1 int, k2 text, k3 int, PRIMARY KEY (k1))");
+        createIndex("CREATE INDEX ON %s(k3) USING 'sai'");
+        
+        execute("insert into %s (k1, k2, k3) values (1, 'fo', 1)");
+        execute("insert into %s (k1, k2, k3) values (2, 'foo', 2)");
+        execute("insert into %s (k1, k2, k3) values (3, 'fo', 3)");
+        execute("insert into %s (k1, k2, k3) values (4, 'ba', 4)");
+        execute("insert into %s (k1, k2, k3) values (5, 'bar', 5)");
+
+        assertRowCount(execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'f%%' ALLOW FILTERING"), 3);
+        assertRowCount(execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'ca%%' ALLOW FILTERING"), 0);
+        assertThatThrownBy(() -> execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'f%%'"))
+                .hasMessageContaining("use ALLOW FILTERING")

Review Comment:
   nit: Can we use `StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE`?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2334908480


##########
test/unit/org/apache/cassandra/index/sai/cql/AllowFilteringTest.java:
##########
@@ -433,4 +433,83 @@ public void testAllowFilteringDuringIndexBuild() throws Throwable
         execute("SELECT * FROM %s WHERE v=0");
         execute("SELECT * FROM %s WHERE v=0 ALLOW FILTERING");
     }
+
+    @Test
+    public void testAllowFilteringWithLikePrefixPostFiltering()
+    {
+        createTable("CREATE TABLE %S (k1 int, k2 text, k3 int, PRIMARY KEY (k1))");
+        createIndex("CREATE INDEX ON %s(k3) USING 'sai'");
+        
+        execute("insert into %s (k1, k2, k3) values (1, 'fo', 1)");
+        execute("insert into %s (k1, k2, k3) values (2, 'foo', 2)");
+        execute("insert into %s (k1, k2, k3) values (3, 'fo', 3)");
+        execute("insert into %s (k1, k2, k3) values (4, 'ba', 4)");
+        execute("insert into %s (k1, k2, k3) values (5, 'bar', 5)");
+
+        assertRowCount(execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'f%%' ALLOW FILTERING"), 3);
+        assertRowCount(execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'ca%%' ALLOW FILTERING"), 0);
+        assertThatThrownBy(() -> execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'f%%'"))
+                .hasMessageContaining("use ALLOW FILTERING")

Review Comment:
   ...and in the tests below, etc.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2264386147


##########
src/java/org/apache/cassandra/index/sai/plan/Expression.java:
##########
@@ -268,6 +287,10 @@ public boolean isSatisfiedBy(ByteBuffer columnValue)
 
         if (lower != null)
         {
+            // Post-filtering for LIKE operators must be consistent with implementation of LIKE operators in non-SAI Allow Filtering path
+            if(operator.isLikeVariant())
+                return termMatches(value.raw, lower.value.raw);

Review Comment:
   I think we still may need to account for things like case-insensitive search eventually, so we should be able to just fall through to `validateStringValue()`, which would just call `termMatches()` anyway?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "pranavshenoy (via GitHub)" <gi...@apache.org>.
pranavshenoy commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2280673512


##########
src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java:
##########
@@ -206,11 +206,20 @@ public StatementRestrictions(ClientState state,
             else if (operator.requiresIndexing())
             {
                 Restriction restriction = relation.toRestriction(table, boundNames);
-
-                if (!type.allowUseOfSecondaryIndices() || !restriction.hasSupportingIndex(indexRegistry))
+                
+                if (!type.allowUseOfSecondaryIndices())
                     throw invalidRequest("%s restriction is only supported on properly " +
                                                         "indexed columns. %s is not valid.", operator, relation);
 
+                if (operator != Operator.LIKE)
+                {
+                    // LIKE can be used as post index query filter, but not as index restriction
+                    if (!restriction.hasSupportingIndex(indexRegistry))
+                        throw invalidRequest("%s restriction is only supported on properly " +
+                                                        "indexed columns. %s is not valid.", operator, relation);
+                }

Review Comment:
   yeah. Have reverted this. Thanks



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2334939064


##########
test/unit/org/apache/cassandra/cql3/restrictions/ClusteringColumnRestrictionsTest.java:
##########
@@ -1669,7 +1669,7 @@ private static Restriction newMultiEq(TableMetadata tableMetadata, int firstInde
         TupleType tupleType = new TupleType(types);
         return new SimpleRestriction(ColumnsExpression.multiColumns(columns, tableMetadata),
                                      Operator.EQ,
-                                     Terms.of(new MultiElements.Value(tupleType, asList(values))));
+                                     Terms.of(new MultiElements.Value(tupleType, asList(values))), false);

Review Comment:
   nit/formatting: I'd move these `false` arguments to the next line so they're on the same level of indentation as the other arguments.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2334971263


##########
src/java/org/apache/cassandra/cql3/Ordering.java:
##########
@@ -105,7 +105,7 @@ public SingleRestriction toRestriction()
         {
             return new SimpleRestriction(ColumnsExpression.singleColumn(columnMetadata, tableMetadata),
                                          Operator.ANN,
-                                         Terms.of(vectorValue));
+                                         Terms.of(vectorValue), false);

Review Comment:
   nit/formatting: I'd bump `false` to the next line so the arguments are all at the same indentation level.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-17198 Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#issuecomment-3281777923

   Committed as https://github.com/apache/cassandra/commit/cf806cac1aca7b56fe715bbd2641cda65beef91e


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "pranavshenoy (via GitHub)" <gi...@apache.org>.
pranavshenoy commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2337140085


##########
test/unit/org/apache/cassandra/index/sai/cql/AllowFilteringTest.java:
##########
@@ -433,4 +433,83 @@ public void testAllowFilteringDuringIndexBuild() throws Throwable
         execute("SELECT * FROM %s WHERE v=0");
         execute("SELECT * FROM %s WHERE v=0 ALLOW FILTERING");
     }
+
+    @Test
+    public void testAllowFilteringWithLikePrefixPostFiltering()
+    {
+        createTable("CREATE TABLE %S (k1 int, k2 text, k3 int, PRIMARY KEY (k1))");
+        createIndex("CREATE INDEX ON %s(k3) USING 'sai'");
+        
+        execute("insert into %s (k1, k2, k3) values (1, 'fo', 1)");
+        execute("insert into %s (k1, k2, k3) values (2, 'foo', 2)");
+        execute("insert into %s (k1, k2, k3) values (3, 'fo', 3)");
+        execute("insert into %s (k1, k2, k3) values (4, 'ba', 4)");
+        execute("insert into %s (k1, k2, k3) values (5, 'bar', 5)");
+
+        assertRowCount(execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'f%%' ALLOW FILTERING"), 3);
+        assertRowCount(execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'ca%%' ALLOW FILTERING"), 0);
+        assertThatThrownBy(() -> execute("SELECT * FROM %s WHERE k3 > 0 AND k2 LIKE 'f%%'"))
+                .hasMessageContaining("use ALLOW FILTERING")

Review Comment:
   done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Support for LIKE expressions as PostFilter in SAI [cassandra]

Posted by "pranavshenoy (via GitHub)" <gi...@apache.org>.
pranavshenoy commented on code in PR #4290:
URL: https://github.com/apache/cassandra/pull/4290#discussion_r2337139479


##########
test/unit/org/apache/cassandra/index/sai/cql/UnindexedExpressionsTest.java:
##########
@@ -63,7 +63,7 @@ public void unsupportedOperatorsAreHandledTest() throws Throwable
         execute("INSERT INTO %s (pk, val1, val2) VALUES (4, 4, '44')");
 
         // The LIKE operator is rejected because it needs to be handled by an index
-        assertInvalidMessage("LIKE restriction is only supported on properly indexed columns",
+        assertInvalidMessage("Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING",

Review Comment:
   done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org