Search in sources :

Example 1 with SqlUserDefinedAggFunction

use of org.apache.calcite.sql.validate.SqlUserDefinedAggFunction in project storm by apache.

the class RelNodeCompiler method aggregate.

private void aggregate(AggregateCall call) {
    SqlAggFunction aggFunction = call.getAggregation();
    String aggregationName = call.getAggregation().getName();
    Type ty = typeFactory.getJavaClass(call.getType());
    if (call.getArgList().size() != 1) {
        if (aggregationName.equals("COUNT")) {
            if (call.getArgList().size() != 0) {
                throw new UnsupportedOperationException("Count with nullable fields");
            }
        }
    }
    if (aggFunction instanceof SqlUserDefinedAggFunction) {
        AggregateFunction aggregateFunction = ((SqlUserDefinedAggFunction) aggFunction).function;
        doAggregate((AggregateFunctionImpl) aggregateFunction, reserveAggVarName(call), ty, call.getArgList());
    } else {
        List<BuiltinAggregateFunctions.TypeClass> typeClasses = BuiltinAggregateFunctions.TABLE.get(aggregationName);
        if (typeClasses == null) {
            throw new UnsupportedOperationException(aggregationName + " Not implemented");
        }
        doAggregate(AggregateFunctionImpl.create(findMatchingClass(aggregationName, typeClasses, ty)), reserveAggVarName(call), ty, call.getArgList());
    }
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) Type(java.lang.reflect.Type) AggregateFunction(org.apache.calcite.schema.AggregateFunction) SqlUserDefinedAggFunction(org.apache.calcite.sql.validate.SqlUserDefinedAggFunction) SqlAggFunction(org.apache.calcite.sql.SqlAggFunction)

Example 2 with SqlUserDefinedAggFunction

use of org.apache.calcite.sql.validate.SqlUserDefinedAggFunction in project calcite by apache.

the class CalciteCatalogReader method operatorTable.

/**
 * Creates an operator table that contains functions in the given class.
 *
 * @see ModelHandler#addFunctions
 */
public static SqlOperatorTable operatorTable(String className) {
    // Dummy schema to collect the functions
    final CalciteSchema schema = CalciteSchema.createRootSchema(false, false);
    ModelHandler.addFunctions(schema.plus(), null, ImmutableList.<String>of(), className, "*", true);
    // The following is technical debt; see [CALCITE-2082] Remove
    // RelDataTypeFactory argument from SqlUserDefinedAggFunction constructor
    final SqlTypeFactoryImpl typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    final ListSqlOperatorTable table = new ListSqlOperatorTable();
    for (String name : schema.getFunctionNames()) {
        for (Function function : schema.getFunctions(name, true)) {
            final SqlIdentifier id = new SqlIdentifier(name, SqlParserPos.ZERO);
            table.add(toOp(typeFactory, id, function));
        }
    }
    return table;
}
Also used : ListSqlOperatorTable(org.apache.calcite.sql.util.ListSqlOperatorTable) SqlUserDefinedFunction(org.apache.calcite.sql.validate.SqlUserDefinedFunction) TableFunction(org.apache.calcite.schema.TableFunction) SqlUserDefinedAggFunction(org.apache.calcite.sql.validate.SqlUserDefinedAggFunction) Function(org.apache.calcite.schema.Function) AggregateFunction(org.apache.calcite.schema.AggregateFunction) SqlUserDefinedTableFunction(org.apache.calcite.sql.validate.SqlUserDefinedTableFunction) ScalarFunction(org.apache.calcite.schema.ScalarFunction) SqlTypeFactoryImpl(org.apache.calcite.sql.type.SqlTypeFactoryImpl) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier)

Example 3 with SqlUserDefinedAggFunction

use of org.apache.calcite.sql.validate.SqlUserDefinedAggFunction in project storm by apache.

the class RelNodeCompiler method aggregateResult.

private String aggregateResult(AggregateCall call, PrintWriter pw) {
    SqlAggFunction aggFunction = call.getAggregation();
    String aggregationName = call.getAggregation().getName();
    Type ty = typeFactory.getJavaClass(call.getType());
    String result;
    if (aggFunction instanceof SqlUserDefinedAggFunction) {
        AggregateFunction aggregateFunction = ((SqlUserDefinedAggFunction) aggFunction).function;
        result = doAggregateResult((AggregateFunctionImpl) aggregateFunction, reserveAggVarName(call), ty, pw);
    } else {
        List<BuiltinAggregateFunctions.TypeClass> typeClasses = BuiltinAggregateFunctions.TABLE.get(aggregationName);
        if (typeClasses == null) {
            throw new UnsupportedOperationException(aggregationName + " Not implemented");
        }
        result = doAggregateResult(AggregateFunctionImpl.create(findMatchingClass(aggregationName, typeClasses, ty)), reserveAggVarName(call), ty, pw);
    }
    return result;
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) Type(java.lang.reflect.Type) AggregateFunction(org.apache.calcite.schema.AggregateFunction) AggregateFunctionImpl(org.apache.calcite.schema.impl.AggregateFunctionImpl) SqlUserDefinedAggFunction(org.apache.calcite.sql.validate.SqlUserDefinedAggFunction) SqlAggFunction(org.apache.calcite.sql.SqlAggFunction)

