org.apache.calcite.rel.logical.LogicalJoin Java Examples

The following examples show how to use org.apache.calcite.rel.logical.LogicalJoin. 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: FlinkSemiAntiJoinProjectTransposeRule.java    From flink with Apache License 2.0 6 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
	LogicalJoin join = call.rel(0);
	LogicalProject project = call.rel(1);

	// convert the semi/anti join condition to reflect the LHS with the project
	// pulled up
	RexNode newCondition = adjustCondition(project, join);
	Join newJoin = LogicalJoin.create(
			project.getInput(), join.getRight(), newCondition, join.getVariablesSet(), join.getJoinType());

	// Create the new projection. Note that the projection expressions
	// are the same as the original because they only reference the LHS
	// of the semi/anti join and the semi/anti join only projects out the LHS
	final RelBuilder relBuilder = call.builder();
	relBuilder.push(newJoin);
	relBuilder.project(project.getProjects(), project.getRowType().getFieldNames());

	call.transformTo(relBuilder.build());
}
 
Example #2
Source File: Lattice.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static boolean populate(List<RelNode> nodes, List<int[][]> tempLinks,
    RelNode rel) {
  if (nodes.isEmpty() && rel instanceof LogicalProject) {
    return populate(nodes, tempLinks, ((LogicalProject) rel).getInput());
  }
  if (rel instanceof TableScan) {
    nodes.add(rel);
    return true;
  }
  if (rel instanceof LogicalJoin) {
    LogicalJoin join = (LogicalJoin) rel;
    if (join.getJoinType().isOuterJoin()) {
      throw new RuntimeException("only non nulls-generating join allowed, but got "
          + join.getJoinType());
    }
    populate(nodes, tempLinks, join.getLeft());
    populate(nodes, tempLinks, join.getRight());
    for (RexNode rex : RelOptUtil.conjunctions(join.getCondition())) {
      tempLinks.add(grab(nodes, rex));
    }
    return true;
  }
  throw new RuntimeException("Invalid node type "
      + rel.getClass().getSimpleName() + " in lattice query");
}
 
Example #3
Source File: RexTransformerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-833">[CALCITE-833]
 * RelOptUtil.splitJoinCondition attempts to split a Join-Condition which
 * has a remaining condition</a>. */
@Test void testSplitJoinCondition() {
  final String sql = "select *\n"
      + "from emp a\n"
      + "INNER JOIN dept b\n"
      + "ON CAST(a.empno AS int) <> b.deptno";

  final RelNode relNode = toRel(sql);
  final LogicalProject project = (LogicalProject) relNode;
  final LogicalJoin join = (LogicalJoin) project.getInput(0);
  final List<RexNode> leftJoinKeys = new ArrayList<>();
  final List<RexNode> rightJoinKeys = new ArrayList<>();
  final ArrayList<RelDataTypeField> sysFieldList = new ArrayList<>();
  final RexNode remaining = RelOptUtil.splitJoinCondition(sysFieldList,
      join.getInputs().get(0),
      join.getInputs().get(1),
      join.getCondition(),
      leftJoinKeys,
      rightJoinKeys,
      null,
      null);

  assertThat(remaining.toString(), is("<>($0, $9)"));
  assertThat(leftJoinKeys.isEmpty(), is(true));
  assertThat(rightJoinKeys.isEmpty(), is(true));
}
 
Example #4
Source File: StreamRules.java    From Bats with Apache License 2.0 6 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  final Delta delta = call.rel(0);
  Util.discard(delta);
  final Join join = call.rel(1);
  final RelNode left = join.getLeft();
  final RelNode right = join.getRight();

  final LogicalDelta rightWithDelta = LogicalDelta.create(right);
  final LogicalJoin joinL = LogicalJoin.create(left, rightWithDelta,
      join.getCondition(), join.getVariablesSet(), join.getJoinType(),
      join.isSemiJoinDone(),
      ImmutableList.copyOf(join.getSystemFieldList()));

  final LogicalDelta leftWithDelta = LogicalDelta.create(left);
  final LogicalJoin joinR = LogicalJoin.create(leftWithDelta, right,
      join.getCondition(), join.getVariablesSet(), join.getJoinType(),
      join.isSemiJoinDone(),
      ImmutableList.copyOf(join.getSystemFieldList()));

  List<RelNode> inputsToUnion = new ArrayList<>();
  inputsToUnion.add(joinL);
  inputsToUnion.add(joinR);

  final LogicalUnion newNode = LogicalUnion.create(inputsToUnion, true);
  call.transformTo(newNode);
}
 
