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.");
}
}
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);
}
}
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));
}
}
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);
}
}
}
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();
}
Aggregations