Search in sources :

Example 56 with TableException

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

the class JsonObjectAggFunction method getValue.

@Override
public String getValue(Accumulator acc) {
    final ObjectNode rootNode = createObjectNode();
    try {
        for (final StringData key : acc.map.keys()) {
            final StringData value = acc.map.get(key);
            final JsonNode valueNode = value == null ? NULL_NODE : getNodeFactory().rawValueNode(new RawValue(value.toString()));
            rootNode.set(key.toString(), valueNode);
        }
    } catch (Exception e) {
        throw new TableException("The accumulator state could not be serialized.", e);
    }
    return serializeJson(rootNode);
}
Also used : TableException(org.apache.flink.table.api.TableException) ObjectNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode) SqlJsonUtils.createObjectNode(org.apache.flink.table.runtime.functions.SqlJsonUtils.createObjectNode) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) StringData(org.apache.flink.table.data.StringData) RawValue(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue) TableException(org.apache.flink.table.api.TableException)

Example 57 with TableException

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

the class ExecutionContext method createTableEnvironment.

// ------------------------------------------------------------------------------------------------------------------
// Helper to create Table Environment
// ------------------------------------------------------------------------------------------------------------------
private StreamTableEnvironment createTableEnvironment() {
    // checks the value of RUNTIME_MODE
    EnvironmentSettings settings = EnvironmentSettings.fromConfiguration(flinkConfig);
    if (!settings.isBlinkPlanner()) {
        throw new TableException("The old planner is not supported anymore. Please update to new default planner.");
    }
    TableConfig tableConfig = new TableConfig();
    tableConfig.addConfiguration(flinkConfig);
    StreamExecutionEnvironment streamExecEnv = createStreamExecutionEnvironment();
    final Executor executor = lookupExecutor(settings.getExecutor(), streamExecEnv);
    return createStreamTableEnvironment(streamExecEnv, settings, tableConfig, executor, sessionState.catalogManager, sessionState.moduleManager, sessionState.functionCatalog, classLoader);
}
Also used : EnvironmentSettings(org.apache.flink.table.api.EnvironmentSettings) TableException(org.apache.flink.table.api.TableException) Executor(org.apache.flink.table.delegation.Executor) TableConfig(org.apache.flink.table.api.TableConfig) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)

Example 58 with TableException

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

the class LogicalTypeDuplicator method visit.

@Override
public LogicalType visit(StructuredType structuredType) {
    final StructuredType.Builder builder = instantiateStructuredBuilder(structuredType);
    builder.attributes(duplicateStructuredAttributes(structuredType));
    builder.setNullable(structuredType.isNullable());
    builder.setFinal(structuredType.isFinal());
    builder.setInstantiable(structuredType.isInstantiable());
    builder.comparison(structuredType.getComparison());
    structuredType.getSuperType().ifPresent(st -> {
        final LogicalType visited = st.accept(this);
        if (!(visited instanceof StructuredType)) {
            throw new TableException("Unexpected super type. Structured type expected but was: " + visited);
        }
        builder.superType((StructuredType) visited);
    });
    structuredType.getDescription().ifPresent(builder::description);
    return builder.build();
}
Also used : TableException(org.apache.flink.table.api.TableException) LogicalType(org.apache.flink.table.types.logical.LogicalType) StructuredType(org.apache.flink.table.types.logical.StructuredType)

Example 59 with TableException

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

the class LegacyTypeInfoDataTypeConverter method toLegacyTypeInfo.

