Search in sources :

Example 21 with Union

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union in project druid by apache.

the class DruidUnionDataSourceRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    final Union unionRel = call.rel(0);
    final DruidRel<?> firstDruidRel = call.rel(1);
    final DruidQueryRel secondDruidRel = call.rel(2);
    return isCompatible(unionRel, firstDruidRel, secondDruidRel, plannerContext);
}
Also used : DruidQueryRel(org.apache.druid.sql.calcite.rel.DruidQueryRel) Union(org.apache.calcite.rel.core.Union)

Example 22 with Union

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union in project druid by apache.

the class DruidUnionDataSourceRule method onMatch.

@Override
public void onMatch(final RelOptRuleCall call) {
    final Union unionRel = call.rel(0);
    final DruidRel<?> firstDruidRel = call.rel(1);
    final DruidQueryRel secondDruidRel = call.rel(2);
    if (firstDruidRel instanceof DruidUnionDataSourceRel) {
        // Unwrap and flatten the inputs to the Union.
        final RelNode newUnionRel = call.builder().pushAll(firstDruidRel.getInputs()).push(secondDruidRel).union(true, firstDruidRel.getInputs().size() + 1).build();
        call.transformTo(DruidUnionDataSourceRel.create((Union) newUnionRel, getColumnNamesIfTableOrUnion(firstDruidRel, plannerContext).get(), firstDruidRel.getPlannerContext()));
    } else {
        // Sanity check.
        if (!(firstDruidRel instanceof DruidQueryRel)) {
            throw new ISE("Expected first rel to be a DruidQueryRel, but it was %s", firstDruidRel.getClass().getName());
        }
        call.transformTo(DruidUnionDataSourceRel.create(unionRel, getColumnNamesIfTableOrUnion(firstDruidRel, plannerContext).get(), firstDruidRel.getPlannerContext()));
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) DruidQueryRel(org.apache.druid.sql.calcite.rel.DruidQueryRel) ISE(org.apache.druid.java.util.common.ISE) DruidUnionDataSourceRel(org.apache.druid.sql.calcite.rel.DruidUnionDataSourceRel) Union(org.apache.calcite.rel.core.Union)

Example 23 with Union

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union in project kylin by apache.

the class OLAPUnionRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final Union union = (Union) rel;
    final RelTraitSet traitSet = union.getTraitSet().replace(OLAPRel.CONVENTION);
    final List<RelNode> inputs = union.getInputs();
    return new OLAPUnionRel(rel.getCluster(), traitSet, convertList(inputs, OLAPRel.CONVENTION), union.all);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet) OLAPUnionRel(org.apache.kylin.query.relnode.OLAPUnionRel) Union(org.apache.calcite.rel.core.Union)

Example 24 with Union

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union in project hive by apache.

the class HiveJoinInsertIncrementalRewritingRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final Union union = call.rel(0);
    // First branch is query, second branch is MV
    RelNode newNode = call.builder().push(union.getInput(0)).convert(union.getRowType(), false).build();
    call.transformTo(newNode);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Union(org.apache.calcite.rel.core.Union)

Example 25 with Union

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union in project hive by apache.

