Search in sources :

Example 6 with DistinctType

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

the class LogicalTypeUtils method toRowType.

/**
 * Converts any logical type to a row type. Composite types are converted to a row type. Atomic
 * types are wrapped into a field.
 */
public static RowType toRowType(LogicalType t) {
    switch(t.getTypeRoot()) {
        case ROW:
            return (RowType) t;
        case STRUCTURED_TYPE:
            final StructuredType structuredType = (StructuredType) t;
            final List<RowField> fields = structuredType.getAttributes().stream().map(attribute -> new RowField(attribute.getName(), attribute.getType(), attribute.getDescription().orElse(null))).collect(Collectors.toList());
            return new RowType(structuredType.isNullable(), fields);
        case DISTINCT_TYPE:
            return toRowType(((DistinctType) t).getSourceType());
        default:
            return RowType.of(t);
    }
}
Also used : RowField(org.apache.flink.table.types.logical.RowType.RowField) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) IntStream(java.util.stream.IntStream) RowData(org.apache.flink.table.data.RowData) TimestampData(org.apache.flink.table.data.TimestampData) MapData(org.apache.flink.table.data.MapData) StructuredType(org.apache.flink.table.types.logical.StructuredType) DecimalData(org.apache.flink.table.data.DecimalData) RowType(org.apache.flink.table.types.logical.RowType) Preconditions(org.apache.flink.util.Preconditions) Collectors(java.util.stream.Collectors) StringData(org.apache.flink.table.data.StringData) TimestampType(org.apache.flink.table.types.logical.TimestampType) ArrayData(org.apache.flink.table.data.ArrayData) List(java.util.List) DistinctType(org.apache.flink.table.types.logical.DistinctType) LogicalType(org.apache.flink.table.types.logical.LogicalType) RawValueData(org.apache.flink.table.data.RawValueData) RowField(org.apache.flink.table.types.logical.RowType.RowField) Internal(org.apache.flink.annotation.Internal) ZonedTimestampType(org.apache.flink.table.types.logical.ZonedTimestampType) RowType(org.apache.flink.table.types.logical.RowType) StructuredType(org.apache.flink.table.types.logical.StructuredType)

Aggregations

DistinctType (org.apache.flink.table.types.logical.DistinctType)6 DataType (org.apache.flink.table.types.DataType)3 FieldsDataType (org.apache.flink.table.types.FieldsDataType)3 LogicalType (org.apache.flink.table.types.logical.LogicalType)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 Internal (org.apache.flink.annotation.Internal)2 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 LocalDateTime (java.time.LocalDateTime)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 JsonParser (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser)1 DeserializationContext (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext)1 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)1 StdDeserializer (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.deser.std.StdDeserializer)1 ArrayNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode)1 DataTypes (org.apache.flink.table.api.DataTypes)1