public static TypeInformation<?> toLegacyTypeInfo(DataType dataType) {
    // time indicators first as their hashCode/equals is shared with those of regular timestamps
    if (canConvertToTimeAttributeTypeInfo(dataType)) {
        return convertToTimeAttributeTypeInfo(dataType.getLogicalType());
    }
    // check in the map but relax the nullability constraint as every not null data type can be
    // stored in the corresponding nullable type information
    final TypeInformation<?> foundTypeInfo = dataTypeTypeInfoMap.get(dataType.nullable().bridgedTo(primitiveToWrapper(dataType.getConversionClass())));
    if (foundTypeInfo != null) {
        return foundTypeInfo;
    }
    // we are relaxing the constraint for DECIMAL, CHAR, VARCHAR, TIMESTAMP_WITHOUT_TIME_ZONE to
    // support value literals in legacy planner
    LogicalType logicalType = dataType.getLogicalType();
    if (logicalType.is(DECIMAL)) {
        return Types.BIG_DEC;
    } else if (logicalType.is(CHAR)) {
        return Types.STRING;
    } else if (logicalType.is(VARCHAR)) {
        return Types.STRING;
    } else // relax the precision constraint as Timestamp can store the highest precision
    if (logicalType.is(TIMESTAMP_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == Timestamp.class) {
        return Types.SQL_TIMESTAMP;
    } else // relax the precision constraint as LocalDateTime can store the highest precision
    if (logicalType.is(TIMESTAMP_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == LocalDateTime.class) {
        return Types.LOCAL_DATE_TIME;
    } else // convert proctime back
    if (logicalType.is(TIMESTAMP_WITH_LOCAL_TIME_ZONE) && dataType.getConversionClass() == Timestamp.class) {
        return Types.SQL_TIMESTAMP;
    } else // relax the precision constraint as LocalTime can store the highest precision
    if (logicalType.is(TIME_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == LocalTime.class) {
        return Types.LOCAL_TIME;
    } else if (canConvertToLegacyTypeInfo(dataType)) {
        return convertToLegacyTypeInfo(dataType);
    } else if (canConvertToRowTypeInfo(dataType)) {
        return convertToRowTypeInfo((FieldsDataType) dataType);
    } else // this could also match for basic array type info but this is covered by legacy type info
    if (canConvertToObjectArrayTypeInfo(dataType)) {
        return convertToObjectArrayTypeInfo((CollectionDataType) dataType);
    } else if (canConvertToMultisetTypeInfo(dataType)) {
        return convertToMultisetTypeInfo((CollectionDataType) dataType);
    } else if (canConvertToMapTypeInfo(dataType)) {
        return convertToMapTypeInfo((KeyValueDataType) dataType);
    } else // makes the raw type accessible in the legacy planner
    if (canConvertToRawTypeInfo(dataType)) {
        return convertToRawTypeInfo(dataType);
    }
    throw new TableException(String.format("Unsupported conversion from data type '%s' (conversion class: %s) to type information. Only data types " + "that originated from type information fully support a reverse conversion.", dataType, dataType.getConversionClass().getName()));
}
Also used : LocalDateTime(java.time.LocalDateTime) TableException(org.apache.flink.table.api.TableException) LocalTime(java.time.LocalTime) CollectionDataType(org.apache.flink.table.types.CollectionDataType) KeyValueDataType(org.apache.flink.table.types.KeyValueDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType)

Example 60 with TableException

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

the class RawType method getSerializerString.

/**
 * Returns the serialized {@link TypeSerializerSnapshot} in Base64 encoding of this raw type.
 */
public String getSerializerString() {
    if (serializerString == null) {
        final DataOutputSerializer outputSerializer = new DataOutputSerializer(128);
        try {
            TypeSerializerSnapshot.writeVersionedSnapshot(outputSerializer, serializer.snapshotConfiguration());
            serializerString = EncodingUtils.encodeBytesToBase64(outputSerializer.getCopyOfBuffer());
            return serializerString;
        } catch (Exception e) {
            throw new TableException(String.format("Unable to generate a string representation of the serializer snapshot of '%s' " + "describing the class '%s' for the RAW type.", serializer.getClass().getName(), clazz.toString()), e);
        }
    }
    return serializerString;
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) TableException(org.apache.flink.table.api.TableException) TableException(org.apache.flink.table.api.TableException) ValidationException(org.apache.flink.table.api.ValidationException)

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