Search in sources :

Example 81 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class ShuffleJsonDeserializer method deserialize.

@Override
public Shuffle deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
    Shuffle.Type type = Shuffle.Type.valueOf(jsonNode.get("type").asText().toUpperCase());
    switch(type) {
        case ANY:
            return ExecEdge.ANY_SHUFFLE;
        case SINGLETON:
            return ExecEdge.SINGLETON_SHUFFLE;
        case BROADCAST:
            return ExecEdge.BROADCAST_SHUFFLE;
        case FORWARD:
            return ExecEdge.FORWARD_SHUFFLE;
        case HASH:
            JsonNode keysNode = jsonNode.get("keys");
            if (keysNode == null || keysNode.size() == 0) {
                throw new TableException("Hash shuffle requires non-empty hash keys.");
            }
            int[] keys = new int[keysNode.size()];
            for (int i = 0; i < keysNode.size(); ++i) {
                keys[i] = keysNode.get(i).asInt();
            }
            return ExecEdge.hashShuffle(keys);
        default:
            throw new TableException("Unsupported shuffle type: " + type);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) Shuffle(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.Shuffle) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)

Example 82 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class RequiredDistributionJsonDeserializer method deserialize.

@Override
public RequiredDistribution deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
    DistributionType type = DistributionType.valueOf(jsonNode.get("type").asText().toUpperCase());
    switch(type) {
        case ANY:
            return InputProperty.ANY_DISTRIBUTION;
        case SINGLETON:
            return InputProperty.SINGLETON_DISTRIBUTION;
        case BROADCAST:
            return InputProperty.BROADCAST_DISTRIBUTION;
        case UNKNOWN:
            return InputProperty.UNKNOWN_DISTRIBUTION;
        case HASH:
            JsonNode keysNode = jsonNode.get("keys");
            if (keysNode == null) {
                throw new TableException("Hash distribution requires non-empty hash keys.");
            }
            int[] keys = new int[keysNode.size()];
            for (int i = 0; i < keysNode.size(); ++i) {
                keys[i] = keysNode.get(i).asInt();
            }
            return InputProperty.hashDistribution(keys);
        default:
            throw new TableException("Unsupported distribution type: " + type);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) DistributionType(org.apache.flink.table.planner.plan.nodes.exec.InputProperty.DistributionType)

Example 83 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class RexNodeJsonDeserializer method deserializeLiteral.

private static RexNode deserializeLiteral(JsonNode jsonNode, SerdeContext serdeContext) {
    final JsonNode logicalTypeNode = jsonNode.required(FIELD_NAME_TYPE);
    final RelDataType relDataType = RelDataTypeJsonDeserializer.deserialize(logicalTypeNode, serdeContext);
    if (jsonNode.has(FIELD_NAME_SARG)) {
        return deserializeSarg(jsonNode.required(FIELD_NAME_SARG), relDataType, serdeContext);
    } else if (jsonNode.has(FIELD_NAME_VALUE)) {
        final Object value = deserializeLiteralValue(jsonNode, relDataType.getSqlTypeName(), serdeContext);
        if (value == null) {
            return serdeContext.getRexBuilder().makeNullLiteral(relDataType);
        }
        return serdeContext.getRexBuilder().makeLiteral(value, relDataType, true);
    } else {
        throw new TableException("Unknown literal: " + jsonNode.toPrettyString());
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 84 with TableException

use of org.apache.flink.table.api.TableException in project flink by apache.

the class RexNodeJsonDeserializer method deserializeInternalFunction.

private static SqlOperator deserializeInternalFunction(String internalName, SqlSyntax syntax, SerdeContext serdeContext) {
    // Try $FUNC$1
    final Optional<SqlOperator> internalOperator = lookupOptionalSqlOperator(FunctionIdentifier.of(internalName), syntax, serdeContext, false);
    if (internalOperator.isPresent()) {
        return internalOperator.get();
    }
    // Try FUNC
    final String publicName = BuiltInSqlOperator.extractNameFromQualifiedName(internalName);
    final Optional<SqlOperator> latestOperator = lookupOptionalSqlOperator(FunctionIdentifier.of(publicName), syntax, serdeContext, true);
    if (latestOperator.isPresent()) {
        return latestOperator.get();
    }
    throw new TableException(String.format("Could not resolve internal system function '%s'. " + "This is a bug, please file an issue.", internalName));
}
Also used : TableException(org.apache.flink.table.api.TableException) BuiltInSqlOperator(org.apache.flink.table.planner.functions.sql.BuiltInSqlOperator) SqlOperator(org.apache.calcite.sql.SqlOperator) 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)

Example 85 with TableException

use of org.apache.flink.table.api.TableException 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

TableException (org.apache.flink.table.api.TableException)163 RowData (org.apache.flink.table.data.RowData)35 RowType (org.apache.flink.table.types.logical.RowType)35 Transformation (org.apache.flink.api.dag.Transformation)28 ArrayList (java.util.ArrayList)27 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)24 LogicalType (org.apache.flink.table.types.logical.LogicalType)24 List (java.util.List)22 DataType (org.apache.flink.table.types.DataType)19 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)18 ValidationException (org.apache.flink.table.api.ValidationException)17 IOException (java.io.IOException)13 AggregateCall (org.apache.calcite.rel.core.AggregateCall)13 ValueLiteralExpression (org.apache.flink.table.expressions.ValueLiteralExpression)13 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)13 Optional (java.util.Optional)11 Configuration (org.apache.flink.configuration.Configuration)11 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)11 Constructor (java.lang.reflect.Constructor)10 Arrays (java.util.Arrays)9