Example #5
Source File: PigRelOpVisitor.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public void visit(LOJoin join) throws FrontendException {
  joinInternal(join.getExpressionPlans(), join.getInnerFlags());
  LogicalJoin joinRel = (LogicalJoin) builder.peek();
  Set<String> duplicateNames = new HashSet<>(joinRel.getLeft().getRowType().getFieldNames());
  duplicateNames.retainAll(joinRel.getRight().getRowType().getFieldNames());
  if (!duplicateNames.isEmpty()) {
    final List<String> fieldNames = new ArrayList<>();
    final List<RexNode> fields = new ArrayList<>();
    for (RelDataTypeField leftField : joinRel.getLeft().getRowType().getFieldList()) {
      fieldNames.add(builder.getAlias(joinRel.getLeft()) + "::" + leftField.getName());
      fields.add(builder.field(leftField.getIndex()));
    }
    int leftCount = joinRel.getLeft().getRowType().getFieldList().size();
    for (RelDataTypeField rightField : joinRel.getRight().getRowType().getFieldList()) {
      fieldNames.add(builder.getAlias(joinRel.getRight()) + "::" + rightField.getName());
      fields.add(builder.field(rightField.getIndex() + leftCount));
    }
    builder.project(fields, fieldNames);
  }
  builder.register(join);
}
 
Example #6
Source File: FlinkSemiAntiJoinProjectTransposeRule.java    From flink with Apache License 2.0 6 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
	LogicalJoin join = call.rel(0);
	LogicalProject project = call.rel(1);

	// convert the semi/anti join condition to reflect the LHS with the project
	// pulled up
	RexNode newCondition = adjustCondition(project, join);
	Join newJoin = LogicalJoin.create(
			project.getInput(), join.getRight(), newCondition, join.getVariablesSet(), join.getJoinType());

	// Create the new projection. Note that the projection expressions
	// are the same as the original because they only reference the LHS
	// of the semi/anti join and the semi/anti join only projects out the LHS
	final RelBuilder relBuilder = call.builder();
	relBuilder.push(newJoin);
	relBuilder.project(project.getProjects(), project.getRowType().getFieldNames());

	call.transformTo(relBuilder.build());
}
 
Example #7
Source File: FlinkSemiAntiJoinProjectTransposeRule.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(RelOptRuleCall call) {
	LogicalJoin join = call.rel(0);
	LogicalProject project = call.rel(1);

	// only accept SEMI/ANTI join
	JoinRelType joinType = join.getJoinType();
	if (joinType != JoinRelType.SEMI && joinType != JoinRelType.ANTI) {
		return false;
	}
	// all expressions in Project should be RexInputRef
	for (RexNode p : project.getProjects()) {
		if (!(p instanceof RexInputRef)) {
			return false;
		}
	}
	return true;
}
 
Example #8
Source File: FlinkSemiAntiJoinFilterTransposeRule.java    From flink with Apache License 2.0 6 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
	LogicalJoin join = call.rel(0);
	LogicalFilter filter = call.rel(1);

	RelNode newJoin = LogicalJoin.create(
			filter.getInput(),
			join.getRight(),
			join.getCondition(),
			join.getVariablesSet(),
			join.getJoinType());

	final RelFactories.FilterFactory factory =
			RelFactories.DEFAULT_FILTER_FACTORY;
	RelNode newFilter =
			factory.createFilter(newJoin, filter.getCondition());

	call.transformTo(newFilter);
}
 
Example #9
Source File: CompositeFilterJoinRule.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void onMatch(RelOptRuleCall call) {

  RelNode result = doMatch(call);

  if (result == null) {
    return;
  }

  call.transformTo(result.accept(new RelShuttleImpl() {
    @Override
    public RelNode visit(LogicalJoin join) {
      TransformCollectingCall c2 = new TransformCollectingCall(call.getPlanner(), JoinPushTransitivePredicatesRule.INSTANCE.getOperand(), new RelNode[] {join}, null);
      JoinPushTransitivePredicatesRule.INSTANCE.onMatch(c2);
      if (c2.outcome.isEmpty()) {
        return join;
      } else {
        return c2.outcome.get(0);
      }
    }
  }));
}
 
