Java Code Examples for org.apache.calcite.rel.logical.LogicalProject#getInput()

The following examples show how to use org.apache.calcite.rel.logical.LogicalProject#getInput() . 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: 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 2
Source File: ProjectToCalcRule.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  final LogicalProject project = call.rel(0);
  final RelNode input = project.getInput();
  final RexProgram program =
      RexProgram.create(
          input.getRowType(),
          project.getProjects(),
          null,
          project.getRowType(),
          project.getCluster().getRexBuilder());
  final LogicalCalc calc = LogicalCalc.create(input, program);
  call.transformTo(calc);
}
 
Example 3
Source File: ProjectToCalcRule.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  final LogicalProject project = call.rel(0);
  final RelNode input = project.getInput();
  final RexProgram program =
      RexProgram.create(
          input.getRowType(),
          project.getProjects(),
          null,
          project.getRowType(),
          project.getCluster().getRexBuilder());
  final LogicalCalc calc = LogicalCalc.create(input, program);
  call.transformTo(calc);
}
 
Example 4
Source File: VolcanoPlannerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  final LogicalProject project = call.rel(0);
  RelNode childRel = project.getInput();
  call.transformTo(
      new PhysLeafRel(
          childRel.getCluster(),
          "b"));
}
 
Example 5
Source File: RelDecorrelator.java    From Bats with Apache License 2.0 4 votes vote down vote up
/**
 * Rewrite LogicalProject.
 *
 * @param rel the project rel to rewrite
 */
public Frame decorrelateRel(LogicalProject rel) {
    //
    // Rewrite logic:
    //
    // 1. Pass along any correlated variables coming from the input.
    //

    final RelNode oldInput = rel.getInput();
    Frame frame = getInvoke(oldInput, rel);
    if (frame == null) {
        // If input has not been rewritten, do not rewrite this rel.
        return null;
    }
    final List<RexNode> oldProjects = rel.getProjects();
    final List<RelDataTypeField> relOutput = rel.getRowType().getFieldList();

    // Project projects the original expressions,
    // plus any correlated variables the input wants to pass along.
    final List<Pair<RexNode, String>> projects = new ArrayList<>();

    // If this Project has correlated reference, create value generator
    // and produce the correlated variables in the new output.
    if (cm.mapRefRelToCorRef.containsKey(rel)) {
        frame = decorrelateInputWithValueGenerator(rel, frame);
    }

    // Project projects the original expressions
    final Map<Integer, Integer> mapOldToNewOutputs = new HashMap<>();
    int newPos;
    for (newPos = 0; newPos < oldProjects.size(); newPos++) {
        projects.add(newPos, Pair.of(decorrelateExpr(currentRel, map, cm, oldProjects.get(newPos)),
                relOutput.get(newPos).getName()));
        mapOldToNewOutputs.put(newPos, newPos);
    }

    // Project any correlated variables the input wants to pass along.
    final SortedMap<CorDef, Integer> corDefOutputs = new TreeMap<>();
    for (Map.Entry<CorDef, Integer> entry : frame.corDefOutputs.entrySet()) {
        projects.add(RexInputRef.of2(entry.getValue(), frame.r.getRowType().getFieldList()));
        corDefOutputs.put(entry.getKey(), newPos);
        newPos++;
    }

    RelNode newProject = relBuilder.push(frame.r).projectNamed(Pair.left(projects), Pair.right(projects), true)
            .build();

    return register(rel, newProject, mapOldToNewOutputs, corDefOutputs);
}
 
Example 6
Source File: RelDecorrelator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Rewrite LogicalProject.
 *
 * @param rel the project rel to rewrite
 */
