mirror of https://github.com/apache/druid.git
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.
This commit is contained in:
parent
bcea05e4e8
commit
69b2ea3ddc
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
@ -6695,6 +6697,22 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
|
|||
assertQueryIsUnplannable(theQuery);
|
||||
}
|
||||
|
||||
@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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue