You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by fj...@apache.org on 2019/05/21 18:32:42 UTC
[incubator-druid] branch master updated: SQL: TIME_EXTRACT should
have 2 required operands. (#7710)
This is an automated email from the ASF dual-hosted git repository.
fjy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git
The following commit(s) were added to refs/heads/master by this push:
new 69b2ea3 SQL: TIME_EXTRACT should have 2 required operands. (#7710)
69b2ea3 is described below
commit 69b2ea3ddc0fd6831f5ca4cfa2a5fcde4ebfc3cc
Author: Gian Merlino <gi...@imply.io>
AuthorDate: Tue May 21 11:32:36 2019 -0700
SQL: TIME_EXTRACT should have 2 required operands. (#7710)
* SQL: TIME_EXTRACT should have 2 required operands.
Timestamp and time unit are both required.
* Add regression test.
---
.../builtin/TimeExtractOperatorConversion.java | 2 +-
.../org/apache/druid/sql/calcite/CalciteQueryTest.java | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeExtractOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeExtractOperatorConversion.java
index 28464fa..5f1c77d 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeExtractOperatorConversion.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeExtractOperatorConversion.java
@@ -43,7 +43,7 @@ public class TimeExtractOperatorConversion implements SqlOperatorConversion
private static final SqlFunction SQL_FUNCTION = OperatorConversions
.operatorBuilder("TIME_EXTRACT")
.operandTypes(SqlTypeFamily.TIMESTAMP, SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)
- .requiredOperands(1)
+ .requiredOperands(2)
.returnType(SqlTypeName.BIGINT)
.functionCategory(SqlFunctionCategory.TIMEDATE)
.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 ecef1b5..e67cde8 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
@@ -21,6 +21,8 @@ package org.apache.druid.sql.calcite;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
+import org.apache.calcite.runtime.CalciteContextException;
+import org.apache.calcite.tools.ValidationException;
import org.apache.druid.common.config.NullHandling;
import org.apache.druid.java.util.common.DateTimes;
import org.apache.druid.java.util.common.Intervals;
@@ -6696,6 +6698,22 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
}
@Test
+ public void testTimeExtractWithTooFewArguments() throws Exception
+ {
+ // Regression test for https://github.com/apache/incubator-druid/pull/7710.
+ expectedException.expect(ValidationException.class);
+ expectedException.expectCause(CoreMatchers.instanceOf(CalciteContextException.class));
+ expectedException.expectCause(
+ ThrowableMessageMatcher.hasMessage(
+ CoreMatchers.containsString(
+ "Invalid number of arguments to function 'TIME_EXTRACT'. Was expecting 2 arguments"
+ )
+ )
+ );
+ testQuery("SELECT TIME_EXTRACT(__time) FROM druid.foo", ImmutableList.of(), ImmutableList.of());
+ }
+
+ @Test
public void testUsingSubqueryAsFilterForbiddenByConfig()
{
assertQueryIsUnplannable(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org