public Frame decorrelateRel(LogicalProject rel) {
  //
  // Rewrite logic:
  //
  // 1. Pass along any correlated variables coming from the input.
  //

  final RelNode oldInput = rel.getInput();
  Frame frame = getInvoke(oldInput, rel);
  if (frame == null) {
    // If input has not been rewritten, do not rewrite this rel.
    return null;
  }
  final List<RexNode> oldProjects = rel.getProjects();
  final List<RelDataTypeField> relOutput = rel.getRowType().getFieldList();

  // Project projects the original expressions,
  // plus any correlated variables the input wants to pass along.
  final List<Pair<RexNode, String>> projects = new ArrayList<>();

  // If this Project has correlated reference, create value generator
  // and produce the correlated variables in the new output.
  if (cm.mapRefRelToCorRef.containsKey(rel)) {
    frame = decorrelateInputWithValueGenerator(rel, frame);
  }

  // Project projects the original expressions
  final Map<Integer, Integer> mapOldToNewOutputs = new HashMap<>();
  int newPos;
  for (newPos = 0; newPos < oldProjects.size(); newPos++) {
    projects.add(
        newPos,
        Pair.of(
            decorrelateExpr(currentRel, map, cm, oldProjects.get(newPos)),
            relOutput.get(newPos).getName()));
    mapOldToNewOutputs.put(newPos, newPos);
  }

  // Project any correlated variables the input wants to pass along.
  final SortedMap<CorDef, Integer> corDefOutputs = new TreeMap<>();
  for (Map.Entry<CorDef, Integer> entry : frame.corDefOutputs.entrySet()) {
    projects.add(
        RexInputRef.of2(entry.getValue(),
            frame.r.getRowType().getFieldList()));
    corDefOutputs.put(entry.getKey(), newPos);
    newPos++;
  }

  RelNode newProject = relBuilder.push(frame.r)
      .projectNamed(Pair.left(projects), Pair.right(projects), true)
      .build();

  return register(rel, newProject, mapOldToNewOutputs, corDefOutputs);
}
 
Example 7
Source File: RelDecorrelator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Rewrite LogicalProject.
 *
 * @param rel the project rel to rewrite
 */
public Frame decorrelateRel(LogicalProject rel) {
  //
  // Rewrite logic:
  //
  // 1. Pass along any correlated variables coming from the input.
  //

  final RelNode oldInput = rel.getInput();
  Frame frame = getInvoke(oldInput, rel);
  if (frame == null) {
    // If input has not been rewritten, do not rewrite this rel.
    return null;
  }
  final List<RexNode> oldProjects = rel.getProjects();
  final List<RelDataTypeField> relOutput = rel.getRowType().getFieldList();

  // Project projects the original expressions,
  // plus any correlated variables the input wants to pass along.
  final List<Pair<RexNode, String>> projects = new ArrayList<>();

  // If this Project has correlated reference, create value generator
  // and produce the correlated variables in the new output.
  if (cm.mapRefRelToCorRef.containsKey(rel)) {
    frame = decorrelateInputWithValueGenerator(rel, frame);
  }

  // Project projects the original expressions
  final Map<Integer, Integer> mapOldToNewOutputs = new HashMap<>();
  int newPos;
  for (newPos = 0; newPos < oldProjects.size(); newPos++) {
    projects.add(
        newPos,
        Pair.of(
            decorrelateExpr(currentRel, map, cm, oldProjects.get(newPos)),
            relOutput.get(newPos).getName()));
    mapOldToNewOutputs.put(newPos, newPos);
  }

  // Project any correlated variables the input wants to pass along.
  final SortedMap<CorDef, Integer> corDefOutputs = new TreeMap<>();
  for (Map.Entry<CorDef, Integer> entry : frame.corDefOutputs.entrySet()) {
    projects.add(
        RexInputRef.of2(entry.getValue(),
            frame.r.getRowType().getFieldList()));
    corDefOutputs.put(entry.getKey(), newPos);
    newPos++;
  }

  RelNode newProject = relBuilder.push(frame.r)
      .projectNamed(Pair.left(projects), Pair.right(projects), true)
      .build();

  return register(rel, newProject, mapOldToNewOutputs, corDefOutputs);
}
 
Example 8
Source File: PigRules.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelNode convert(RelNode rel) {
  final LogicalProject project = (LogicalProject) rel;
  final RelTraitSet traitSet = project.getTraitSet().replace(PigRel.CONVENTION);
  return new PigProject(project.getCluster(), traitSet, project.getInput(),
      project.getProjects(), project.getRowType());
}