Search in sources :

Example 1 with LogicalTableFunctionScan

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalTableFunctionScan in project calcite by apache.

the class EnumerableTableFunctionScanRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final RelTraitSet traitSet = rel.getTraitSet().replace(EnumerableConvention.INSTANCE);
    LogicalTableFunctionScan tbl = (LogicalTableFunctionScan) rel;
    return new EnumerableTableFunctionScan(rel.getCluster(), traitSet, tbl.getInputs(), tbl.getElementType(), tbl.getRowType(), tbl.getCall(), tbl.getColumnMappings());
}
Also used : LogicalTableFunctionScan(org.apache.calcite.rel.logical.LogicalTableFunctionScan) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 2 with LogicalTableFunctionScan

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalTableFunctionScan in project flink by apache.

the class JoinTableFunctionScanToCorrelateRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    LogicalJoin join = call.rel(0);
    RelNode leftInput = call.rel(1);
    LogicalTableFunctionScan logicalTableFunctionScan = call.rel(2);
    RelNode correlate = call.builder().push(leftInput).push(logicalTableFunctionScan).correlate(join.getJoinType(), join.getCluster().createCorrel()).build();
    call.transformTo(correlate);
}
Also used : LogicalTableFunctionScan(org.apache.calcite.rel.logical.LogicalTableFunctionScan) RelNode(org.apache.calcite.rel.RelNode) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin)

Example 3 with LogicalTableFunctionScan

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalTableFunctionScan in project hive by apache.

the class RelFieldTrimmer method trimFields.

/**
 * Variant of {@link #trimFields(RelNode, ImmutableBitSet, Set)} for
 * {@link org.apache.calcite.rel.logical.LogicalTableFunctionScan}.
 */
public TrimResult trimFields(LogicalTableFunctionScan tabFun, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
    final RelDataType rowType = tabFun.getRowType();
    final int fieldCount = rowType.getFieldCount();
    final List<RelNode> newInputs = new ArrayList<>();
    for (RelNode input : tabFun.getInputs()) {
        final int inputFieldCount = input.getRowType().getFieldCount();
        ImmutableBitSet inputFieldsUsed = ImmutableBitSet.range(inputFieldCount);
        // Create input with trimmed columns.
        final Set<RelDataTypeField> inputExtraFields = Collections.emptySet();
        TrimResult trimResult = trimChildRestore(tabFun, input, inputFieldsUsed, inputExtraFields);
        assert trimResult.right.isIdentity();
        newInputs.add(trimResult.left);
    }
    LogicalTableFunctionScan newTabFun = tabFun;
    if (!tabFun.getInputs().equals(newInputs)) {
        newTabFun = tabFun.copy(tabFun.getTraitSet(), newInputs, tabFun.getCall(), tabFun.getElementType(), tabFun.getRowType(), tabFun.getColumnMappings());
    }
    assert newTabFun.getClass() == tabFun.getClass();
    // Always project all fields.
    Mapping mapping = Mappings.createIdentity(fieldCount);
    return result(newTabFun, mapping);
}
Also used : LogicalTableFunctionScan(org.apache.calcite.rel.logical.LogicalTableFunctionScan) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelNode(org.apache.calcite.rel.RelNode) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) Mapping(org.apache.calcite.util.mapping.Mapping)

Example 4 with LogicalTableFunctionScan

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalTableFunctionScan in project calcite by apache.

the class FilterTableFunctionTransposeRule method onMatch.

