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