use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union in project Mycat2 by MyCATApache.
the class RelMdUniqueKeys method getProjectUniqueKeys.
private static Set<ImmutableBitSet> getProjectUniqueKeys(SingleRel rel, RelMetadataQuery mq, boolean ignoreNulls, List<RexNode> projExprs) {
// LogicalProject maps a set of rows to a different set;
// Without knowledge of the mapping function(whether it
// preserves uniqueness), it is only safe to derive uniqueness
// info from the child of a project when the mapping is f(a) => a.
//
// Further more, the unique bitset coming from the child needs
// to be mapped to match the output of the project.
// Single input can be mapped to multiple outputs
ImmutableMultimap.Builder<Integer, Integer> inToOutPosBuilder = ImmutableMultimap.builder();
ImmutableBitSet.Builder mappedInColumnsBuilder = ImmutableBitSet.builder();
// Build an input to output position map.
for (int i = 0; i < projExprs.size(); i++) {
RexNode projExpr = projExprs.get(i);
if (projExpr instanceof RexInputRef) {
int inputIndex = ((RexInputRef) projExpr).getIndex();
inToOutPosBuilder.put(inputIndex, i);
mappedInColumnsBuilder.set(inputIndex);
}
}
ImmutableBitSet inColumnsUsed = mappedInColumnsBuilder.build();
if (inColumnsUsed.isEmpty()) {
// return empty set.
return ImmutableSet.of();
}
Set<ImmutableBitSet> childUniqueKeySet = mq.getUniqueKeys(rel.getInput(), ignoreNulls);
if (childUniqueKeySet == null) {
return ImmutableSet.of();
}
Map<Integer, ImmutableBitSet> mapInToOutPos = Maps.transformValues(inToOutPosBuilder.build().asMap(), ImmutableBitSet::of);
ImmutableSet.Builder<ImmutableBitSet> resultBuilder = ImmutableSet.builder();
// projected.
for (ImmutableBitSet colMask : childUniqueKeySet) {
if (!inColumnsUsed.contains(colMask)) {
// colMask contains a column that is not projected as RexInput => the key is not unique
continue;
}
// colMask is mapped to output project, however, the column can be mapped more than once:
// select id, id, id, unique2, unique2
// the resulting unique keys would be {{0},{3}}, {{0},{4}}, {{0},{1},{4}}, ...
Iterable<List<ImmutableBitSet>> product = Linq4j.product(Util.transform(colMask, in -> Util.filter(requireNonNull(mapInToOutPos.get(in), () -> "no entry for column " + in + " in mapInToOutPos: " + mapInToOutPos).powerSet(), bs -> !bs.isEmpty())));
resultBuilder.addAll(Util.transform(product, ImmutableBitSet::union));
}
return resultBuilder.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union in project Mycat2 by MyCATApache.
the class MycatUnionRule method convert.
public RelNode convert(RelNode rel) {
final Union union = (Union) rel;
final RelTraitSet traitSet = union.getTraitSet().replace(out);
return MycatUnion.create(traitSet, convertList(union.getInputs(), out), union.all);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union in project ignite-3 by apache.
the class UnionPlannerTest method testUnion.
@Test
public void testUnion() throws Exception {
IgniteSchema publicSchema = prepareSchema();
String sql = "" + "SELECT * FROM table1 " + "UNION " + "SELECT * FROM table2 " + "UNION " + "SELECT * FROM table3 ";
assertPlan(sql, publicSchema, isInstanceOf(IgniteReduceAggregateBase.class).and(hasChildThat(isInstanceOf(Union.class))));
assertPlan(sql, publicSchema, isInstanceOf(IgniteReduceAggregateBase.class).and(hasChildThat(isInstanceOf(Union.class).and(input(0, isTableScan("TABLE1"))).and(input(1, isTableScan("TABLE2"))).and(input(2, isTableScan("TABLE3"))))));
}
Aggregations