Search in sources :

Example 1 with ExpressionConverter

use of org.apache.flink.table.planner.expressions.converter.ExpressionConverter 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);
}
Also used : DataType(org.apache.flink.table.types.DataType) ScanRuntimeProvider(org.apache.flink.table.connector.source.ScanTableSource.ScanRuntimeProvider) ChangelogMode(org.apache.flink.table.connector.ChangelogMode) Column(org.apache.flink.table.catalog.Column) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) ShortcutUtils(org.apache.flink.table.planner.utils.ShortcutUtils) RowType(org.apache.flink.table.types.logical.RowType) ScanTableSource(org.apache.flink.table.connector.source.ScanTableSource) FlinkRelBuilder(org.apache.flink.table.planner.calcite.FlinkRelBuilder) MetadataColumn(org.apache.flink.table.catalog.Column.MetadataColumn) ReadableConfig(org.apache.flink.configuration.ReadableConfig) RexNode(org.apache.calcite.rex.RexNode) RowField(org.apache.flink.table.types.logical.RowType.RowField) RelHint(org.apache.calcite.rel.hint.RelHint) Map(java.util.Map) LogicalTypeCasts.supportsExplicitCast(org.apache.flink.table.types.logical.utils.LogicalTypeCasts.supportsExplicitCast) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) ContextResolvedTable(org.apache.flink.table.catalog.ContextResolvedTable) RelDataType(org.apache.calcite.rel.type.RelDataType) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) TableConfig(org.apache.flink.table.api.TableConfig) WatermarkSpec(org.apache.flink.table.catalog.WatermarkSpec) RexBuilder(org.apache.calcite.rex.RexBuilder) TableException(org.apache.flink.table.api.TableException) Set(java.util.Set) ExpressionConverter(org.apache.flink.table.planner.expressions.converter.ExpressionConverter) RelNode(org.apache.calcite.rel.RelNode) Collectors(java.util.stream.Collectors) SourceAbilitySpec(org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) ComputedColumn(org.apache.flink.table.catalog.Column.ComputedColumn) DataStream(org.apache.flink.streaming.api.datastream.DataStream) List(java.util.List) Stream(java.util.stream.Stream) LogicalType(org.apache.flink.table.types.logical.LogicalType) FlinkStatistic(org.apache.flink.table.planner.plan.stats.FlinkStatistic) RowKind(org.apache.flink.types.RowKind) ValidationException(org.apache.flink.table.api.ValidationException) SupportsReadingMetadata(org.apache.flink.table.connector.source.abilities.SupportsReadingMetadata) Internal(org.apache.flink.annotation.Internal) TypeConversions(org.apache.flink.table.types.utils.TypeConversions) ExecutionConfigOptions(org.apache.flink.table.api.config.ExecutionConfigOptions) Collections(java.util.Collections) ScanRuntimeProviderContext(org.apache.flink.table.runtime.connector.source.ScanRuntimeProviderContext) LogicalTableScan(org.apache.calcite.rel.logical.LogicalTableScan) Column(org.apache.flink.table.catalog.Column) MetadataColumn(org.apache.flink.table.catalog.Column.MetadataColumn) ComputedColumn(org.apache.flink.table.catalog.Column.ComputedColumn) ExpressionConverter(org.apache.flink.table.planner.expressions.converter.ExpressionConverter) ComputedColumn(org.apache.flink.table.catalog.Column.ComputedColumn) RexNode(org.apache.calcite.rex.RexNode)

Example 2 with ExpressionConverter

use of org.apache.flink.table.planner.expressions.converter.ExpressionConverter in project flink by apache.

the class DynamicSourceUtils method pushWatermarkAssigner.

// --------------------------------------------------------------------------------------------
/**
 * Creates a specialized node for assigning watermarks.
 */
private static void pushWatermarkAssigner(FlinkRelBuilder relBuilder, ResolvedSchema schema) {
    final ExpressionConverter converter = new ExpressionConverter(relBuilder);
    final RelDataType inputRelDataType = relBuilder.peek().getRowType();
    // schema resolver has checked before that only one spec exists
    final WatermarkSpec watermarkSpec = schema.getWatermarkSpecs().get(0);
    final String rowtimeColumn = watermarkSpec.getRowtimeAttribute();
    final int rowtimeColumnIdx = inputRelDataType.getFieldNames().indexOf(rowtimeColumn);
    final RexNode watermarkRexNode = watermarkSpec.getWatermarkExpression().accept(converter);
    relBuilder.watermark(rowtimeColumnIdx, watermarkRexNode);
}
Also used : WatermarkSpec(org.apache.flink.table.catalog.WatermarkSpec) ExpressionConverter(org.apache.flink.table.planner.expressions.converter.ExpressionConverter) RelDataType(org.apache.calcite.rel.type.RelDataType) RelHint(org.apache.calcite.rel.hint.RelHint) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

RelHint (org.apache.calcite.rel.hint.RelHint)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 RexNode (org.apache.calcite.rex.RexNode)2 WatermarkSpec (org.apache.flink.table.catalog.WatermarkSpec)2 ExpressionConverter (org.apache.flink.table.planner.expressions.converter.ExpressionConverter)2 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 RelNode (org.apache.calcite.rel.RelNode)1 LogicalTableScan (org.apache.calcite.rel.logical.LogicalTableScan)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 Internal (org.apache.flink.annotation.Internal)1 ReadableConfig (org.apache.flink.configuration.ReadableConfig)1 DataStream (org.apache.flink.streaming.api.datastream.DataStream)1 TableConfig (org.apache.flink.table.api.TableConfig)1 TableException (org.apache.flink.table.api.TableException)1 ValidationException (org.apache.flink.table.api.ValidationException)1