Search in sources :

Example 1 with ZetaSqlScalarFunctionImpl

use of org.apache.beam.sdk.extensions.sql.zetasql.translation.ZetaSqlScalarFunctionImpl 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;
}
Also used : SqlUserDefinedFunction(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlUserDefinedFunction) ZetaSqlScalarFunctionImpl(org.apache.beam.sdk.extensions.sql.zetasql.translation.ZetaSqlScalarFunctionImpl) SqlOperator(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator) RexLocalRef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLocalRef) RexImpTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.adapter.enumerable.RexImpTable) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Aggregations

ZetaSqlScalarFunctionImpl (org.apache.beam.sdk.extensions.sql.zetasql.translation.ZetaSqlScalarFunctionImpl)1 RexImpTable (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.adapter.enumerable.RexImpTable)1 RexLocalRef (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLocalRef)1 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)1 SqlOperator (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator)1 SqlUserDefinedFunction (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlUserDefinedFunction)1