Search in sources :

Example 76 with TableException

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

the class LogicalTypeJsonDeserializer method deserializeDistinctType.

private static LogicalType deserializeDistinctType(JsonNode logicalTypeNode, SerdeContext serdeContext) {
    final ObjectIdentifier identifier = ObjectIdentifierJsonDeserializer.deserialize(logicalTypeNode.get(FIELD_NAME_OBJECT_IDENTIFIER).asText(), serdeContext);
    final CatalogPlanRestore restoreStrategy = serdeContext.getConfiguration().get(TableConfigOptions.PLAN_RESTORE_CATALOG_OBJECTS);
    switch(restoreStrategy) {
        case ALL:
            if (logicalTypeNode.has(FIELD_NAME_SOURCE_TYPE)) {
                return deserializeDistinctTypeFromPlan(identifier, logicalTypeNode, serdeContext);
            }
            return deserializeUserDefinedTypeFromCatalog(identifier, serdeContext);
        case ALL_ENFORCED:
            return deserializeDistinctTypeFromPlan(identifier, logicalTypeNode, serdeContext);
        case IDENTIFIER:
            return deserializeUserDefinedTypeFromCatalog(identifier, serdeContext);
        default:
            throw new TableException("Unsupported catalog restore strategy.");
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) CatalogPlanRestore(org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanRestore) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 77 with TableException

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

the class LogicalWindowJsonDeserializer method deserialize.

@Override
public LogicalWindow deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    JsonNode jsonNode = jsonParser.readValueAsTree();
    String kind = jsonNode.get(FIELD_NAME_KIND).asText().toUpperCase();
    WindowReference alias = deserializationContext.readValue(jsonNode.get(FIELD_NAME_ALIAS).traverse(jsonParser.getCodec()), WindowReference.class);
    FieldReferenceExpression timeField = deserializeFieldReferenceExpression(jsonNode.get(FIELD_NAME_TIME_FIELD), jsonParser, deserializationContext);
    switch(kind) {
        case KIND_TUMBLING:
            boolean isTimeTumblingWindow = jsonNode.get(FIELD_NAME_IS_TIME_WINDOW).asBoolean();
            if (isTimeTumblingWindow) {
                Duration size = deserializationContext.readValue(traverse(jsonNode.get(FIELD_NAME_SIZE), jsonParser.getCodec()), Duration.class);
                return new TumblingGroupWindow(alias, timeField, new ValueLiteralExpression(size));
            } else {
                long size = jsonNode.get(FIELD_NAME_SIZE).asLong();
                return new TumblingGroupWindow(alias, timeField, new ValueLiteralExpression(size));
            }
        case KIND_SLIDING:
            boolean isTimeSlidingWindow = jsonNode.get(FIELD_NAME_IS_TIME_WINDOW).asBoolean();
            if (isTimeSlidingWindow) {
                Duration size = deserializationContext.readValue(traverse(jsonNode.get(FIELD_NAME_SIZE), jsonParser.getCodec()), Duration.class);
                Duration slide = deserializationContext.readValue(traverse(jsonNode.get(FIELD_NAME_SLIDE), jsonParser.getCodec()), Duration.class);
                return new SlidingGroupWindow(alias, timeField, new ValueLiteralExpression(size), new ValueLiteralExpression(slide));
            } else {
                long size = jsonNode.get(FIELD_NAME_SIZE).asLong();
                long slide = jsonNode.get(FIELD_NAME_SLIDE).asLong();
                return new SlidingGroupWindow(alias, timeField, new ValueLiteralExpression(size), new ValueLiteralExpression(slide));
            }
        case KIND_SESSION:
            Duration gap = deserializationContext.readValue(traverse(jsonNode.get(FIELD_NAME_GAP), jsonParser.getCodec()), Duration.class);
            return new SessionGroupWindow(alias, timeField, new ValueLiteralExpression(gap));
        default:
            throw new TableException("Unknown Logical Window:" + jsonNode);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) TumblingGroupWindow(org.apache.flink.table.planner.plan.logical.TumblingGroupWindow) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) Duration(java.time.Duration) SlidingGroupWindow(org.apache.flink.table.planner.plan.logical.SlidingGroupWindow) SessionGroupWindow(org.apache.flink.table.planner.plan.logical.SessionGroupWindow) WindowReference(org.apache.flink.table.runtime.groupwindow.WindowReference)

