Search in sources :

Example 1 with FunctionKind

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

the class FunctionCatalogOperatorTable method verifyFunctionKind.

/**
 * Verifies which kinds of functions are allowed to be returned from the catalog given the
 * context information.
 */
private boolean verifyFunctionKind(@Nullable SqlFunctionCategory category, ContextResolvedFunction resolvedFunction) {
    final FunctionDefinition definition = resolvedFunction.getDefinition();
    // built-in functions without implementation are handled separately
    if (definition instanceof BuiltInFunctionDefinition) {
        final BuiltInFunctionDefinition builtInFunction = (BuiltInFunctionDefinition) definition;
        if (!builtInFunction.hasRuntimeImplementation()) {
            return false;
        }
    }
    final FunctionKind kind = definition.getKind();
    if (kind == FunctionKind.TABLE) {
        return true;
    } else if (kind == FunctionKind.SCALAR || kind == FunctionKind.AGGREGATE || kind == FunctionKind.TABLE_AGGREGATE) {
        if (category != null && category.isTableFunction()) {
            throw new ValidationException(String.format("Function '%s' cannot be used as a table function.", resolvedFunction));
        }
        return true;
    }
    return false;
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) FunctionKind(org.apache.flink.table.functions.FunctionKind)

Example 2 with FunctionKind

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

the class BridgingSqlAggFunction method of.

/**
 * Creates an instance of a aggregating function (either a system or user-defined function).
 *
 * @param dataTypeFactory used for creating {@link DataType}
 * @param typeFactory used for bridging to {@link RelDataType}
 * @param kind commonly used SQL standard function; use {@link SqlKind#OTHER_FUNCTION} if this
 *     function cannot be mapped to a common function kind.
 * @param resolvedFunction system or user-defined {@link FunctionDefinition} with context
 * @param typeInference type inference logic
 */
public static BridgingSqlAggFunction of(DataTypeFactory dataTypeFactory, FlinkTypeFactory typeFactory, SqlKind kind, ContextResolvedFunction resolvedFunction, TypeInference typeInference) {
    final FunctionKind functionKind = resolvedFunction.getDefinition().getKind();
    checkState(functionKind == FunctionKind.AGGREGATE || functionKind == FunctionKind.TABLE_AGGREGATE, "Aggregating function kind expected.");
    return new BridgingSqlAggFunction(dataTypeFactory, typeFactory, kind, resolvedFunction, typeInference);
}
Also used : FunctionKind(org.apache.flink.table.functions.FunctionKind)

Example 3 with FunctionKind

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

the class BridgingSqlFunction method of.

/**
 * Creates an instance of a scalar or table function (either a system or user-defined function).
 *
 * @param dataTypeFactory used for creating {@link DataType}
 * @param typeFactory used for bridging to {@link RelDataType}
 * @param kind commonly used SQL standard function; use {@link SqlKind#OTHER_FUNCTION} if this
 *     function cannot be mapped to a common function kind.
 * @param resolvedFunction system or user-defined {@link FunctionDefinition} with context
 * @param typeInference type inference logic
 */
public static BridgingSqlFunction of(DataTypeFactory dataTypeFactory, FlinkTypeFactory typeFactory, SqlKind kind, ContextResolvedFunction resolvedFunction, TypeInference typeInference) {
    final FunctionKind functionKind = resolvedFunction.getDefinition().getKind();
    checkState(functionKind == FunctionKind.SCALAR || functionKind == FunctionKind.TABLE, "Scalar or table function kind expected.");
    return new BridgingSqlFunction(dataTypeFactory, typeFactory, kind, resolvedFunction, typeInference);
}
Also used : FunctionKind(org.apache.flink.table.functions.FunctionKind)

Aggregations

FunctionKind (org.apache.flink.table.functions.FunctionKind)3 ValidationException (org.apache.flink.table.api.ValidationException)1 AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)1 BuiltInFunctionDefinition (org.apache.flink.table.functions.BuiltInFunctionDefinition)1 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)1 ScalarFunctionDefinition (org.apache.flink.table.functions.ScalarFunctionDefinition)1 TableFunctionDefinition (org.apache.flink.table.functions.TableFunctionDefinition)1