use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project beam by apache.
the class ZetaSqlScalarFunctionImpl method create.
/**
* Creates {@link org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function} from
* given method. When {@code eval} method does not suit, {@code null} is returned.
*
* @param method method that is used to implement the function
* @param functionGroup ZetaSQL function group identifier. Different function groups may have
* divergent translation paths.
* @return created {@link Function} or null
*/
public static Function create(Method method, String functionGroup, String jarPath) {
validateMethod(method);
CallImplementor implementor = createImplementor(method);
return new ZetaSqlScalarFunctionImpl(method, implementor, functionGroup, jarPath);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project beam by apache.
the class BeamZetaSqlCatalogTest method rejectsScalarFunctionImplWithUnsupportedParameterType.
@Test
public void rejectsScalarFunctionImplWithUnsupportedParameterType() throws NoSuchMethodException {
JdbcConnection jdbcConnection = createJdbcConnection();
SchemaPlus calciteSchema = jdbcConnection.getCurrentSchemaPlus();
Method method = TakesArrayTimeFn.class.getMethod("eval", List.class);
calciteSchema.add("take_array", ScalarFunctionImpl.create(method));
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Calcite type TIME not allowed in function take_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 SqlCaseWithValueOperatorRewriter method apply.
@Override
public RexNode apply(RexBuilder rexBuilder, List<RexNode> operands) {
Preconditions.checkArgument(operands.size() % 2 == 0 && !operands.isEmpty(), "$case_with_value should have an even number of arguments greater than 0 in function call" + " (The value operand, the else operand, and paired when/then operands).");
SqlOperator op = SqlStdOperatorTable.CASE;
List<RexNode> newOperands = new ArrayList<>();
RexNode value = operands.get(0);
for (int i = 1; i < operands.size() - 2; i += 2) {
RexNode when = operands.get(i);
RexNode then = operands.get(i + 1);
newOperands.add(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, ImmutableList.of(value, when)));
newOperands.add(then);
}
RexNode elseOperand = Iterables.getLast(operands);
newOperands.add(elseOperand);
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 ScalarFunctionImpl method create.
/**
* Creates {@link org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.schema.Function} from
* given method. When {@code eval} method does not suit, {@code null} is returned.
*
* @param method method that is used to implement the function
* @param jarPath Path to jar that contains the method.
* @return created {@link Function} or null
*/
public static Function create(Method method, String jarPath) {
validateMethod(method);
CallImplementor implementor = createImplementor(method);
return new ScalarFunctionImpl(method, implementor, jarPath);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project beam by apache.
the class BeamCalcRelType method canImplement.
@Override
protected boolean canImplement(RexCall call) {
final SqlOperator operator = call.getOperator();
RexImpTable.RexCallImplementor implementor = RexImpTable.INSTANCE.get(operator);
if (implementor == null) {
// Reject methods with no implementation
return false;
}
if (operator instanceof SqlUserDefinedFunction) {
SqlUserDefinedFunction udf = (SqlUserDefinedFunction) call.op;
if (udf.function instanceof ZetaSqlScalarFunctionImpl) {
ZetaSqlScalarFunctionImpl scalarFunction = (ZetaSqlScalarFunctionImpl) udf.function;
if (!scalarFunction.functionGroup.equals(BeamZetaSqlCatalog.USER_DEFINED_JAVA_SCALAR_FUNCTIONS)) {
// Reject ZetaSQL Builtin Scalar Functions
return false;
}
for (RexNode operand : call.getOperands()) {
if (operand instanceof RexLocalRef) {
if (!supportsType(operand.getType())) {
LOG.error("User-defined function {} received unsupported operand type {}.", call.op.getName(), ((RexLocalRef) operand).getType());
return false;
}
} else {
LOG.error("User-defined function {} received unrecognized operand kind {}.", call.op.getName(), operand.getKind());
return false;
}
}
} else {
// Reject other UDFs
return false;
}
} else {
// Reject Calcite implementations
return false;
}
return true;
}
Aggregations