use of org.apache.flink.table.types.logical.StructuredType.StructuredAttribute in project flink by apache.
the class DataTypeExtractorTest method getSimplePojoDataType.
/**
* Testing data type shared with the Scala tests.
*/
static DataType getSimplePojoDataType(Class<?> simplePojoClass) {
final StructuredType.Builder builder = StructuredType.newBuilder(simplePojoClass);
builder.attributes(Arrays.asList(new StructuredAttribute("intField", new IntType(true)), new StructuredAttribute("primitiveBooleanField", new BooleanType(false)), new StructuredAttribute("primitiveIntField", new IntType(false)), new StructuredAttribute("stringField", VarCharType.STRING_TYPE)));
builder.setFinal(true);
builder.setInstantiable(true);
final StructuredType structuredType = builder.build();
final List<DataType> fieldDataTypes = Arrays.asList(DataTypes.INT(), DataTypes.BOOLEAN().notNull().bridgedTo(boolean.class), DataTypes.INT().notNull().bridgedTo(int.class), DataTypes.STRING());
return new FieldsDataType(structuredType, simplePojoClass, fieldDataTypes);
}
use of org.apache.flink.table.types.logical.StructuredType.StructuredAttribute in project flink by apache.
the class DataTypeExtractorTest method getPojoWithCustomOrderDataType.
/**
* Testing data type shared with the Scala tests.
*/
public static DataType getPojoWithCustomOrderDataType(Class<?> pojoClass) {
final StructuredType.Builder builder = StructuredType.newBuilder(pojoClass);
builder.attributes(Arrays.asList(new StructuredAttribute("z", new BigIntType()), new StructuredAttribute("y", new BooleanType()), new StructuredAttribute("x", new IntType())));
builder.setFinal(true);
builder.setInstantiable(true);
final StructuredType structuredType = builder.build();
final List<DataType> fieldDataTypes = Arrays.asList(DataTypes.BIGINT(), DataTypes.BOOLEAN(), DataTypes.INT());
return new FieldsDataType(structuredType, pojoClass, fieldDataTypes);
}
use of org.apache.flink.table.types.logical.StructuredType.StructuredAttribute in project flink by apache.
the class LogicalTypeJsonDeserializer method deserializeStructuredTypeFromPlan.
private static LogicalType deserializeStructuredTypeFromPlan(JsonNode logicalTypeNode, SerdeContext serdeContext) {
final ObjectIdentifier identifier;
if (logicalTypeNode.has(FIELD_NAME_OBJECT_IDENTIFIER)) {
identifier = ObjectIdentifierJsonDeserializer.deserialize(logicalTypeNode.get(FIELD_NAME_OBJECT_IDENTIFIER).asText(), serdeContext);
} else {
identifier = null;
}
final Class<?> implementationClass;
if (logicalTypeNode.has(FIELD_NAME_IMPLEMENTATION_CLASS)) {
implementationClass = loadClass(logicalTypeNode.get(FIELD_NAME_IMPLEMENTATION_CLASS).asText(), serdeContext, "structured type");
} else {
implementationClass = null;
}
final StructuredType.Builder builder;
if (identifier != null && implementationClass != null) {
builder = StructuredType.newBuilder(identifier, implementationClass);
} else if (identifier != null) {
builder = StructuredType.newBuilder(identifier);
} else {
builder = StructuredType.newBuilder(implementationClass);
}
if (logicalTypeNode.has(FIELD_NAME_DESCRIPTION)) {
builder.description(logicalTypeNode.get(FIELD_NAME_FIELD_DESCRIPTION).asText());
}
final ArrayNode attributeNodes = (ArrayNode) logicalTypeNode.get(FIELD_NAME_ATTRIBUTES);
final List<StructuredAttribute> attributes = new ArrayList<>();
for (JsonNode attributeNode : attributeNodes) {
final String attributeName = attributeNode.get(FIELD_NAME_ATTRIBUTE_NAME).asText();
final LogicalType attributeType = deserialize(attributeNode.get(FIELD_NAME_ATTRIBUTE_TYPE), serdeContext);
final String attributeDescription;
if (attributeNode.has(FIELD_NAME_ATTRIBUTE_DESCRIPTION)) {
attributeDescription = attributeNode.get(FIELD_NAME_ATTRIBUTE_DESCRIPTION).asText();
} else {
attributeDescription = null;
}
attributes.add(new StructuredAttribute(attributeName, attributeType, attributeDescription));
}
builder.attributes(attributes);
if (logicalTypeNode.has(FIELD_NAME_FINAL)) {
builder.setFinal(logicalTypeNode.get(FIELD_NAME_FINAL).asBoolean());
}
if (logicalTypeNode.has(FIELD_NAME_INSTANTIABLE)) {
builder.setInstantiable(logicalTypeNode.get(FIELD_NAME_INSTANTIABLE).asBoolean());
}
if (logicalTypeNode.has(FIELD_NAME_COMPARISON)) {
builder.comparison(StructuredComparison.valueOf(logicalTypeNode.get(FIELD_NAME_COMPARISON).asText()));
}
if (logicalTypeNode.has(FIELD_NAME_SUPER_TYPE)) {
final StructuredType superType = (StructuredType) deserialize(logicalTypeNode.get(FIELD_NAME_SUPER_TYPE), serdeContext);
builder.superType(superType);
}
return builder.build();
}
use of org.apache.flink.table.types.logical.StructuredType.StructuredAttribute in project flink by apache.
the class LogicalTypeJsonSerializer method serializeStructuredType.
private static void serializeStructuredType(StructuredType structuredType, JsonGenerator jsonGenerator, SerializerProvider serializerProvider, boolean serializeCatalogObjects) throws IOException {
if (structuredType.getObjectIdentifier().isPresent()) {
serializerProvider.defaultSerializeField(FIELD_NAME_OBJECT_IDENTIFIER, structuredType.getObjectIdentifier().get(), jsonGenerator);
}
if (structuredType.getDescription().isPresent()) {
jsonGenerator.writeStringField(FIELD_NAME_DESCRIPTION, structuredType.getDescription().get());
}
if (structuredType.getImplementationClass().isPresent()) {
serializerProvider.defaultSerializeField(FIELD_NAME_IMPLEMENTATION_CLASS, structuredType.getImplementationClass().get(), jsonGenerator);
}
jsonGenerator.writeFieldName(FIELD_NAME_ATTRIBUTES);
jsonGenerator.writeStartArray();
for (StructuredAttribute attribute : structuredType.getAttributes()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(FIELD_NAME_ATTRIBUTE_NAME, attribute.getName());
jsonGenerator.writeFieldName(FIELD_NAME_ATTRIBUTE_TYPE);
serializeInternal(attribute.getType(), jsonGenerator, serializerProvider, serializeCatalogObjects);
if (attribute.getDescription().isPresent()) {
jsonGenerator.writeStringField(FIELD_NAME_ATTRIBUTE_DESCRIPTION, attribute.getDescription().get());
}
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
if (!structuredType.isFinal()) {
jsonGenerator.writeBooleanField(FIELD_NAME_FINAL, false);
}
if (!structuredType.isInstantiable()) {
jsonGenerator.writeBooleanField(FIELD_NAME_INSTANTIABLE, false);
}
if (structuredType.getComparison() != StructuredComparison.NONE) {
jsonGenerator.writeStringField(FIELD_NAME_COMPARISON, structuredType.getComparison().name());
}
if (structuredType.getSuperType().isPresent()) {
serializerProvider.defaultSerializeField(FIELD_NAME_SUPER_TYPE, structuredType.getSuperType().get(), jsonGenerator);
}
}
Aggregations