Search in sources :

Example 6 with RowField

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

Example 7 with RowField

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

the class DynamicSourceUtils method createProducedType.

/**
 * Returns the {@link DataType} that a source should produce as the input into the runtime.
 *
 * <p>The format looks as follows: {@code PHYSICAL COLUMNS + METADATA COLUMNS}
 *
 * <p>Physical columns use the table schema's name. Metadata column use the metadata key as
 * name.
 */
public static RowType createProducedType(ResolvedSchema schema, DynamicTableSource source) {
    final Map<String, DataType> metadataMap = extractMetadataMap(source);
    final Stream<RowField> physicalFields = ((RowType) schema.toPhysicalRowDataType().getLogicalType()).getFields().stream();
    final Stream<RowField> metadataFields = createRequiredMetadataKeys(schema, source).stream().map(k -> new RowField(k, metadataMap.get(k).getLogicalType()));
    final List<RowField> rowFields = Stream.concat(physicalFields, metadataFields).collect(Collectors.toList());
    return new RowType(false, rowFields);
}
Also used : RowField(org.apache.flink.table.types.logical.RowType.RowField) DataType(org.apache.flink.table.types.DataType) RelDataType(org.apache.calcite.rel.type.RelDataType) RowType(org.apache.flink.table.types.logical.RowType)

Aggregations

RowType (org.apache.flink.table.types.logical.RowType)7 RowField (org.apache.flink.table.types.logical.RowType.RowField)7 LogicalType (org.apache.flink.table.types.logical.LogicalType)5 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 DataType (org.apache.flink.table.types.DataType)3 LocalZonedTimestampType (org.apache.flink.table.types.logical.LocalZonedTimestampType)3 StructuredType (org.apache.flink.table.types.logical.StructuredType)3 TimestampType (org.apache.flink.table.types.logical.TimestampType)3 ZonedTimestampType (org.apache.flink.table.types.logical.ZonedTimestampType)3 Preconditions (org.apache.flink.util.Preconditions)3 Internal (org.apache.flink.annotation.Internal)2 ArrayData (org.apache.flink.table.data.ArrayData)2 DecimalData (org.apache.flink.table.data.DecimalData)2 MapData (org.apache.flink.table.data.MapData)2 RawValueData (org.apache.flink.table.data.RawValueData)2 RowData (org.apache.flink.table.data.RowData)2 StringData (org.apache.flink.table.data.StringData)2