Example 4 with SqlUserDefinedAggFunction

use of org.apache.calcite.sql.validate.SqlUserDefinedAggFunction in project streamline by hortonworks.

the class RelNodeCompiler method aggregate.

private void aggregate(AggregateCall call) {
    SqlAggFunction aggFunction = call.getAggregation();
    String aggregationName = call.getAggregation().getName();
    Type ty = typeFactory.getJavaClass(call.getType());
    if (call.getArgList().size() != 1) {
        if (aggregationName.equals("COUNT")) {
            if (call.getArgList().size() != 0) {
                throw new UnsupportedOperationException("Count with nullable fields");
            }
        }
    }
    if (aggFunction instanceof SqlUserDefinedAggFunction) {
        AggregateFunction aggregateFunction = ((SqlUserDefinedAggFunction) aggFunction).function;
        doAggregate((AggregateFunctionImpl) aggregateFunction, reserveAggVarName(call), ty, call.getArgList());
    } else {
        List<BuiltinAggregateFunctions.TypeClass> typeClasses = BuiltinAggregateFunctions.TABLE.get(aggregationName);
        if (typeClasses == null) {
            throw new UnsupportedOperationException(aggregationName + " Not implemented");
        }
        doAggregate(AggregateFunctionImpl.create(findMatchingClass(aggregationName, typeClasses, ty)), reserveAggVarName(call), ty, call.getArgList());
    }
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) Type(java.lang.reflect.Type) AggregateFunction(org.apache.calcite.schema.AggregateFunction) SqlUserDefinedAggFunction(org.apache.calcite.sql.validate.SqlUserDefinedAggFunction) SqlAggFunction(org.apache.calcite.sql.SqlAggFunction)

Example 5 with SqlUserDefinedAggFunction

use of org.apache.calcite.sql.validate.SqlUserDefinedAggFunction in project streamline by hortonworks.

the class RelNodeCompiler method aggregateResult.

private String aggregateResult(AggregateCall call, PrintWriter pw) {
    SqlAggFunction aggFunction = call.getAggregation();
    String aggregationName = call.getAggregation().getName();
    Type ty = typeFactory.getJavaClass(call.getType());
    String result;
    if (aggFunction instanceof SqlUserDefinedAggFunction) {
        AggregateFunction aggregateFunction = ((SqlUserDefinedAggFunction) aggFunction).function;
        result = doAggregateResult((AggregateFunctionImpl) aggregateFunction, reserveAggVarName(call), ty, pw);
    } else {
        List<BuiltinAggregateFunctions.TypeClass> typeClasses = BuiltinAggregateFunctions.TABLE.get(aggregationName);
        if (typeClasses == null) {
            throw new UnsupportedOperationException(aggregationName + " Not implemented");
        }
        result = doAggregateResult(AggregateFunctionImpl.create(findMatchingClass(aggregationName, typeClasses, ty)), reserveAggVarName(call), ty, pw);
    }
    return result;
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) Type(java.lang.reflect.Type) AggregateFunction(org.apache.calcite.schema.AggregateFunction) AggregateFunctionImpl(org.apache.calcite.schema.impl.AggregateFunctionImpl) SqlUserDefinedAggFunction(org.apache.calcite.sql.validate.SqlUserDefinedAggFunction) SqlAggFunction(org.apache.calcite.sql.SqlAggFunction)

Aggregations

AggregateFunction (org.apache.calcite.schema.AggregateFunction)6 SqlUserDefinedAggFunction (org.apache.calcite.sql.validate.SqlUserDefinedAggFunction)6 RelDataType (org.apache.calcite.rel.type.RelDataType)5 Type (java.lang.reflect.Type)4 SqlAggFunction (org.apache.calcite.sql.SqlAggFunction)4 ScalarFunction (org.apache.calcite.schema.ScalarFunction)2 TableFunction (org.apache.calcite.schema.TableFunction)2 AggregateFunctionImpl (org.apache.calcite.schema.impl.AggregateFunctionImpl)2 SqlUserDefinedFunction (org.apache.calcite.sql.validate.SqlUserDefinedFunction)2 SqlUserDefinedTableFunction (org.apache.calcite.sql.validate.SqlUserDefinedTableFunction)2 ArrayList (java.util.ArrayList)1 CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)1 PredicateImpl (org.apache.calcite.runtime.PredicateImpl)1 Function (org.apache.calcite.schema.Function)1 FunctionParameter (org.apache.calcite.schema.FunctionParameter)1 TableMacro (org.apache.calcite.schema.TableMacro)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1 FamilyOperandTypeChecker (org.apache.calcite.sql.type.FamilyOperandTypeChecker)1 SqlTypeFactoryImpl (org.apache.calcite.sql.type.SqlTypeFactoryImpl)1 SqlTypeFamily (org.apache.calcite.sql.type.SqlTypeFamily)1