Search in sources :

Example 1 with TableAggregateFunctionDefinition

use of org.apache.flink.table.functions.TableAggregateFunctionDefinition in project flink by apache.

the class SqlAggFunctionVisitor method createSqlAggFunction.

private SqlAggFunction createSqlAggFunction(CallExpression call) {
    final FunctionDefinition definition = call.getFunctionDefinition();
    // legacy
    if (definition instanceof AggregateFunctionDefinition) {
        return createLegacySqlAggregateFunction(call.getFunctionIdentifier().orElse(null), (AggregateFunctionDefinition) definition);
    } else if (definition instanceof TableAggregateFunctionDefinition) {
        return createLegacySqlTableAggregateFunction(call.getFunctionIdentifier().orElse(null), (TableAggregateFunctionDefinition) definition);
    }
    // new stack
    final DataTypeFactory dataTypeFactory = ShortcutUtils.unwrapContext(relBuilder).getCatalogManager().getDataTypeFactory();
    final TypeInference typeInference = definition.getTypeInference(dataTypeFactory);
    return BridgingSqlAggFunction.of(dataTypeFactory, ShortcutUtils.unwrapTypeFactory(relBuilder), SqlKind.OTHER_FUNCTION, ContextResolvedFunction.fromCallExpression(call), typeInference);
}
Also used : TypeInference(org.apache.flink.table.types.inference.TypeInference) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) DataTypeFactory(org.apache.flink.table.catalog.DataTypeFactory)

Example 2 with TableAggregateFunctionDefinition

use of org.apache.flink.table.functions.TableAggregateFunctionDefinition in project flink by apache.

the class FunctionCatalog method registerTempSystemAggregateFunction.

/**
 * @deprecated Use {@link #registerTemporarySystemFunction(String, FunctionDefinition, boolean)}
 *     instead.
 */
@Deprecated
public <T, ACC> void registerTempSystemAggregateFunction(String name, ImperativeAggregateFunction<T, ACC> function, TypeInformation<T> resultType, TypeInformation<ACC> accType) {
    UserDefinedFunctionHelper.prepareInstance(config, function);
    final FunctionDefinition definition;
    if (function instanceof AggregateFunction) {
        definition = new AggregateFunctionDefinition(name, (AggregateFunction<?, ?>) function, resultType, accType);
    } else if (function instanceof TableAggregateFunction) {
        definition = new TableAggregateFunctionDefinition(name, (TableAggregateFunction<?, ?>) function, resultType, accType);
    } else {
        throw new TableException("Unknown function class: " + function.getClass());
    }
    registerTempSystemFunction(name, definition);
}
Also used : TableException(org.apache.flink.table.api.TableException) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) TableAggregateFunction(org.apache.flink.table.functions.TableAggregateFunction) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) AggregateFunction(org.apache.flink.table.functions.AggregateFunction) TableAggregateFunction(org.apache.flink.table.functions.TableAggregateFunction) ImperativeAggregateFunction(org.apache.flink.table.functions.ImperativeAggregateFunction) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition)

Example 3 with TableAggregateFunctionDefinition

use of org.apache.flink.table.functions.TableAggregateFunctionDefinition in project flink by apache.

the class RexNodeJsonSerializer method serializeBridgingSqlFunction.

private static void serializeBridgingSqlFunction(String summaryName, ContextResolvedFunction resolvedFunction, JsonGenerator gen, SerializerProvider serializerProvider, boolean serializeCatalogObjects) throws IOException {
    final FunctionDefinition definition = resolvedFunction.getDefinition();
    if (definition instanceof ScalarFunctionDefinition || definition instanceof TableFunctionDefinition || definition instanceof TableAggregateFunctionDefinition || definition instanceof AggregateFunctionDefinition) {
        throw legacyException(summaryName);
    }
    if (definition instanceof BuiltInFunctionDefinition) {
        final BuiltInFunctionDefinition builtInFunction = (BuiltInFunctionDefinition) definition;
        gen.writeStringField(FIELD_NAME_INTERNAL_NAME, builtInFunction.getQualifiedName());
    } else if (resolvedFunction.isAnonymous()) {
        serializeInlineFunction(summaryName, definition, gen);
    } else if (resolvedFunction.isTemporary()) {
        serializeTemporaryFunction(resolvedFunction, gen, serializerProvider);
    } else {
        assert resolvedFunction.isPermanent();
        serializePermanentFunction(resolvedFunction, gen, serializerProvider, serializeCatalogObjects);
    }
}
Also used : ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition)

Aggregations

AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)3 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)3 TableAggregateFunctionDefinition (org.apache.flink.table.functions.TableAggregateFunctionDefinition)3 ScalarFunctionDefinition (org.apache.flink.table.functions.ScalarFunctionDefinition)2 TableFunctionDefinition (org.apache.flink.table.functions.TableFunctionDefinition)2 TableException (org.apache.flink.table.api.TableException)1 DataTypeFactory (org.apache.flink.table.catalog.DataTypeFactory)1 AggregateFunction (org.apache.flink.table.functions.AggregateFunction)1 BuiltInFunctionDefinition (org.apache.flink.table.functions.BuiltInFunctionDefinition)1 ImperativeAggregateFunction (org.apache.flink.table.functions.ImperativeAggregateFunction)1 TableAggregateFunction (org.apache.flink.table.functions.TableAggregateFunction)1 TypeInference (org.apache.flink.table.types.inference.TypeInference)1