use of org.apache.flink.table.types.FieldsDataType in project flink by apache.
the class DataTypeUtilsTest method testExpandDistinctType.
@Test
public void testExpandDistinctType() {
FieldsDataType dataType = (FieldsDataType) ROW(FIELD("f0", INT()), FIELD("f1", STRING()), FIELD("f2", TIMESTAMP(5).bridgedTo(Timestamp.class)), FIELD("f3", TIMESTAMP(3)));
LogicalType originalLogicalType = dataType.getLogicalType();
DistinctType distinctLogicalType = DistinctType.newBuilder(ObjectIdentifier.of("catalog", "database", "type"), originalLogicalType).build();
DataType distinctDataType = new FieldsDataType(distinctLogicalType, dataType.getChildren());
ResolvedSchema schema = DataTypeUtils.expandCompositeTypeToSchema(distinctDataType);
assertThat(schema).isEqualTo(ResolvedSchema.of(Column.physical("f0", INT()), Column.physical("f1", STRING()), Column.physical("f2", TIMESTAMP(5).bridgedTo(Timestamp.class)), Column.physical("f3", TIMESTAMP(3).bridgedTo(LocalDateTime.class))));
}
use of org.apache.flink.table.types.FieldsDataType in project flink by apache.
the class DataTypeUtilsTest method testExpandStructuredType.
@Test
public void testExpandStructuredType() {
StructuredType logicalType = StructuredType.newBuilder(ObjectIdentifier.of("catalog", "database", "type")).attributes(Arrays.asList(new StructuredType.StructuredAttribute("f0", DataTypes.INT().getLogicalType()), new StructuredType.StructuredAttribute("f1", DataTypes.STRING().getLogicalType()), new StructuredType.StructuredAttribute("f2", DataTypes.TIMESTAMP(5).getLogicalType()), new StructuredType.StructuredAttribute("f3", DataTypes.TIMESTAMP(3).getLogicalType()))).build();
List<DataType> dataTypes = Arrays.asList(DataTypes.INT(), DataTypes.STRING(), DataTypes.TIMESTAMP(5).bridgedTo(Timestamp.class), DataTypes.TIMESTAMP(3));
FieldsDataType dataType = new FieldsDataType(logicalType, dataTypes);
ResolvedSchema schema = DataTypeUtils.expandCompositeTypeToSchema(dataType);
assertThat(schema).isEqualTo(ResolvedSchema.of(Column.physical("f0", INT()), Column.physical("f1", STRING()), Column.physical("f2", TIMESTAMP(5).bridgedTo(Timestamp.class)), Column.physical("f3", TIMESTAMP(3).bridgedTo(LocalDateTime.class))));
}
use of org.apache.flink.table.types.FieldsDataType in project flink by apache.
the class LogicalTypeChecksTest method testIsCompositeTypeStructuredType.
@Test
public void testIsCompositeTypeStructuredType() {
StructuredType logicalType = StructuredType.newBuilder(ObjectIdentifier.of("catalog", "database", "type")).attributes(Arrays.asList(new StructuredType.StructuredAttribute("f0", DataTypes.INT().getLogicalType()), new StructuredType.StructuredAttribute("f1", DataTypes.STRING().getLogicalType()))).build();
List<DataType> fieldDataTypes = Arrays.asList(DataTypes.INT(), DataTypes.STRING());
FieldsDataType dataType = new FieldsDataType(logicalType, fieldDataTypes);
assertThat(LogicalTypeChecks.isCompositeType(dataType.getLogicalType())).isTrue();
}
use of org.apache.flink.table.types.FieldsDataType in project flink by apache.
the class DataTypeExtractorTest method getComplexPojoDataType.
/**
* Testing data type shared with the Scala tests.
*/
static DataType getComplexPojoDataType(Class<?> complexPojoClass, Class<?> simplePojoClass) {
final StructuredType.Builder builder = StructuredType.newBuilder(complexPojoClass);
builder.attributes(Arrays.asList(new StructuredAttribute("mapField", new MapType(VarCharType.STRING_TYPE, new IntType())), new StructuredAttribute("simplePojoField", getSimplePojoDataType(simplePojoClass).getLogicalType()), new StructuredAttribute("someObject", dummyRaw(Object.class).getLogicalType())));
builder.setFinal(true);
builder.setInstantiable(true);
final StructuredType structuredType = builder.build();
final List<DataType> fieldDataTypes = Arrays.asList(DataTypes.MAP(DataTypes.STRING(), DataTypes.INT()), getSimplePojoDataType(simplePojoClass), dummyRaw(Object.class));
return new FieldsDataType(structuredType, complexPojoClass, fieldDataTypes);
}
use of org.apache.flink.table.types.FieldsDataType in project flink by apache.
the class DataTypeExtractorTest method getOuterTupleDataType.
private static DataType getOuterTupleDataType() {
final StructuredType.Builder builder = StructuredType.newBuilder(Tuple2.class);
builder.attributes(Arrays.asList(new StructuredAttribute("f0", new IntType()), new StructuredAttribute("f1", getInnerTupleDataType().getLogicalType())));
builder.setFinal(true);
builder.setInstantiable(true);
final StructuredType structuredType = builder.build();
final List<DataType> fieldDataTypes = Arrays.asList(DataTypes.INT(), getInnerTupleDataType());
return new FieldsDataType(structuredType, Tuple2.class, fieldDataTypes);
}
Aggregations