// ~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
    LogicalFilter filter = call.rel(0);
    LogicalTableFunctionScan funcRel = call.rel(1);
    Set<RelColumnMapping> columnMappings = funcRel.getColumnMappings();
    if (columnMappings == null || columnMappings.isEmpty()) {
        // possible.
        return;
    }
    List<RelNode> funcInputs = funcRel.getInputs();
    if (funcInputs.size() != 1) {
        // offsetting field indices, similar to join
        return;
    }
    // TODO:  support mappings other than 1-to-1
    if (funcRel.getRowType().getFieldCount() != funcInputs.get(0).getRowType().getFieldCount()) {
        return;
    }
    for (RelColumnMapping mapping : columnMappings) {
        if (mapping.iInputColumn != mapping.iOutputColumn) {
            return;
        }
        if (mapping.derived) {
            return;
        }
    }
    final List<RelNode> newFuncInputs = new ArrayList<RelNode>();
    final RelOptCluster cluster = funcRel.getCluster();
    final RexNode condition = filter.getCondition();
    // create filters on top of each func input, modifying the filter
    // condition to reference the child instead
    RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
    List<RelDataTypeField> origFields = funcRel.getRowType().getFieldList();
    // TODO:  these need to be non-zero once we
    // support arbitrary mappings
    int[] adjustments = new int[origFields.size()];
    for (RelNode funcInput : funcInputs) {
        RexNode newCondition = condition.accept(new RelOptUtil.RexInputConverter(rexBuilder, origFields, funcInput.getRowType().getFieldList(), adjustments));
        newFuncInputs.add(LogicalFilter.create(funcInput, newCondition));
    }
    // create a new UDX whose children are the filters created above
    LogicalTableFunctionScan newFuncRel = LogicalTableFunctionScan.create(cluster, newFuncInputs, funcRel.getCall(), funcRel.getElementType(), funcRel.getRowType(), columnMappings);
    call.transformTo(newFuncRel);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter) RelOptUtil(org.apache.calcite.plan.RelOptUtil) ArrayList(java.util.ArrayList) LogicalTableFunctionScan(org.apache.calcite.rel.logical.LogicalTableFunctionScan) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelNode(org.apache.calcite.rel.RelNode) RexBuilder(org.apache.calcite.rex.RexBuilder) RelColumnMapping(org.apache.calcite.rel.metadata.RelColumnMapping) RexNode(org.apache.calcite.rex.RexNode)

Example 5 with LogicalTableFunctionScan

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalTableFunctionScan in project flink by apache.

the class ProjectWindowTableFunctionTransposeRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    LogicalProject project = call.rel(0);
    LogicalTableFunctionScan scan = call.rel(1);
    RelNode scanInput = scan.getInput(0);
    TimeAttributeWindowingStrategy windowingStrategy = WindowUtil.convertToWindowingStrategy((RexCall) scan.getCall(), scanInput.getRowType());
    // 1. get fields to push down
    ImmutableBitSet projectFields = RelOptUtil.InputFinder.bits(project.getProjects(), null);
    int scanInputFieldCount = scanInput.getRowType().getFieldCount();
    ImmutableBitSet toPushFields = ImmutableBitSet.range(0, scanInputFieldCount).intersect(projectFields).set(windowingStrategy.getTimeAttributeIndex());
    if (toPushFields.cardinality() == scanInputFieldCount) {
        return;
    }
    // 2. create new input of window table function scan
    RelBuilder relBuilder = call.builder();
    RelNode newScanInput = createInnerProject(relBuilder, scanInput, toPushFields);
    // mapping origin field index to new field index, used to rewrite WindowTableFunction and
    // top project
    Map<Integer, Integer> mapping = getFieldMapping(scan.getRowType().getFieldCount(), scanInputFieldCount, toPushFields);
    // 3. create new window table function scan
    LogicalTableFunctionScan newScan = createNewTableFunctionScan(relBuilder, scan, windowingStrategy.getTimeAttributeType(), newScanInput, mapping);
    // 4. create top project
    RelNode topProject = createTopProject(relBuilder, project, newScan, mapping);
    call.transformTo(topProject);
}
Also used : LogicalTableFunctionScan(org.apache.calcite.rel.logical.LogicalTableFunctionScan) RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) TimeAttributeWindowingStrategy(org.apache.flink.table.planner.plan.logical.TimeAttributeWindowingStrategy) LogicalProject(org.apache.calcite.rel.logical.LogicalProject)

Aggregations

LogicalTableFunctionScan (org.apache.calcite.rel.logical.LogicalTableFunctionScan)7 RelNode (org.apache.calcite.rel.RelNode)6 ArrayList (java.util.ArrayList)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)3 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)3 RelColumnMapping (org.apache.calcite.rel.metadata.RelColumnMapping)2 RexNode (org.apache.calcite.rex.RexNode)2 Mapping (org.apache.calcite.util.mapping.Mapping)2 Type (java.lang.reflect.Type)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 JoinRelType (org.apache.calcite.rel.core.JoinRelType)1 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)1 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)1 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 TranslatableTable (org.apache.calcite.schema.TranslatableTable)1