Java Code Examples for org.apache.calcite.rel.logical.LogicalJoin#getVariablesSet()

The following examples show how to use org.apache.calcite.rel.logical.LogicalJoin#getVariablesSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyWithCluster.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public RelNode visit(LogicalJoin join) {
  // to the best of my knowledge join.systemFieldList is always empty
  Preconditions.checkState(join.getSystemFieldList().isEmpty(), "join.systemFieldList is not empty!");

  final RelNode left = join.getLeft().accept(this);
  final RelNode right = join.getRight().accept(this);

  return new LogicalJoin(
    cluster,
    copyOf(join.getTraitSet()),
    left,
    right,
    copyOf(join.getCondition()),
    join.getVariablesSet(),
    join.getJoinType(),
    join.isSemiJoinDone(),
    ImmutableList.<RelDataTypeField>of()
  );
}
 
Example 2
Source File: Bindables.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode rel) {
  final LogicalJoin join = (LogicalJoin) rel;
  final BindableConvention out = BindableConvention.INSTANCE;
  final RelTraitSet traitSet = join.getTraitSet().replace(out);
  return new BindableJoin(rel.getCluster(), traitSet,
      convert(join.getLeft(),
          join.getLeft().getTraitSet()
              .replace(BindableConvention.INSTANCE)),
      convert(join.getRight(),
          join.getRight().getTraitSet()
              .replace(BindableConvention.INSTANCE)),
      join.getCondition(), join.getVariablesSet(), join.getJoinType());
}
 
Example 3
Source File: EnumerableMergeJoinRule.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public RelNode convert(RelNode rel) {
  LogicalJoin join = (LogicalJoin) rel;
  final JoinInfo info = join.analyzeCondition();
  if (!EnumerableMergeJoin.isMergeJoinSupported(join.getJoinType())) {
    // EnumerableMergeJoin only supports certain join types.
    return null;
  }
  if (info.pairs().size() == 0) {
    // EnumerableMergeJoin CAN support cartesian join, but disable it for now.
    return null;
  }
  final List<RelNode> newInputs = new ArrayList<>();
  final List<RelCollation> collations = new ArrayList<>();
  int offset = 0;
  for (Ord<RelNode> ord : Ord.zip(join.getInputs())) {
    RelTraitSet traits = ord.e.getTraitSet()
        .replace(EnumerableConvention.INSTANCE);
    if (!info.pairs().isEmpty()) {
      final List<RelFieldCollation> fieldCollations = new ArrayList<>();
      for (int key : info.keys().get(ord.i)) {
        fieldCollations.add(
            new RelFieldCollation(key, RelFieldCollation.Direction.ASCENDING,
                RelFieldCollation.NullDirection.LAST));
      }
      final RelCollation collation = RelCollations.of(fieldCollations);
      collations.add(RelCollations.shift(collation, offset));
      traits = traits.replace(collation);
    }
    newInputs.add(convert(ord.e, traits));
    offset += ord.e.getRowType().getFieldCount();
  }
  final RelNode left = newInputs.get(0);
  final RelNode right = newInputs.get(1);
  final RelOptCluster cluster = join.getCluster();
  RelNode newRel;

  RelTraitSet traitSet = join.getTraitSet()
      .replace(EnumerableConvention.INSTANCE);
  if (!collations.isEmpty()) {
    traitSet = traitSet.replace(collations);
  }
  // Re-arrange condition: first the equi-join elements, then the non-equi-join ones (if any);
  // this is not strictly necessary but it will be useful to avoid spurious errors in the
  // unit tests when verifying the plan.
  final RexBuilder rexBuilder = join.getCluster().getRexBuilder();
  final RexNode equi = info.getEquiCondition(left, right, rexBuilder);
  final RexNode condition;
  if (info.isEqui()) {
    condition = equi;
  } else {
    final RexNode nonEqui = RexUtil.composeConjunction(rexBuilder, info.nonEquiConditions);
    condition = RexUtil.composeConjunction(rexBuilder, Arrays.asList(equi, nonEqui));
  }
  newRel = new EnumerableMergeJoin(cluster,
      traitSet,
      left,
      right,
      condition,
      join.getVariablesSet(),
      join.getJoinType());
  return newRel;
}