Search in sources :

Example 31 with Function

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());
}
Also used : SchemaPlus(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus) JdbcConnection(org.apache.beam.sdk.extensions.sql.impl.JdbcConnection) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 32 with Function

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);
}
Also used : SqlOperator(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 33 with Function

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);
}
Also used : SqlOperator(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 34 with Function

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;
}
Also used : Function(org.apache.calcite.schema.Function) SqlCreateFunction(org.apache.storm.sql.parser.SqlCreateFunction) Method(java.lang.reflect.Method)

Example 35 with Function

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());
}
Also used : Function(org.apache.calcite.schema.Function) TableMacro(org.apache.calcite.schema.TableMacro) MaterializedViewTable(org.apache.calcite.schema.impl.MaterializedViewTable) Table(org.apache.calcite.schema.Table) StarTable(org.apache.calcite.schema.impl.StarTable) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) NameMap(org.apache.calcite.util.NameMap) NavigableMap(java.util.NavigableMap)

Aggregations

Function (org.apache.calcite.schema.Function)13 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)12 Method (java.lang.reflect.Method)11 ArrayList (java.util.ArrayList)11 SqlOperator (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator)6 RelDataType (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType)4 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)4 TableMacro (org.apache.calcite.schema.TableMacro)4 Test (org.junit.Test)4 ResolvedExpr (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedExpr)3 ResolvedLiteral (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedLiteral)3 JdbcConnection (org.apache.beam.sdk.extensions.sql.impl.JdbcConnection)3 SqlIdentifier (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier)3 Table (org.apache.calcite.schema.Table)3 Function (com.google.zetasql.Function)2 FunctionArgumentType (com.google.zetasql.FunctionArgumentType)2 FunctionSignature (com.google.zetasql.FunctionSignature)2 TableValuedFunction (com.google.zetasql.TableValuedFunction)2 Type (com.google.zetasql.Type)2 ResolvedAggregateFunctionCall (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedAggregateFunctionCall)2