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