Search in sources :

Example 66 with DataType

use of org.apache.flink.table.types.DataType in project flink by apache.

the class LogicalTypeChecksTest method testHasNested.

@Test
public void testHasNested() {
    final DataType dataType = ROW(FIELD("f0", INT()), FIELD("f1", STRING()));
    assertThat(LogicalTypeChecks.hasNested(dataType.getLogicalType(), t -> t.is(LogicalTypeRoot.VARCHAR))).isTrue();
    assertThat(LogicalTypeChecks.hasNested(dataType.getLogicalType(), t -> t.is(LogicalTypeRoot.ROW))).isTrue();
    assertThat(LogicalTypeChecks.hasNested(dataType.getLogicalType(), t -> t.is(LogicalTypeRoot.BOOLEAN))).isFalse();
}
Also used : DataType(org.apache.flink.table.types.DataType) FieldsDataType(org.apache.flink.table.types.FieldsDataType) Test(org.junit.Test)

Example 67 with DataType

use of org.apache.flink.table.types.DataType 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 68 with DataType

use of org.apache.flink.table.types.DataType 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 69 with DataType

use of org.apache.flink.table.types.DataType 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)

Example 70 with DataType

use of org.apache.flink.table.types.DataType in project flink by apache.

the class TypeTransformationsTest method testTimeToSqlTypes.

@Test
public void testTimeToSqlTypes() {
    DataType dataType = DataTypes.ROW(DataTypes.FIELD("a", DataTypes.STRING()), DataTypes.FIELD("b", DataTypes.TIMESTAMP()), DataTypes.FIELD("c", DataTypes.TIMESTAMP(5)), DataTypes.FIELD("d", DataTypes.ARRAY(DataTypes.TIME()).bridgedTo(List.class)), DataTypes.FIELD("e", DataTypes.MAP(DataTypes.DATE(), DataTypes.TIME(9))), DataTypes.FIELD("f", DataTypes.TIMESTAMP_WITH_TIME_ZONE()));
    DataType expected = DataTypes.ROW(DataTypes.FIELD("a", DataTypes.STRING()), DataTypes.FIELD("b", DataTypes.TIMESTAMP().bridgedTo(Timestamp.class)), DataTypes.FIELD("c", DataTypes.TIMESTAMP(5).bridgedTo(Timestamp.class)), DataTypes.FIELD("d", DataTypes.ARRAY(DataTypes.TIME().bridgedTo(Time.class)).bridgedTo(List.class)), DataTypes.FIELD("e", DataTypes.MAP(DataTypes.DATE().bridgedTo(Date.class), DataTypes.TIME(9).bridgedTo(Time.class))), DataTypes.FIELD("f", DataTypes.TIMESTAMP_WITH_TIME_ZONE()));
    assertEquals(expected, DataTypeUtils.transform(dataType, timeToSqlTypes()));
}
Also used : DataType(org.apache.flink.table.types.DataType) AtomicDataType(org.apache.flink.table.types.AtomicDataType) Time(java.sql.Time) Date(java.sql.Date) Test(org.junit.Test)

Aggregations

DataType (org.apache.flink.table.types.DataType)260 Test (org.junit.Test)72 RowType (org.apache.flink.table.types.logical.RowType)59 LogicalType (org.apache.flink.table.types.logical.LogicalType)58 RowData (org.apache.flink.table.data.RowData)54 List (java.util.List)38 FieldsDataType (org.apache.flink.table.types.FieldsDataType)32 ValidationException (org.apache.flink.table.api.ValidationException)31 ArrayList (java.util.ArrayList)29 Collectors (java.util.stream.Collectors)24 AtomicDataType (org.apache.flink.table.types.AtomicDataType)24 Map (java.util.Map)23 Internal (org.apache.flink.annotation.Internal)23 TableException (org.apache.flink.table.api.TableException)23 HashMap (java.util.HashMap)22 GenericRowData (org.apache.flink.table.data.GenericRowData)22 Row (org.apache.flink.types.Row)22 TableSchema (org.apache.flink.table.api.TableSchema)20 TypeConversions.fromLogicalToDataType (org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType)19 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)18