Search in sources :

Example 1 with ContextResolvedFunction

use of org.apache.flink.table.catalog.ContextResolvedFunction in project flink by apache.

the class RexNodeJsonDeserializer method deserializeFunctionClass.

private static SqlOperator deserializeFunctionClass(JsonNode jsonNode, SerdeContext serdeContext) {
    final String className = jsonNode.required(FIELD_NAME_CLASS).asText();
    final Class<?> functionClass = loadClass(className, serdeContext, "function");
    final UserDefinedFunction functionInstance = UserDefinedFunctionHelper.instantiateFunction(functionClass);
    final ContextResolvedFunction resolvedFunction;
    // because we never serialize classes for system functions
    if (jsonNode.has(FIELD_NAME_CATALOG_NAME)) {
        final ObjectIdentifier objectIdentifier = ObjectIdentifierJsonDeserializer.deserialize(jsonNode.required(FIELD_NAME_CATALOG_NAME).asText(), serdeContext);
        resolvedFunction = ContextResolvedFunction.permanent(FunctionIdentifier.of(objectIdentifier), functionInstance);
    } else {
        resolvedFunction = ContextResolvedFunction.anonymous(functionInstance);
    }
    switch(functionInstance.getKind()) {
        case SCALAR:
        case TABLE:
            return BridgingSqlFunction.of(serdeContext.getFlinkContext(), serdeContext.getTypeFactory(), resolvedFunction);
        case AGGREGATE:
            return BridgingSqlAggFunction.of(serdeContext.getFlinkContext(), serdeContext.getTypeFactory(), resolvedFunction);
        default:
            throw new TableException(String.format("Unsupported anonymous function kind '%s' for class '%s'.", functionInstance.getKind(), className));
    }
}
Also used : ContextResolvedFunction(org.apache.flink.table.catalog.ContextResolvedFunction) TableException(org.apache.flink.table.api.TableException) UserDefinedFunction(org.apache.flink.table.functions.UserDefinedFunction) DateString(org.apache.calcite.util.DateString) ByteString(org.apache.calcite.avatica.util.ByteString) TimestampString(org.apache.calcite.util.TimestampString) TimeString(org.apache.calcite.util.TimeString) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Aggregations

ByteString (org.apache.calcite.avatica.util.ByteString)1 DateString (org.apache.calcite.util.DateString)1 TimeString (org.apache.calcite.util.TimeString)1 TimestampString (org.apache.calcite.util.TimestampString)1 TableException (org.apache.flink.table.api.TableException)1 ContextResolvedFunction (org.apache.flink.table.catalog.ContextResolvedFunction)1 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)1 UserDefinedFunction (org.apache.flink.table.functions.UserDefinedFunction)1