Example 78 with TableException

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

the class RexNodeJsonSerializer method serializeLiteralValue.

private static void serializeLiteralValue(Comparable<?> value, SqlTypeName literalTypeName, SqlTypeName elementTypeName, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
    if (value == null) {
        gen.writeNullField(FIELD_NAME_VALUE);
        return;
    }
    switch(literalTypeName) {
        case BOOLEAN:
            gen.writeBooleanField(FIELD_NAME_VALUE, (Boolean) value);
            break;
        case TINYINT:
            gen.writeNumberField(FIELD_NAME_VALUE, ((BigDecimal) value).byteValue());
            break;
        case SMALLINT:
            gen.writeNumberField(FIELD_NAME_VALUE, ((BigDecimal) value).shortValue());
            break;
        case INTEGER:
            gen.writeNumberField(FIELD_NAME_VALUE, ((BigDecimal) value).intValue());
            break;
        case BIGINT:
            gen.writeNumberField(FIELD_NAME_VALUE, ((BigDecimal) value).longValue());
            break;
        case FLOAT:
            gen.writeNumberField(FIELD_NAME_VALUE, ((BigDecimal) value).floatValue());
            break;
        case DOUBLE:
            gen.writeNumberField(FIELD_NAME_VALUE, ((BigDecimal) value).doubleValue());
            break;
        case DECIMAL:
        case INTERVAL_YEAR:
        case INTERVAL_YEAR_MONTH:
        case INTERVAL_MONTH:
        case INTERVAL_DAY:
        case INTERVAL_DAY_HOUR:
        case INTERVAL_DAY_MINUTE:
        case INTERVAL_DAY_SECOND:
        case INTERVAL_HOUR:
        case INTERVAL_HOUR_MINUTE:
        case INTERVAL_HOUR_SECOND:
        case INTERVAL_MINUTE:
        case INTERVAL_MINUTE_SECOND:
        case INTERVAL_SECOND:
        case DATE:
        case TIME:
        case TIMESTAMP:
        case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
            gen.writeStringField(FIELD_NAME_VALUE, value.toString());
            break;
        case BINARY:
        case VARBINARY:
            gen.writeStringField(FIELD_NAME_VALUE, ((ByteString) value).toBase64String());
            break;
        case CHAR:
        case VARCHAR:
            gen.writeStringField(FIELD_NAME_VALUE, ((NlsString) value).getValue());
            break;
        case SYMBOL:
            final SerializableSymbol symbol = calciteToSerializable((Enum<?>) value);
            gen.writeStringField(FIELD_NAME_SYMBOL, symbol.getKind());
            gen.writeStringField(FIELD_NAME_VALUE, symbol.getValue());
            break;
        case SARG:
            serializeSargValue((Sarg<?>) value, elementTypeName, gen, serializerProvider);
            break;
        default:
            throw new TableException(String.format("Literal type '%s' is not supported for serializing value '%s'.", literalTypeName, value));
    }
}
Also used : SerializableSymbol(org.apache.flink.table.planner.typeutils.SymbolUtil.SerializableSymbol) TableException(org.apache.flink.table.api.TableException)

Example 79 with TableException

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

the class RexNodeJsonSerializer method serialize.

