This is an automated email from the ASF dual-hosted git repository.
gian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 2592077 Fix is null selector returning incorrect value for Long data
type (#11170)
2592077 is described below
commit 259207753dc0866430981c3b64274feaa3c804b6
Author: Maria Sitkovets <[email protected]>
AuthorDate: Wed May 19 23:47:02 2021 -0400
Fix is null selector returning incorrect value for Long data type (#11170)
* Fix is null selector returning incorrect value for Long data type
* Fix style errors
* Refactor getObject method to also cache null column values
* Make lastInput variable nullable
* Refactor unit test
* Use new boolean lastInputIsNull instead of Long for lastInput to avoid
boxing
* Refactor to remove Long for input variable
* Make a separate null caching variable
* Cleaner null caching implementation
---
...gInputCachingExpressionColumnValueSelector.java | 11 ++++++-
.../apache/druid/sql/calcite/CalciteQueryTest.java | 36 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git
a/processing/src/main/java/org/apache/druid/segment/virtual/SingleLongInputCachingExpressionColumnValueSelector.java
b/processing/src/main/java/org/apache/druid/segment/virtual/SingleLongInputCachingExpressionColumnValueSelector.java
index 76bbb62..a388b8a 100644
---
a/processing/src/main/java/org/apache/druid/segment/virtual/SingleLongInputCachingExpressionColumnValueSelector.java
+++
b/processing/src/main/java/org/apache/druid/segment/virtual/SingleLongInputCachingExpressionColumnValueSelector.java
@@ -26,6 +26,7 @@ import org.apache.druid.math.expr.Expr;
import org.apache.druid.math.expr.ExprEval;
import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import org.apache.druid.segment.ColumnValueSelector;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -52,6 +53,10 @@ public class
SingleLongInputCachingExpressionColumnValueSelector implements Colu
@Nullable
private ExprEval lastOutput;
+ // Computed output value for null.
+ @MonotonicNonNull
+ private ExprEval nullOutput;
+
public SingleLongInputCachingExpressionColumnValueSelector(
final ColumnValueSelector selector,
final Expr expression,
@@ -99,7 +104,11 @@ public class
SingleLongInputCachingExpressionColumnValueSelector implements Colu
{
// things can still call this even when underlying selector is null (e.g.
ExpressionColumnValueSelector#isNull)
if (selector.isNull()) {
- return ExprEval.ofLong(null);
+ if (nullOutput == null) {
+ bindings.set(null);
+ nullOutput = expression.eval(bindings);
+ }
+ return nullOutput;
}
// No assert for null handling, as the delegate selector already has it.
final long input = selector.getLong();
diff --git
a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
index b06967a..48eb303 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
@@ -4948,6 +4948,42 @@ public class CalciteQueryTest extends
BaseCalciteQueryTest
}
@Test
+ public void testLongPredicateIsNull() throws Exception
+ {
+ testQuery(
+ "SELECT l1 is null FROM druid.numfoo",
+ ImmutableList.of(
+ newScanQueryBuilder()
+ .dataSource(CalciteTests.DATASOURCE3)
+ .intervals(querySegmentSpec(Filtration.eternity()))
+ .columns("v0")
+ .virtualColumns(
+ expressionVirtualColumn("v0", NullHandling.replaceWithDefault() ?
"0" : "isnull(\"l1\")", ValueType.LONG)
+ )
+ .context(QUERY_CONTEXT_DEFAULT)
+ .build()
+ ),
+ NullHandling.replaceWithDefault() ?
+ ImmutableList.of(
+ new Object[]{false},
+ new Object[]{false},
+ new Object[]{false},
+ new Object[]{false},
+ new Object[]{false},
+ new Object[]{false}
+ ) :
+ ImmutableList.of(
+ new Object[]{false},
+ new Object[]{false},
+ new Object[]{false},
+ new Object[]{true},
+ new Object[]{true},
+ new Object[]{true}
+ )
+ );
+ }
+
+ @Test
public void testLongPredicateFilterNulls() throws Exception
{
testQuery(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]