This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new f640957eff Fix TextMatchFilterOptimizer `or not` behavior (#13533)
f640957eff is described below
commit f640957effbee767dc5d697c65d7c37d5d9648b5
Author: Christopher Peck <[email protected]>
AuthorDate: Mon Jul 8 18:20:41 2024 -0700
Fix TextMatchFilterOptimizer `or not` behavior (#13533)
---
.../core/query/optimizer/filter/TextMatchFilterOptimizer.java | 9 +++++++++
.../apache/pinot/core/query/optimizer/QueryOptimizerTest.java | 5 +++++
2 files changed, 14 insertions(+)
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/filter/TextMatchFilterOptimizer.java
b/pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/filter/TextMatchFilterOptimizer.java
index c6b2e29838..065cbc7ebe 100644
---
a/pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/filter/TextMatchFilterOptimizer.java
+++
b/pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/filter/TextMatchFilterOptimizer.java
@@ -138,6 +138,15 @@ public class TextMatchFilterOptimizer implements
FilterOptimizer {
for (Expression expression : entry.getValue()) {
if
(expression.getFunctionCall().getOperator().equals(FilterKind.NOT.name())) {
Expression operand =
expression.getFunctionCall().getOperands().get(0);
+
+ // Lucene special case: if `OR NOT`, skip optimizing as NOT cannot
be used with just one term
+ if (operator.equals(FilterKind.OR.name())) {
+ Expression textMatchExpression =
RequestUtils.getFunctionExpression(FilterKind.TEXT_MATCH.name(),
+ operand.getFunctionCall().getOperands().get(0),
operand.getFunctionCall().getOperands().get(1));
+
newChildren.add(RequestUtils.getFunctionExpression(FilterKind.NOT.name(),
textMatchExpression));
+ continue;
+ }
+
literals.add(FilterKind.NOT.name() + SPACE +
operand.getFunctionCall().getOperands().get(1).getLiteral()
.getStringValue());
continue;
diff --git
a/pinot-core/src/test/java/org/apache/pinot/core/query/optimizer/QueryOptimizerTest.java
b/pinot-core/src/test/java/org/apache/pinot/core/query/optimizer/QueryOptimizerTest.java
index 25a8109237..ed01138f24 100644
---
a/pinot-core/src/test/java/org/apache/pinot/core/query/optimizer/QueryOptimizerTest.java
+++
b/pinot-core/src/test/java/org/apache/pinot/core/query/optimizer/QueryOptimizerTest.java
@@ -293,6 +293,11 @@ public class QueryOptimizerTest {
+ "AND TEXT_MATCH(string2, 'foo2') AND TEXT_MATCH(string2,
'bar2')",
"SELECT * FROM testTable WHERE TEXT_MATCH(string1, '(foo1 AND bar1)')
AND TEXT_MATCH(string2, '(foo2 AND "
+ "bar2)')");
+ testQuery("SELECT * FROM testTable WHERE TEXT_MATCH(string, 'foo') OR NOT
TEXT_MATCH(string, 'bar')",
+ "SELECT * FROM testTable WHERE NOT TEXT_MATCH(string, 'bar') OR
TEXT_MATCH(string, 'foo')");
+ testQuery(
+ "select * from testTable where intCol > 1 AND (text_match(string,
'foo') OR NOT text_match(string, 'bar'))",
+ "select * from testTable where intCol > 1 AND (NOT text_match(string,
'bar') OR text_match(string, 'foo'))");
testCannotOptimizeQuery("SELECT * FROM testTable WHERE TEXT_MATCH(string1,
'foo') OR TEXT_MATCH(string2, 'bar')");
testCannotOptimizeQuery(
"SELECT * FROM testTable WHERE int = 1 AND TEXT_MATCH(string, 'foo')
OR TEXT_MATCH(string, 'bar')");
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]