@Override
public void serialize(RexNode rexNode, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    final ReadableConfig config = SerdeContext.get(serializerProvider).getConfiguration();
    final CatalogPlanCompilation compilationStrategy = config.get(TableConfigOptions.PLAN_COMPILE_CATALOG_OBJECTS);
    switch(rexNode.getKind()) {
        case INPUT_REF:
        case TABLE_INPUT_REF:
            serializeInputRef((RexInputRef) rexNode, jsonGenerator, serializerProvider);
            break;
        case LITERAL:
            serializeLiteral((RexLiteral) rexNode, jsonGenerator, serializerProvider);
            break;
        case FIELD_ACCESS:
            serializeFieldAccess((RexFieldAccess) rexNode, jsonGenerator, serializerProvider);
            break;
        case CORREL_VARIABLE:
            serializeCorrelVariable((RexCorrelVariable) rexNode, jsonGenerator, serializerProvider);
            break;
        case PATTERN_INPUT_REF:
            serializePatternFieldRef((RexPatternFieldRef) rexNode, jsonGenerator, serializerProvider);
            break;
        default:
            if (rexNode instanceof RexCall) {
                serializeCall((RexCall) rexNode, jsonGenerator, serializerProvider, compilationStrategy);
            } else {
                throw new TableException("Unknown RexNode: " + rexNode);
            }
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) ReadableConfig(org.apache.flink.configuration.ReadableConfig) TableException(org.apache.flink.table.api.TableException) CatalogPlanCompilation(org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanCompilation)

Example 80 with TableException

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

the class LogicalWindowJsonSerializer method serialize.

@Override
public void serialize(LogicalWindow logicalWindow, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
    gen.writeStartObject();
    if (logicalWindow instanceof TumblingGroupWindow) {
        TumblingGroupWindow window = (TumblingGroupWindow) logicalWindow;
        gen.writeStringField(FIELD_NAME_KIND, KIND_TUMBLING);
        serializerProvider.defaultSerializeField(FIELD_NAME_ALIAS, window.aliasAttribute(), gen);
        FieldReferenceExpression timeField = logicalWindow.timeAttribute();
        serializeFieldReferenceExpression(timeField, gen, serializerProvider);
        ValueLiteralExpression size = window.size();
        if (hasTimeIntervalType(size)) {
            Duration duration = toDuration(size);
            gen.writeBooleanField(FIELD_NAME_IS_TIME_WINDOW, true);
            gen.writeObjectField(FIELD_NAME_SIZE, duration);
        } else {
            Long duration = toLong(size);
            gen.writeBooleanField(FIELD_NAME_IS_TIME_WINDOW, false);
            gen.writeNumberField(FIELD_NAME_SIZE, duration);
        }
    } else if (logicalWindow instanceof SlidingGroupWindow) {
        SlidingGroupWindow window = (SlidingGroupWindow) logicalWindow;
        gen.writeStringField(FIELD_NAME_KIND, KIND_SLIDING);
        serializerProvider.defaultSerializeField(FIELD_NAME_ALIAS, window.aliasAttribute(), gen);
        serializeFieldReferenceExpression(window.timeAttribute(), gen, serializerProvider);
        ValueLiteralExpression size = window.size();
        if (hasTimeIntervalType(size)) {
            Duration duration = toDuration(size);
            gen.writeBooleanField(FIELD_NAME_IS_TIME_WINDOW, true);
            gen.writeObjectField(FIELD_NAME_SIZE, duration);
            gen.writeObjectField(FIELD_NAME_SLIDE, toDuration(window.slide()));
        } else {
            Long duration = toLong(size);
            gen.writeBooleanField(FIELD_NAME_IS_TIME_WINDOW, false);
            gen.writeObjectField(FIELD_NAME_SIZE, duration);
            gen.writeObjectField(FIELD_NAME_SLIDE, toLong(window.slide()));
        }
    } else if (logicalWindow instanceof SessionGroupWindow) {
        gen.writeStringField(FIELD_NAME_KIND, KIND_SESSION);
        SessionGroupWindow window = (SessionGroupWindow) logicalWindow;
        serializerProvider.defaultSerializeField(FIELD_NAME_ALIAS, window.aliasAttribute(), gen);
        serializeFieldReferenceExpression(window.timeAttribute(), gen, serializerProvider);
        gen.writeObjectField(FIELD_NAME_GAP, toDuration(window.gap()));
    } else {
        throw new TableException("Unknown LogicalWindow: " + logicalWindow);
    }
    gen.writeEndObject();
}
Also used : TableException(org.apache.flink.table.api.TableException) TumblingGroupWindow(org.apache.flink.table.planner.plan.logical.TumblingGroupWindow) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) AggregateUtil.toLong(org.apache.flink.table.planner.plan.utils.AggregateUtil.toLong) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) Duration(java.time.Duration) AggregateUtil.toDuration(org.apache.flink.table.planner.plan.utils.AggregateUtil.toDuration) SlidingGroupWindow(org.apache.flink.table.planner.plan.logical.SlidingGroupWindow) SessionGroupWindow(org.apache.flink.table.planner.plan.logical.SessionGroupWindow)

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