use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project druid by druid-io.
the class ExpressionsTest method testRoundWithInvalidArgument.
@Test
public void testRoundWithInvalidArgument() {
final SqlFunction roundFunction = new RoundOperatorConversion().calciteOperator();
if (!NullHandling.sqlCompatible()) {
expectException(IAE.class, "The first argument to the function[round] should be integer or double type but got the type: STRING");
}
testHelper.testExpression(roundFunction, testHelper.makeInputRef("s"), DruidExpression.ofExpression(ColumnType.STRING, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.STRING, "s"))), NullHandling.sqlCompatible() ? null : "IAE Exception");
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project druid by druid-io.
the class ExpressionsTest method testRound.
@Test
public void testRound() {
final SqlFunction roundFunction = new RoundOperatorConversion().calciteOperator();
testHelper.testExpression(roundFunction, testHelper.makeInputRef("a"), DruidExpression.ofExpression(ColumnType.LONG, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.LONG, "a"))), 10L);
testHelper.testExpression(roundFunction, testHelper.makeInputRef("b"), DruidExpression.ofExpression(ColumnType.LONG, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.LONG, "b"))), 25L);
testHelper.testExpressionString(roundFunction, ImmutableList.of(testHelper.makeInputRef("b"), testHelper.makeLiteral(-1)), DruidExpression.ofExpression(ColumnType.LONG, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.LONG, "b"), DruidExpression.ofLiteral(ColumnType.LONG, DruidExpression.numberLiteral(-1)))), 30L);
testHelper.testExpression(roundFunction, testHelper.makeInputRef("x"), DruidExpression.ofExpression(ColumnType.FLOAT, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "x"))), 2.0);
testHelper.testExpressionString(roundFunction, ImmutableList.of(testHelper.makeInputRef("x"), testHelper.makeLiteral(1)), DruidExpression.ofExpression(ColumnType.FLOAT, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "x"), DruidExpression.ofLiteral(ColumnType.LONG, DruidExpression.numberLiteral(1)))), 2.3);
testHelper.testExpression(roundFunction, testHelper.makeInputRef("y"), DruidExpression.ofExpression(ColumnType.LONG, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.LONG, "y"))), 3.0);
testHelper.testExpression(roundFunction, testHelper.makeInputRef("z"), DruidExpression.ofExpression(ColumnType.FLOAT, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "z"))), -2.0);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project flink by apache.
the class SqlValidatorImpl method handleUnresolvedFunction.
public CalciteException handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, List<RelDataType> argTypes, List<String> argNames) {
// For builtins, we can give a better error message
final List<SqlOperator> overloads = new ArrayList<>();
opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null, SqlSyntax.FUNCTION, overloads, catalogReader.nameMatcher());
if (overloads.size() == 1) {
SqlFunction fun = (SqlFunction) overloads.get(0);
if ((fun.getSqlIdentifier() == null) && (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) {
final int expectedArgCount = fun.getOperandCountRange().getMin();
throw newValidationError(call, RESOURCE.invalidArgCount(call.getOperator().getName(), expectedArgCount));
}
}
AssignableOperandTypeChecker typeChecking = new AssignableOperandTypeChecker(argTypes, argNames);
String signature = typeChecking.getAllowedSignatures(unresolvedFunction, unresolvedFunction.getName());
throw newValidationError(call, RESOURCE.validatorUnknownFunction(signature));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project flink by apache.
the class FunctionCatalogOperatorTable method convertToBridgingSqlFunction.
private Optional<SqlFunction> convertToBridgingSqlFunction(@Nullable SqlFunctionCategory category, ContextResolvedFunction resolvedFunction) {
final FunctionDefinition definition = resolvedFunction.getDefinition();
if (!verifyFunctionKind(category, resolvedFunction)) {
return Optional.empty();
}
final TypeInference typeInference;
try {
typeInference = definition.getTypeInference(dataTypeFactory);
} catch (Throwable t) {
throw new ValidationException(String.format("An error occurred in the type inference logic of function '%s'.", resolvedFunction), t);
}
if (typeInference.getOutputTypeStrategy() == TypeStrategies.MISSING) {
return Optional.empty();
}
final SqlFunction function;
if (definition.getKind() == FunctionKind.AGGREGATE || definition.getKind() == FunctionKind.TABLE_AGGREGATE) {
function = BridgingSqlAggFunction.of(dataTypeFactory, typeFactory, SqlKind.OTHER_FUNCTION, resolvedFunction, typeInference);
} else {
function = BridgingSqlFunction.of(dataTypeFactory, typeFactory, SqlKind.OTHER_FUNCTION, resolvedFunction, typeInference);
}
return Optional.of(function);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project flink by apache.
the class SqlValidatorImpl method deriveConstructorType.
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, SqlFunction resolvedConstructor, List<RelDataType> argTypes) {
SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier();
assert sqlIdentifier != null;
RelDataType type = catalogReader.getNamedType(sqlIdentifier);
if (type == null) {
// TODO jvs 12-Feb-2005: proper type name formatting
throw newValidationError(sqlIdentifier, RESOURCE.unknownDatatypeName(sqlIdentifier.toString()));
}
if (resolvedConstructor == null) {
if (call.operandCount() > 0) {
// no user-defined constructor could be found
throw handleUnresolvedFunction(call, unresolvedConstructor, argTypes, null);
}
} else {
SqlCall testCall = resolvedConstructor.createCall(call.getParserPosition(), call.getOperandList());
RelDataType returnType = resolvedConstructor.validateOperands(this, scope, testCall);
assert type == returnType;
}
if (config.identifierExpansion()) {
if (resolvedConstructor != null) {
((SqlBasicCall) call).setOperator(resolvedConstructor);
} else {
// fake a fully-qualified call to the default constructor
((SqlBasicCall) call).setOperator(new SqlFunction(type.getSqlIdentifier(), ReturnTypes.explicit(type), null, null, null, SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR));
}
}
return type;
}
Aggregations