Example #10
Source File: SemiJoinFilterTransposeRule.java    From calcite with Apache License 2.0 6 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  LogicalJoin semiJoin = call.rel(0);
  LogicalFilter filter = call.rel(1);

  RelNode newSemiJoin =
      LogicalJoin.create(filter.getInput(),
          semiJoin.getRight(),
          // No need to copy the hints, the framework would try to do that.
          ImmutableList.of(),
          semiJoin.getCondition(),
          ImmutableSet.of(),
          JoinRelType.SEMI);

  final RelFactories.FilterFactory factory =
      RelFactories.DEFAULT_FILTER_FACTORY;
  RelNode newFilter =
      factory.createFilter(newSemiJoin, filter.getCondition(),
          ImmutableSet.of());

  call.transformTo(newFilter);
}
 
Example #11
Source File: FlinkSemiAntiJoinProjectTransposeRule.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(RelOptRuleCall call) {
	LogicalJoin join = call.rel(0);
	LogicalProject project = call.rel(1);

	// only accept SEMI/ANTI join
	JoinRelType joinType = join.getJoinType();
	if (joinType != JoinRelType.SEMI && joinType != JoinRelType.ANTI) {
		return false;
	}
	// all expressions in Project should be RexInputRef
	for (RexNode p : project.getProjects()) {
		if (!(p instanceof RexInputRef)) {
			return false;
		}
	}
	return true;
}
 
Example #12
Source File: FlinkSemiAntiJoinFilterTransposeRule.java    From flink with Apache License 2.0 6 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
	LogicalJoin join = call.rel(0);
	LogicalFilter filter = call.rel(1);

	RelNode newJoin = LogicalJoin.create(
			filter.getInput(),
			join.getRight(),
			join.getCondition(),
			join.getVariablesSet(),
			join.getJoinType());

	final RelFactories.FilterFactory factory =
			RelFactories.DEFAULT_FILTER_FACTORY;
	RelNode newFilter =
			factory.createFilter(newJoin, filter.getCondition());

	call.transformTo(newFilter);
}
 
Example #13
Source File: ElasticsearchJoinRule.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
public RelNode convert(RelNode relNode) {
    LogicalJoin join = (LogicalJoin) relNode;
    List<RelNode> newInputs = new ArrayList<RelNode>();
    for (RelNode input : join.getInputs()) {
        if (!(input.getConvention().getName().equals(ElasticsearchRelNode.CONVENTION.getName()))) {
            input =
                    convert(
                            input,
                            input.getTraitSet()
                                    .replace(ElasticsearchRelNode.CONVENTION));
        }
        newInputs.add(input);
    }
    final RelOptCluster cluster = join.getCluster();
    final RelTraitSet traitSet =
            join.getTraitSet().replace(ElasticsearchRelNode.CONVENTION);
    final RelNode left = newInputs.get(0);
    final RelNode right = newInputs.get(1);

    return new ElasticsearchJoin(join.getCluster(), traitSet, left, right,
            join.getCondition(), join.getJoinType());
}
 
Example #14
Source File: ElasticsearchJoinRule.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
public RelNode convert(RelNode relNode) {
    LogicalJoin join = (LogicalJoin) relNode;
    List<RelNode> newInputs = new ArrayList<RelNode>();
    for (RelNode input : join.getInputs()) {
        if (!(input.getConvention().getName().equals(ElasticsearchRelNode.CONVENTION.getName()))) {
            input =
                    convert(
                            input,
                            input.getTraitSet()
                                    .replace(ElasticsearchRelNode.CONVENTION));
        }
        newInputs.add(input);
    }
    final RelOptCluster cluster = join.getCluster();
    final RelTraitSet traitSet =
            join.getTraitSet().replace(ElasticsearchRelNode.CONVENTION);
    final RelNode left = newInputs.get(0);
    final RelNode right = newInputs.get(1);

    return new ElasticsearchJoin(join.getCluster(), traitSet, left, right,
            join.getCondition(), join.getJoinType());
}
 
Example #15
Source File: LoptSemiJoinOptimizer.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Removes a dimension table from a fact table's list of possible semijoins
 *
 * @param possibleDimensions possible dimension tables associated with the
 * fact table
 * @param factIdx index corresponding to fact table
 * @param dimIdx index corresponding to dimension table
 */
