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