the class HiveAggregatePartitionIncrementalRewritingRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    RexBuilder rexBuilder = call.builder().getRexBuilder();
    final Aggregate aggregate = call.rel(0);
    final Union union = call.rel(1);
    final RelNode queryBranch = union.getInput(0);
    final RelNode mvBranch = union.getInput(1);
    // find Partition col indexes in mvBranch top operator row schema
    // mvBranch can be more complex than just a TS on the MV and the partition columns indexes in the top Operator's
    // row schema may differ from the one in the TS row schema. Example:
    // Project($2, $0, $1)
    // TableScan(table=materialized_view1, schema=a, b, part_col)
    RelMetadataQuery relMetadataQuery = RelMetadataQuery.instance();
    int partitionColumnCount = -1;
    List<Integer> partitionColumnIndexes = new ArrayList<>();
    for (int i = 0; i < mvBranch.getRowType().getFieldList().size(); ++i) {
        RelDataTypeField relDataTypeField = mvBranch.getRowType().getFieldList().get(i);
        RexInputRef inputRef = rexBuilder.makeInputRef(relDataTypeField.getType(), i);
        Set<RexNode> expressionLineage = relMetadataQuery.getExpressionLineage(mvBranch, inputRef);
        if (expressionLineage == null || expressionLineage.size() != 1) {
            continue;
        }
        Set<RexTableInputRef> tableInputRefs = findRexTableInputRefs(expressionLineage.iterator().next());
        if (tableInputRefs.size() != 1) {
            continue;
        }
        RexTableInputRef tableInputRef = tableInputRefs.iterator().next();
        RelOptHiveTable relOptHiveTable = (RelOptHiveTable) tableInputRef.getTableRef().getTable();
        if (!(relOptHiveTable.getHiveTableMD().isMaterializedView())) {
            LOG.warn("{} is not a materialized view, bail out.", relOptHiveTable.getQualifiedName());
            return;
        }
        partitionColumnCount = relOptHiveTable.getPartColInfoMap().size();
        if (relOptHiveTable.getPartColInfoMap().containsKey(tableInputRef.getIndex())) {
            partitionColumnIndexes.add(i);
        }
    }
    if (partitionColumnCount <= 0 || partitionColumnIndexes.size() != partitionColumnCount) {
        LOG.debug("Could not find all partition column lineages, bail out.");
        return;
    }
    List<RexNode> joinConjs = new ArrayList<>();
    for (int partColIndex : partitionColumnIndexes) {
        RexNode leftRef = rexBuilder.makeInputRef(mvBranch.getRowType().getFieldList().get(partColIndex).getType(), partColIndex);
        RexNode rightRef = rexBuilder.makeInputRef(queryBranch.getRowType().getFieldList().get(partColIndex).getType(), partColIndex + mvBranch.getRowType().getFieldCount());
        joinConjs.add(rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM, leftRef, rightRef));
    }
    RexNode joinCond = RexUtil.composeConjunction(rexBuilder, joinConjs);
    RelBuilder builder = call.builder();
    RelNode newNode = builder.push(mvBranch).push(queryBranch).join(JoinRelType.SEMI, joinCond).push(queryBranch).union(union.all).aggregate(builder.groupKey(aggregate.getGroupSet()), aggregate.getAggCallList()).build();
    call.transformTo(newNode);
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelBuilder(org.apache.calcite.tools.RelBuilder) ArrayList(java.util.ArrayList) RexTableInputRef(org.apache.calcite.rex.RexTableInputRef) Union(org.apache.calcite.rel.core.Union) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelOptHiveTable(org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable) RelNode(org.apache.calcite.rel.RelNode) RexBuilder(org.apache.calcite.rex.RexBuilder) RexInputRef(org.apache.calcite.rex.RexInputRef) Aggregate(org.apache.calcite.rel.core.Aggregate) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

Union (org.apache.calcite.rel.core.Union)41 RelNode (org.apache.calcite.rel.RelNode)28 Aggregate (org.apache.calcite.rel.core.Aggregate)15 Sort (org.apache.calcite.rel.core.Sort)13 ArrayList (java.util.ArrayList)12 RexNode (org.apache.calcite.rex.RexNode)12 Join (org.apache.calcite.rel.core.Join)11 Filter (org.apache.calcite.rel.core.Filter)10 Project (org.apache.calcite.rel.core.Project)10 RelBuilder (org.apache.calcite.tools.RelBuilder)10 TableScan (org.apache.calcite.rel.core.TableScan)9 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)9 RexBuilder (org.apache.calcite.rex.RexBuilder)9 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)9 Intersect (org.apache.calcite.rel.core.Intersect)8 Minus (org.apache.calcite.rel.core.Minus)8 Correlate (org.apache.calcite.rel.core.Correlate)7 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)7 Map (java.util.Map)6 Calc (org.apache.calcite.rel.core.Calc)6