use of org.apache.flink.table.catalog.Column.ComputedColumn in project flink by apache.
the class DynamicSourceUtils method pushGeneratedProjection.
/**
* Creates a projection that adds computed columns and finalizes the table schema.
*/
private static void pushGeneratedProjection(FlinkRelBuilder relBuilder, ResolvedSchema schema) {
final ExpressionConverter converter = new ExpressionConverter(relBuilder);
final List<RexNode> projection = schema.getColumns().stream().map(c -> {
if (c instanceof ComputedColumn) {
final ComputedColumn computedColumn = (ComputedColumn) c;
return computedColumn.getExpression().accept(converter);
} else {
return relBuilder.field(c.getName());
}
}).collect(Collectors.toList());
relBuilder.projectNamed(projection, schema.getColumns().stream().map(Column::getName).collect(Collectors.toList()), true);
}
use of org.apache.flink.table.catalog.Column.ComputedColumn in project flink by apache.
the class DynamicSourceUtils method pushMetadataProjection.
/**
* Creates a projection that reorders physical and metadata columns according to the given
* schema. It casts metadata columns into the expected data type to be accessed by computed
* columns in the next step. Computed columns are ignored here.
*
* @see SupportsReadingMetadata
*/
private static void pushMetadataProjection(FlinkRelBuilder relBuilder, ResolvedSchema schema) {
final RexBuilder rexBuilder = relBuilder.getRexBuilder();
final List<String> fieldNames = schema.getColumns().stream().filter(c -> !(c instanceof ComputedColumn)).map(Column::getName).collect(Collectors.toList());
final List<RexNode> fieldNodes = schema.getColumns().stream().filter(c -> !(c instanceof ComputedColumn)).map(c -> {
final RelDataType relDataType = relBuilder.getTypeFactory().createFieldTypeFromLogicalType(c.getDataType().getLogicalType());
if (c instanceof MetadataColumn) {
final MetadataColumn metadataColumn = (MetadataColumn) c;
final String metadataKey = metadataColumn.getMetadataKey().orElse(metadataColumn.getName());
return rexBuilder.makeAbstractCast(relDataType, relBuilder.field(metadataKey));
} else {
return relBuilder.field(c.getName());
}
}).collect(Collectors.toList());
relBuilder.projectNamed(fieldNodes, fieldNames, true);
}
Aggregations