Search in sources :

Example 1 with FieldsDataType

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))));
}
Also used : LocalDateTime(java.time.LocalDateTime) FieldsDataType(org.apache.flink.table.types.FieldsDataType) DistinctType(org.apache.flink.table.types.logical.DistinctType) LogicalType(org.apache.flink.table.types.logical.LogicalType) DataType(org.apache.flink.table.types.DataType) FieldsDataType(org.apache.flink.table.types.FieldsDataType) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 2 with FieldsDataType

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))));
}
Also used : LocalDateTime(java.time.LocalDateTime) FieldsDataType(org.apache.flink.table.types.FieldsDataType) DataType(org.apache.flink.table.types.DataType) FieldsDataType(org.apache.flink.table.types.FieldsDataType) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Timestamp(java.sql.Timestamp) StructuredType(org.apache.flink.table.types.logical.StructuredType) Test(org.junit.Test)

Example 3 with FieldsDataType

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();
}
Also used : FieldsDataType(org.apache.flink.table.types.FieldsDataType) DataType(org.apache.flink.table.types.DataType) FieldsDataType(org.apache.flink.table.types.FieldsDataType) StructuredType(org.apache.flink.table.types.logical.StructuredType) Test(org.junit.Test)

Example 4 with FieldsDataType

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);
}
Also used : FieldsDataType(org.apache.flink.table.types.FieldsDataType) StructuredAttribute(org.apache.flink.table.types.logical.StructuredType.StructuredAttribute) DataType(org.apache.flink.table.types.DataType) FieldsDataType(org.apache.flink.table.types.FieldsDataType) MapType(org.apache.flink.table.types.logical.MapType) StructuredType(org.apache.flink.table.types.logical.StructuredType) IntType(org.apache.flink.table.types.logical.IntType) BigIntType(org.apache.flink.table.types.logical.BigIntType)

Example 5 with FieldsDataType

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);
}
Also used : FieldsDataType(org.apache.flink.table.types.FieldsDataType) StructuredAttribute(org.apache.flink.table.types.logical.StructuredType.StructuredAttribute) DataType(org.apache.flink.table.types.DataType) FieldsDataType(org.apache.flink.table.types.FieldsDataType) StructuredType(org.apache.flink.table.types.logical.StructuredType) IntType(org.apache.flink.table.types.logical.IntType) BigIntType(org.apache.flink.table.types.logical.BigIntType)

Aggregations

DataType (org.apache.flink.table.types.DataType)14 FieldsDataType (org.apache.flink.table.types.FieldsDataType)14 StructuredType (org.apache.flink.table.types.logical.StructuredType)11 StructuredAttribute (org.apache.flink.table.types.logical.StructuredType.StructuredAttribute)8 BigIntType (org.apache.flink.table.types.logical.BigIntType)6 IntType (org.apache.flink.table.types.logical.IntType)6 LogicalType (org.apache.flink.table.types.logical.LogicalType)5 CollectionDataType (org.apache.flink.table.types.CollectionDataType)4 KeyValueDataType (org.apache.flink.table.types.KeyValueDataType)4 BooleanType (org.apache.flink.table.types.logical.BooleanType)4 MapType (org.apache.flink.table.types.logical.MapType)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3 Nullable (javax.annotation.Nullable)3 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)3 Test (org.junit.Test)3 Timestamp (java.sql.Timestamp)2 LocalDateTime (java.time.LocalDateTime)2 Arrays (java.util.Arrays)2