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