Search in sources :

Example 11 with StructuredType

use of org.apache.flink.table.types.logical.StructuredType in project flink by apache.

the class DataTypeExtractorTest method getInnerTupleDataType.

private static DataType getInnerTupleDataType() {
    final StructuredType.Builder builder = StructuredType.newBuilder(Tuple2.class);
    builder.attributes(Arrays.asList(new StructuredAttribute("f0", VarCharType.STRING_TYPE), new StructuredAttribute("f1", new BooleanType())));
    builder.setFinal(true);
    builder.setInstantiable(true);
    final StructuredType structuredType = builder.build();
    final List<DataType> fieldDataTypes = Arrays.asList(DataTypes.STRING(), DataTypes.BOOLEAN());
    return new FieldsDataType(structuredType, Tuple2.class, fieldDataTypes);
}
Also used : FieldsDataType(org.apache.flink.table.types.FieldsDataType) BooleanType(org.apache.flink.table.types.logical.BooleanType) 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)

Example 12 with StructuredType

use of org.apache.flink.table.types.logical.StructuredType 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);
}
Also used : FieldsDataType(org.apache.flink.table.types.FieldsDataType) BooleanType(org.apache.flink.table.types.logical.BooleanType) 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 13 with StructuredType

use of org.apache.flink.table.types.logical.StructuredType 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);
}
Also used : FieldsDataType(org.apache.flink.table.types.FieldsDataType) BooleanType(org.apache.flink.table.types.logical.BooleanType) StructuredAttribute(org.apache.flink.table.types.logical.StructuredType.StructuredAttribute) BigIntType(org.apache.flink.table.types.logical.BigIntType) 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 14 with StructuredType

use of org.apache.flink.table.types.logical.StructuredType in project flink by apache.

the class LogicalTypesTest method testUnregisteredStructuredType.

@Test
public void testUnregisteredStructuredType() {
    final StructuredType structuredType = createUserType(false, true);
    assertThat(structuredType).satisfies(nonEqualityCheckWithOtherType(createUserType(false, false))).satisfies(LogicalTypesTest::nullability).isJavaSerializable().hasNoSerializableString().hasSummaryString(String.format("*%s<`name` VARCHAR(1) '...', `setting` INT, `timestamp` TIMESTAMP(6)>*", User.class.getName())).satisfies(conversions(new Class[] { Row.class, User.class }, new Class[] { Row.class, Human.class, User.class })).hasExactlyChildren(UDT_NAME_TYPE, UDT_SETTING_TYPE, UDT_TIMESTAMP_TYPE);
}
Also used : StructuredType(org.apache.flink.table.types.logical.StructuredType) Test(org.junit.Test)

Example 15 with StructuredType

use of org.apache.flink.table.types.logical.StructuredType in project flink by apache.

the class RelDataTypeJsonSerdeTest method testRelDataTypeSerde.

