Search in sources :

Example 1 with StructuredAttribute

use of org.apache.flink.table.types.logical.StructuredType.StructuredAttribute 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 2 with StructuredAttribute

use of org.apache.flink.table.types.logical.StructuredType.StructuredAttribute 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 3 with StructuredAttribute

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

the class StructuredRelDataType method create.

public static StructuredRelDataType create(FlinkTypeFactory factory, StructuredType structuredType) {
    final List<RelDataTypeField> fields = new ArrayList<>();
    for (int i = 0; i < structuredType.getAttributes().size(); i++) {
        final StructuredAttribute attribute = structuredType.getAttributes().get(i);
        final RelDataTypeField field = new RelDataTypeFieldImpl(attribute.getName(), i, factory.createFieldTypeFromLogicalType(attribute.getType()));
        fields.add(field);
    }
    return new StructuredRelDataType(structuredType, fields);
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) ArrayList(java.util.ArrayList) StructuredAttribute(org.apache.flink.table.types.logical.StructuredType.StructuredAttribute) RelDataTypeFieldImpl(org.apache.calcite.rel.type.RelDataTypeFieldImpl)

Example 4 with StructuredAttribute

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

the class DataTypeExtractorTest method getPojoWithRawSelfReferenceDataType.

private static DataType getPojoWithRawSelfReferenceDataType() {
    final StructuredType.Builder builder = StructuredType.newBuilder(PojoWithRawSelfReference.class);
    builder.attributes(Arrays.asList(new StructuredAttribute("integer", new IntType()), new StructuredAttribute("reference", dummyRaw(PojoWithRawSelfReference.class).getLogicalType())));
    builder.setFinal(true);
    builder.setInstantiable(true);
    final StructuredType structuredType = builder.build();
    final List<DataType> fieldDataTypes = Arrays.asList(DataTypes.INT(), dummyRaw(PojoWithRawSelfReference.class));
    return new FieldsDataType(structuredType, PojoWithRawSelfReference.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 5 with StructuredAttribute

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

Aggregations

StructuredAttribute (org.apache.flink.table.types.logical.StructuredType.StructuredAttribute)9 StructuredType (org.apache.flink.table.types.logical.StructuredType)7 DataType (org.apache.flink.table.types.DataType)6 FieldsDataType (org.apache.flink.table.types.FieldsDataType)6 BigIntType (org.apache.flink.table.types.logical.BigIntType)5 IntType (org.apache.flink.table.types.logical.IntType)5 BooleanType (org.apache.flink.table.types.logical.BooleanType)3 ArrayList (java.util.ArrayList)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 RelDataTypeFieldImpl (org.apache.calcite.rel.type.RelDataTypeFieldImpl)1 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1 MapType (org.apache.flink.table.types.logical.MapType)1