use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project beam by apache.
the class BeamZetaSqlCatalogTest method rejectsScalarFunctionImplWithUnsupportedReturnType.
@Test
public void rejectsScalarFunctionImplWithUnsupportedReturnType() throws NoSuchMethodException {
JdbcConnection jdbcConnection = createJdbcConnection();
SchemaPlus calciteSchema = jdbcConnection.getCurrentSchemaPlus();
Method method = ReturnsArrayTimeFn.class.getMethod("eval");
calciteSchema.add("return_array", ScalarFunctionImpl.create(method));
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Calcite type TIME not allowed in function return_array");
BeamZetaSqlCatalog.create(calciteSchema, jdbcConnection.getTypeFactory(), SqlAnalyzer.baseAnalyzerOptions());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project beam by apache.
the class SqlNullIfOperatorRewriter method apply.
@Override
public RexNode apply(RexBuilder rexBuilder, List<RexNode> operands) {
Preconditions.checkArgument(operands.size() == 2, "NULLIF should have two arguments in function call.");
SqlOperator op = SqlOperatorMappingTable.ZETASQL_FUNCTION_TO_CALCITE_SQL_OPERATOR.get("$case_no_value").apply(null);
List<RexNode> newOperands = ImmutableList.of(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, ImmutableList.of(operands.get(0), operands.get(1))), rexBuilder.makeNullLiteral(operands.get(1).getType()), operands.get(0));
return rexBuilder.makeCall(op, newOperands);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project beam by apache.
the class SqlIfNullOperatorRewriter method apply.
@Override
public RexNode apply(RexBuilder rexBuilder, List<RexNode> operands) {
Preconditions.checkArgument(operands.size() == 2, "IFNULL should have two arguments in function call.");
SqlOperator op = SqlStdOperatorTable.CASE;
List<RexNode> newOperands = ImmutableList.of(rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, ImmutableList.of(operands.get(0))), operands.get(1), operands.get(0));
return rexBuilder.makeCall(op, newOperands);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project storm by apache.
the class StormSqlContext method interpretCreateFunction.
public void interpretCreateFunction(SqlCreateFunction sqlCreateFunction) throws ClassNotFoundException {
if (sqlCreateFunction.jarName() != null) {
throw new UnsupportedOperationException("UDF 'USING JAR' not implemented");
}
Method method;
Function function;
if ((method = findMethod(sqlCreateFunction.className(), "evaluate")) != null) {
function = ScalarFunctionImpl.create(method);
} else if (findMethod(sqlCreateFunction.className(), "add") != null) {
function = AggregateFunctionImpl.create(Class.forName(sqlCreateFunction.className()));
} else {
throw new RuntimeException("Invalid scalar or aggregate function");
}
schema.add(sqlCreateFunction.functionName().toUpperCase(), function);
hasUdf = true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class CalciteSchema method getTablesBasedOnNullaryFunctions.
/**
* Returns tables derived from explicit and implicit functions
* that take zero parameters.
*/
public final NavigableMap<String, Table> getTablesBasedOnNullaryFunctions() {
ImmutableSortedMap.Builder<String, Table> builder = new ImmutableSortedMap.Builder<>(NameSet.COMPARATOR);
for (Map.Entry<String, FunctionEntry> entry : nullaryFunctionMap.map().entrySet()) {
final Function function = entry.getValue().getFunction();
if (function instanceof TableMacro) {
assert function.getParameters().isEmpty();
final Table table = ((TableMacro) function).apply(ImmutableList.of());
builder.put(entry.getKey(), table);
}
}
// add tables derived from implicit functions
addImplicitTablesBasedOnNullaryFunctionsToBuilder(builder);
return Compatible.INSTANCE.navigableMap(builder.build());
}
Aggregations