private void removePossibleSemiJoin(
    Map<Integer, LogicalJoin> possibleDimensions,
    Integer factIdx,
    Integer dimIdx) {
  // dimension table may not have a corresponding semijoin if it
  // wasn't indexable
  if (possibleDimensions == null) {
    return;
  }
  possibleDimensions.remove(dimIdx);
  if (possibleDimensions.isEmpty()) {
    possibleSemiJoins.remove(factIdx);
  } else {
    possibleSemiJoins.put(factIdx, possibleDimensions);
  }
}
 
Example #16
Source File: SqlHintsConverterTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public RelNode convert(RelNode rel) {
  LogicalJoin join = (LogicalJoin) rel;
  assertThat(join.getHints().size(), is(1));
  assertThat(join.getHints().get(0), is(expectedHint));
  List<RelNode> newInputs = new ArrayList<>();
  for (RelNode input : join.getInputs()) {
    if (!(input.getConvention() instanceof EnumerableConvention)) {
      input =
        convert(
          input,
          input.getTraitSet()
            .replace(EnumerableConvention.INSTANCE));
    }
    newInputs.add(input);
  }
  final RelOptCluster cluster = join.getCluster();
  final RelNode left = newInputs.get(0);
  final RelNode right = newInputs.get(1);
  final JoinInfo info = join.analyzeCondition();
  return EnumerableHashJoin.create(
    left,
    right,
    info.getEquiCondition(left, right, cluster.getRexBuilder()),
    join.getVariablesSet(),
    join.getJoinType());
}
 
Example #17
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 #18
Source File: SubQueryDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode visit(LogicalJoin join) {
	switch (join.getJoinType()) {
		case LEFT:
			checkCorConditionOfInput(join.getRight());
			break;
		case RIGHT:
			checkCorConditionOfInput(join.getLeft());
			break;
		case FULL:
			checkCorConditionOfInput(join.getLeft());
			checkCorConditionOfInput(join.getRight());
			break;
		default:
			break;
	}

	final boolean hasSubQuery = RexUtil.SubQueryFinder.find(join.getCondition()) != null;
	try {
		if (!corNodeStack.isEmpty()) {
			mapSubQueryNodeToCorSet.put(join, corNodeStack.peek().getVariablesSet());
		}
		if (hasSubQuery) {
			corNodeStack.push(join);
		}
		checkCorCondition(join);
		join.getCondition().accept(rexVisitor(join));
	} finally {
		if (hasSubQuery) {
			corNodeStack.pop();
		}
	}
	visitChild(join, 0, join.getLeft());
	visitChild(join, 1, join.getRight());
	return join;
}
 
Example #19
Source File: SubQueryDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode visit(LogicalJoin join) {
	switch (join.getJoinType()) {
		case LEFT:
			checkCorConditionOfInput(join.getRight());
			break;
		case RIGHT:
			checkCorConditionOfInput(join.getLeft());
			break;
		case FULL:
			checkCorConditionOfInput(join.getLeft());
			checkCorConditionOfInput(join.getRight());
			break;
		default:
			break;
	}

	final boolean hasSubQuery = RexUtil.SubQueryFinder.find(join.getCondition()) != null;
	try {
		if (!corNodeStack.isEmpty()) {
			mapSubQueryNodeToCorSet.put(join, corNodeStack.peek().getVariablesSet());
		}
		if (hasSubQuery) {
			corNodeStack.push(join);
		}
		checkCorCondition(join);
		join.getCondition().accept(rexVisitor(join));
	} finally {
		if (hasSubQuery) {
			corNodeStack.pop();
		}
	}
	visitChild(join, 0, join.getLeft());
	visitChild(join, 1, join.getRight());
	return join;
}
 
Example #20
Source File: SqlHintsConverterTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns a {@link HintPredicate} for join with specified table references. */
private static HintPredicate joinWithFixedTableName() {
  return (hint, rel) -> {
    if (!(rel instanceof LogicalJoin)) {
      return false;
    }
    LogicalJoin join = (LogicalJoin) rel;
    final List<String> tableNames = hint.listOptions;
    final List<String> inputTables = join.getInputs().stream()
        .filter(input -> input instanceof TableScan)
        .map(scan -> Util.last(scan.getTable().getQualifiedName()))
        .collect(Collectors.toList());
    return equalsStringList(tableNames, inputTables);
  };
}
 
