You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by gi...@apache.org on 2024/02/15 16:45:40 UTC
(druid) branch master updated: fix return type inference of parse_long, which can also be null if string is not parseable into a long (#15909)
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 fe2ba8cc280 fix return type inference of parse_long, which can also be null if string is not parseable into a long (#15909)
fe2ba8cc280 is described below
commit fe2ba8cc280b012ba1695905f5d5b2d2ce3c7af1
Author: Clint Wylie <cw...@apache.org>
AuthorDate: Thu Feb 15 08:45:34 2024 -0800
fix return type inference of parse_long, which can also be null if string is not parseable into a long (#15909)
* fix return type inference of parse_long, which can also be null if string is not parseable into a long
* fix msq test
---
.../druid/msq/test/CalciteSelectQueryMSQTest.java | 15 +++++++++++++
.../builtin/ParseLongOperatorConversion.java | 2 +-
.../apache/druid/sql/calcite/CalciteQueryTest.java | 25 ++++++++++++++++++++++
3 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectQueryMSQTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectQueryMSQTest.java
index da98254e4de..503e17755cf 100644
--- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectQueryMSQTest.java
+++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectQueryMSQTest.java
@@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Module;
+import org.apache.druid.common.config.NullHandling;
import org.apache.druid.guice.DruidInjectorBuilder;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.msq.exec.WorkerMemoryParameters;
@@ -215,4 +216,18 @@ public class CalciteSelectQueryMSQTest extends CalciteQueryTest
)
.run();
}
+
+ @Override
+ public void testFilterParseLongNullable()
+ {
+ // this isn't really correct in default value mode, the result should be ImmutableList.of(new Object[]{0L})
+ // but MSQ is missing default aggregator values in empty group results. this override can be removed when this
+ // is fixed
+ testBuilder().queryContext(QUERY_CONTEXT_DEFAULT)
+ .sql("select count(*) from druid.foo where parse_long(dim1, 10) is null")
+ .expectedResults(
+ NullHandling.sqlCompatible() ? ImmutableList.of(new Object[]{4L}) : ImmutableList.of()
+ )
+ .run();
+ }
}
diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ParseLongOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ParseLongOperatorConversion.java
index 53b7b790256..762ee43496a 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ParseLongOperatorConversion.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ParseLongOperatorConversion.java
@@ -38,7 +38,7 @@ public class ParseLongOperatorConversion implements SqlOperatorConversion
private static final SqlFunction SQL_FUNCTION = OperatorConversions
.operatorBuilder(NAME)
.operandTypes(SqlTypeFamily.CHARACTER, SqlTypeFamily.INTEGER)
- .returnTypeCascadeNullable(SqlTypeName.BIGINT)
+ .returnTypeNullable(SqlTypeName.BIGINT)
.functionCategory(SqlFunctionCategory.STRING)
.requiredOperandCount(1)
.build();
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 2ce2fff0431..acc545e693e 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
@@ -15292,4 +15292,29 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
)
.run();
}
+
+ @Test
+ public void testFilterParseLongNullable()
+ {
+ testQuery(
+ "select count(*) from druid.foo where parse_long(dim1, 10) is null",
+ ImmutableList.of(
+ Druids.newTimeseriesQueryBuilder()
+ .dataSource(CalciteTests.DATASOURCE1)
+ .intervals(querySegmentSpec(Filtration.eternity()))
+ .virtualColumns(
+ expressionVirtualColumn(
+ "v0",
+ "parse_long(\"dim1\",10)",
+ ColumnType.LONG)
+ )
+ .filters(isNull("v0"))
+ .granularity(Granularities.ALL)
+ .aggregators(new CountAggregatorFactory("a0"))
+ .context(QUERY_CONTEXT_DEFAULT)
+ .build()
+ ),
+ ImmutableList.of(new Object[]{NullHandling.sqlCompatible() ? 4L : 0L})
+ );
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org