// --------------------------------------------------------------------------------------------
// Test data
// --------------------------------------------------------------------------------------------
public static List<RelDataType> testRelDataTypeSerde() {
    // the values in the list do not care about nullable.
    final List<RelDataType> types = Arrays.asList(FACTORY.createSqlType(SqlTypeName.BOOLEAN), FACTORY.createSqlType(SqlTypeName.TINYINT), FACTORY.createSqlType(SqlTypeName.SMALLINT), FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.BIGINT), FACTORY.createSqlType(SqlTypeName.DECIMAL, 10, 3), FACTORY.createSqlType(SqlTypeName.DECIMAL, 19, 0), FACTORY.createSqlType(SqlTypeName.DECIMAL, 38, 19), FACTORY.createSqlType(SqlTypeName.FLOAT), FACTORY.createSqlType(SqlTypeName.DOUBLE), FACTORY.createSqlType(SqlTypeName.DATE), FACTORY.createSqlType(SqlTypeName.TIME), FACTORY.createSqlType(SqlTypeName.TIMESTAMP), FACTORY.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.DAY, 2, TimeUnit.MINUTE, RelDataType.PRECISION_NOT_SPECIFIED, SqlParserPos.ZERO)), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.DAY, 6, TimeUnit.SECOND, 9, SqlParserPos.ZERO)), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.HOUR, RelDataType.PRECISION_NOT_SPECIFIED, TimeUnit.SECOND, 9, SqlParserPos.ZERO)), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.MINUTE, RelDataType.PRECISION_NOT_SPECIFIED, TimeUnit.SECOND, 0, SqlParserPos.ZERO)), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.SECOND, RelDataType.PRECISION_NOT_SPECIFIED, TimeUnit.SECOND, 6, SqlParserPos.ZERO)), FACTORY.createSqlType(SqlTypeName.CHAR), FACTORY.createSqlType(SqlTypeName.CHAR, 0), FACTORY.createSqlType(SqlTypeName.CHAR, 32), FACTORY.createSqlType(SqlTypeName.VARCHAR), FACTORY.createSqlType(SqlTypeName.VARCHAR, 0), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10), FACTORY.createSqlType(SqlTypeName.BINARY), FACTORY.createSqlType(SqlTypeName.BINARY, 0), FACTORY.createSqlType(SqlTypeName.BINARY, 100), FACTORY.createSqlType(SqlTypeName.VARBINARY), FACTORY.createSqlType(SqlTypeName.VARBINARY, 0), FACTORY.createSqlType(SqlTypeName.VARBINARY, 1000), FACTORY.createSqlType(SqlTypeName.NULL), FACTORY.createSqlType(SqlTypeName.SYMBOL), FACTORY.createMultisetType(FACTORY.createSqlType(SqlTypeName.VARCHAR), -1), FACTORY.createArrayType(FACTORY.createSqlType(SqlTypeName.VARCHAR, 16), -1), FACTORY.createArrayType(FACTORY.createArrayType(FACTORY.createSqlType(SqlTypeName.VARCHAR, 16), -1), -1), FACTORY.createMapType(FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10)), FACTORY.createMapType(FACTORY.createMapType(FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10)), FACTORY.createArrayType(FACTORY.createMapType(FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10)), -1)), // simple struct type
    FACTORY.createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, Arrays.asList(FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.DECIMAL, 10, 3)), Arrays.asList("f1", "f2")), // struct type with array type
    FACTORY.createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, Arrays.asList(FACTORY.createSqlType(SqlTypeName.VARCHAR), FACTORY.createArrayType(FACTORY.createSqlType(SqlTypeName.VARCHAR, 16), -1)), Arrays.asList("f1", "f2")), // nested struct type
    FACTORY.createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, Arrays.asList(FACTORY.createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, Arrays.asList(FACTORY.createSqlType(SqlTypeName.VARCHAR, 5), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10)), Arrays.asList("f1", "f2")), FACTORY.createArrayType(FACTORY.createSqlType(SqlTypeName.VARCHAR, 16), -1)), Arrays.asList("f3", "f4")), FACTORY.createRowtimeIndicatorType(true, false), FACTORY.createRowtimeIndicatorType(true, true), FACTORY.createProctimeIndicatorType(true), FACTORY.createFieldTypeFromLogicalType(StructuredType.newBuilder(ObjectIdentifier.of("cat", "db", "structuredType"), DataTypeJsonSerdeTest.PojoClass.class).attributes(Arrays.asList(new StructuredType.StructuredAttribute("f0", new IntType(true)), new StructuredType.StructuredAttribute("f1", new BigIntType(true)), new StructuredType.StructuredAttribute("f2", new VarCharType(200), "desc"))).comparison(StructuredType.StructuredComparison.FULL).setFinal(false).setInstantiable(false).description("description for StructuredType").build()));
    final List<RelDataType> mutableTypes = new ArrayList<>(types.size() * 2);
    for (RelDataType type : types) {
        mutableTypes.add(FACTORY.createTypeWithNullability(type, true));
        mutableTypes.add(FACTORY.createTypeWithNullability(type, false));
    }
    mutableTypes.add(FACTORY.createTypeWithNullability(FACTORY.createFieldTypeFromLogicalType(new RawType<>(true, Void.class, VoidSerializer.INSTANCE)), true));
    mutableTypes.add(FACTORY.createTypeWithNullability(FACTORY.createFieldTypeFromLogicalType(new RawType<>(false, Void.class, VoidSerializer.INSTANCE)), false));
    mutableTypes.add(FACTORY.createTypeWithNullability(FACTORY.createFieldTypeFromLogicalType(new RawType<>(true, Void.class, VoidSerializer.INSTANCE)), false));
    return mutableTypes;
}
Also used : SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) ArrayList(java.util.ArrayList) BigIntType(org.apache.flink.table.types.logical.BigIntType) RelDataType(org.apache.calcite.rel.type.RelDataType) VarCharType(org.apache.flink.table.types.logical.VarCharType) 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

StructuredType (org.apache.flink.table.types.logical.StructuredType)19 DataType (org.apache.flink.table.types.DataType)11 FieldsDataType (org.apache.flink.table.types.FieldsDataType)9 BigIntType (org.apache.flink.table.types.logical.BigIntType)7 IntType (org.apache.flink.table.types.logical.IntType)7 StructuredAttribute (org.apache.flink.table.types.logical.StructuredType.StructuredAttribute)7 LogicalType (org.apache.flink.table.types.logical.LogicalType)6 BooleanType (org.apache.flink.table.types.logical.BooleanType)4 ArrayList (java.util.ArrayList)3 TableException (org.apache.flink.table.api.TableException)3 Test (org.junit.Test)3 LocalDateTime (java.time.LocalDateTime)2 List (java.util.List)2 IntStream (java.util.stream.IntStream)2 Internal (org.apache.flink.annotation.Internal)2 RowData (org.apache.flink.table.data.RowData)2 MapType (org.apache.flink.table.types.logical.MapType)2 RowType (org.apache.flink.table.types.logical.RowType)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1