Example #21
Source File: JoinTranslator.java    From samza with Apache License 2.0 5 votes vote down vote up
private SqlIOConfig resolveSQlIOForTable(RelNode relNode, TranslatorContext context) {
  // Let's recursively get to the TableScan node to identify IO for the table.
  if (relNode instanceof LogicalProject) {
    return resolveSQlIOForTable(((LogicalProject) relNode).getInput(), context);
  }

  if (relNode instanceof LogicalFilter) {
    return resolveSQlIOForTable(((LogicalFilter) relNode).getInput(), context);
  }

  // We return null for table IO as the table seems to be involved in another join. The output of stream-table join
  // is considered a stream. Hence, we return null for the table.
  if (relNode instanceof LogicalJoin && relNode.getInputs().size() > 1) {
    return null;
  }

  if (!(relNode instanceof TableScan)) {
    throw new SamzaException(String.format("Unsupported query. relNode %s is not of type TableScan.",
        relNode.toString()));
  }

  String sourceName = SqlIOConfig.getSourceFromSourceParts(relNode.getTable().getQualifiedName());
  SqlIOConfig sourceConfig =
      context.getExecutionContext().getSamzaSqlApplicationConfig().getInputSystemStreamConfigBySource().get(sourceName);
  if (sourceConfig == null) {
    throw new SamzaException("Unsupported source found in join statement: " + sourceName);
  }
  return sourceConfig;
}
 
Example #22
Source File: RelNodeCompiler.java    From streamline with Apache License 2.0 5 votes vote down vote up
private void beginJoinStage(Join join) {
  int[] ordinals = new int[2];
  if (!RelOptUtil.analyzeSimpleEquiJoin((LogicalJoin) join, ordinals)) {
    throw new UnsupportedOperationException("Only simple equi joins are supported");
  }

  pw.print(String.format(JOIN_STAGE_PROLOGUE, getStageName(join),
                         getStageName(join.getLeft()),
                         getStageName(join.getRight()),
                         ordinals[0],
                         ordinals[1]));
}
 
Example #23
Source File: SubQueryDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * check whether a node has some input which have correlation condition.
 * e.g. SELECT * FROM l WHERE EXISTS (SELECT * FROM r LEFT JOIN (SELECT * FROM t WHERE t.j=l.b) t1 ON r.f=t1.k)
 * the above sql can not be converted to semi-join plan,
 * because the right input of Left-Join has the correlation condition(t.j=l.b).
 */
private void checkCorConditionOfInput(final RelNode input) {
	final RelShuttleImpl shuttle = new RelShuttleImpl() {
		final RexVisitor<Void> visitor = new RexVisitorImpl<Void>(true) {
			@Override
			public Void visitCorrelVariable(RexCorrelVariable correlVariable) {
				hasUnsupportedCorCondition = true;
				return super.visitCorrelVariable(correlVariable);
			}
		};

		@Override
		public RelNode visit(LogicalFilter filter) {
			filter.getCondition().accept(visitor);
			return super.visit(filter);
		}

		@Override
		public RelNode visit(LogicalProject project) {
			for (RexNode rex : project.getProjects()) {
				rex.accept(visitor);
			}
			return super.visit(project);
		}

		@Override
		public RelNode visit(LogicalJoin join) {
			join.getCondition().accept(visitor);
			return super.visit(join);
		}
	};
	input.accept(shuttle);
}
 
Example #24
Source File: SubQueryDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * check whether the predicate on join has unsupported correlation condition.
 * e.g. SELECT * FROM l WHERE a IN (SELECT c FROM r WHERE l.b IN (SELECT e FROM t))
 */
private void checkCorCondition(final LogicalJoin join) {
	if (!hasUnsupportedCorCondition) {
		join.getCondition().accept(new RexVisitorImpl<Void>(true) {
			@Override
			public Void visitCorrelVariable(RexCorrelVariable correlVariable) {
				hasUnsupportedCorCondition = true;
				return super.visitCorrelVariable(correlVariable);
			}
		});
	}
}
 
Example #25
Source File: RelOptUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public static boolean analyzeSimpleEquiJoin(
    LogicalJoin join,
    int[] joinFieldOrdinals) {
  RexNode joinExp = join.getCondition();
  if (joinExp.getKind() != SqlKind.EQUALS) {
    return false;
  }
  RexCall binaryExpression = (RexCall) joinExp;
  RexNode leftComparand = binaryExpression.operands.get(0);
  RexNode rightComparand = binaryExpression.operands.get(1);
  if (!(leftComparand instanceof RexInputRef)) {
    return false;
  }
  if (!(rightComparand instanceof RexInputRef)) {
    return false;
  }

  final int leftFieldCount =
      join.getLeft().getRowType().getFieldCount();
  RexInputRef leftFieldAccess = (RexInputRef) leftComparand;
  if (!(leftFieldAccess.getIndex() < leftFieldCount)) {
    // left field must access left side of join
    return false;
  }

  RexInputRef rightFieldAccess = (RexInputRef) rightComparand;
  if (!(rightFieldAccess.getIndex() >= leftFieldCount)) {
    // right field must access right side of join
    return false;
  }

  joinFieldOrdinals[0] = leftFieldAccess.getIndex();
  joinFieldOrdinals[1] = rightFieldAccess.getIndex() - leftFieldCount;
  return true;
}
 
Example #26
Source File: StreamRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  final Delta delta = call.rel(0);
  Util.discard(delta);
  final Join join = call.rel(1);
  final RelNode left = join.getLeft();
  final RelNode right = join.getRight();

  final LogicalDelta rightWithDelta = LogicalDelta.create(right);
  final LogicalJoin joinL = LogicalJoin.create(left,
      rightWithDelta,
      join.getHints(),
      join.getCondition(),
      join.getVariablesSet(),
      join.getJoinType(),
      join.isSemiJoinDone(),
      ImmutableList.copyOf(join.getSystemFieldList()));

  final LogicalDelta leftWithDelta = LogicalDelta.create(left);
  final LogicalJoin joinR = LogicalJoin.create(leftWithDelta,
      right,
      join.getHints(),
      join.getCondition(),
      join.getVariablesSet(),
      join.getJoinType(),
      join.isSemiJoinDone(),
      ImmutableList.copyOf(join.getSystemFieldList()));

  List<RelNode> inputsToUnion = new ArrayList<>();
  inputsToUnion.add(joinL);
  inputsToUnion.add(joinR);

  final LogicalUnion newNode = LogicalUnion.create(inputsToUnion, true);
  call.transformTo(newNode);
}
 
Example #27
Source File: EnumerableJoinRule.java    From calcite with Apache License 2.0 5 votes vote down vote up
EnumerableJoinRule() {
  super(
      LogicalJoin.class,
      Convention.NONE,
      EnumerableConvention.INSTANCE,
      "EnumerableJoinRule");
}
 
Example #28
Source File: SubQueryDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * check whether the predicate on join has unsupported correlation condition.
 * e.g. SELECT * FROM l WHERE a IN (SELECT c FROM r WHERE l.b IN (SELECT e FROM t))
 */
private void checkCorCondition(final LogicalJoin join) {
	if (!hasUnsupportedCorCondition) {
		join.getCondition().accept(new RexVisitorImpl<Void>(true) {
			@Override
			public Void visitCorrelVariable(RexCorrelVariable correlVariable) {
				hasUnsupportedCorCondition = true;
				return super.visitCorrelVariable(correlVariable);
			}
		});
	}
}
 
Example #29
Source File: RelMetadataTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testTableReferencesJoinUnknownNode() {
  final String sql = "select * from emp limit 10";
  final RelNode node = convertSql(sql);
  final RelNode nodeWithUnknown = new DummyRelNode(
      node.getCluster(), node.getTraitSet(), node);
  final RexBuilder rexBuilder = node.getCluster().getRexBuilder();
  // Join
  final LogicalJoin join =
      LogicalJoin.create(nodeWithUnknown, node, ImmutableList.of(),
          rexBuilder.makeLiteral(true), ImmutableSet.of(), JoinRelType.INNER);
  final RelMetadataQuery mq = node.getCluster().getMetadataQuery();
  final Set<RelTableRef> tableReferences = mq.getTableReferences(join);
  assertNull(tableReferences);
}
 
Example #30
Source File: SemiJoinProjectTransposeRule.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SemiJoinProjectTransposeRule.
 */
private SemiJoinProjectTransposeRule(RelBuilderFactory relBuilderFactory) {
  super(
      operandJ(LogicalJoin.class, null, Join::isSemiJoin,
          some(operand(LogicalProject.class, any()))),
      relBuilderFactory, null);
}