Java Code Examples for org.apache.calcite.util.Util#equalShallow()

The following examples show how to use org.apache.calcite.util.Util#equalShallow() . 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: SubQueryDecorrelator.java    From flink with Apache License 2.0 6 votes vote down vote up
/** Fallback if none of the other {@code decorrelateRel} methods match. */
public Frame decorrelateRel(RelNode rel) {
	RelNode newRel = rel.copy(rel.getTraitSet(), rel.getInputs());
	if (rel.getInputs().size() > 0) {
		List<RelNode> oldInputs = rel.getInputs();
		List<RelNode> newInputs = new ArrayList<>();
		for (int i = 0; i < oldInputs.size(); ++i) {
			final Frame frame = getInvoke(oldInputs.get(i));
			if (frame == null || frame.c != null) {
				// if input is not rewritten, or if it produces correlated variables, terminate rewrite
				return null;
			}
			newInputs.add(frame.r);
			newRel.replaceInput(i, frame.r);
		}

		if (!Util.equalShallow(oldInputs, newInputs)) {
			newRel = rel.copy(rel.getTraitSet(), newInputs);
		}
	}
	// the output position should not change since there are no corVars coming from below.
	return new Frame(rel, newRel, null, identityMap(rel.getRowType().getFieldCount()));
}
 
Example 2
Source File: SubQueryDecorrelator.java    From flink with Apache License 2.0 6 votes vote down vote up
/** Fallback if none of the other {@code decorrelateRel} methods match. */
public Frame decorrelateRel(RelNode rel) {
	RelNode newRel = rel.copy(rel.getTraitSet(), rel.getInputs());
	if (rel.getInputs().size() > 0) {
		List<RelNode> oldInputs = rel.getInputs();
		List<RelNode> newInputs = new ArrayList<>();
		for (int i = 0; i < oldInputs.size(); ++i) {
			final Frame frame = getInvoke(oldInputs.get(i));
			if (frame == null || frame.c != null) {
				// if input is not rewritten, or if it produces correlated variables, terminate rewrite
				return null;
			}
			newInputs.add(frame.r);
			newRel.replaceInput(i, frame.r);
		}

		if (!Util.equalShallow(oldInputs, newInputs)) {
			newRel = rel.copy(rel.getTraitSet(), newInputs);
		}
	}
	// the output position should not change since there are no corVars coming from below.
	return new Frame(rel, newRel, null, identityMap(rel.getRowType().getFieldCount()));
}
 
Example 3
Source File: RelDecorrelator.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Fallback if none of the other {@code decorrelateRel} methods match. */
public Frame decorrelateRel(RelNode rel) {
    RelNode newRel = rel.copy(rel.getTraitSet(), rel.getInputs());

    if (rel.getInputs().size() > 0) {
        List<RelNode> oldInputs = rel.getInputs();
        List<RelNode> newInputs = new ArrayList<>();
        for (int i = 0; i < oldInputs.size(); ++i) {
            final Frame frame = getInvoke(oldInputs.get(i), rel);
            if (frame == null || !frame.corDefOutputs.isEmpty()) {
                // if input is not rewritten, or if it produces correlated
                // variables, terminate rewrite
                return null;
            }
            newInputs.add(frame.r);
            newRel.replaceInput(i, frame.r);
        }

        if (!Util.equalShallow(oldInputs, newInputs)) {
            newRel = rel.copy(rel.getTraitSet(), newInputs);
        }
    }

    // the output position should not change since there are no corVars
    // coming from below.
    return register(rel, newRel, identityMap(rel.getRowType().getFieldCount()), ImmutableSortedMap.of());
}
 
Example 4
Source File: RelDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
/** Fallback if none of the other {@code decorrelateRel} methods match. */
public Frame decorrelateRel(RelNode rel) {
  RelNode newRel = rel.copy(rel.getTraitSet(), rel.getInputs());

  if (rel.getInputs().size() > 0) {
    List<RelNode> oldInputs = rel.getInputs();
    List<RelNode> newInputs = new ArrayList<>();
    for (int i = 0; i < oldInputs.size(); ++i) {
      final Frame frame = getInvoke(oldInputs.get(i), rel);
      if (frame == null || !frame.corDefOutputs.isEmpty()) {
        // if input is not rewritten, or if it produces correlated
        // variables, terminate rewrite
        return null;
      }
      newInputs.add(frame.r);
      newRel.replaceInput(i, frame.r);
    }

    if (!Util.equalShallow(oldInputs, newInputs)) {
      newRel = rel.copy(rel.getTraitSet(), newInputs);
    }
  }

  // the output position should not change since there are no corVars
  // coming from below.
  return register(rel, newRel, identityMap(rel.getRowType().getFieldCount()),
      ImmutableSortedMap.of());
}
 
Example 5
Source File: RelDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
/** Fallback if none of the other {@code decorrelateRel} methods match. */
public Frame decorrelateRel(RelNode rel) {
  RelNode newRel = rel.copy(rel.getTraitSet(), rel.getInputs());

  if (rel.getInputs().size() > 0) {
    List<RelNode> oldInputs = rel.getInputs();
    List<RelNode> newInputs = new ArrayList<>();
    for (int i = 0; i < oldInputs.size(); ++i) {
      final Frame frame = getInvoke(oldInputs.get(i), rel);
      if (frame == null || !frame.corDefOutputs.isEmpty()) {
        // if input is not rewritten, or if it produces correlated
        // variables, terminate rewrite
        return null;
      }
      newInputs.add(frame.r);
      newRel.replaceInput(i, frame.r);
    }

    if (!Util.equalShallow(oldInputs, newInputs)) {
      newRel = rel.copy(rel.getTraitSet(), newInputs);
    }
  }

  // the output position should not change since there are no corVars
  // coming from below.
  return register(rel, newRel, identityMap(rel.getRowType().getFieldCount()),
      ImmutableSortedMap.of());
}
 
Example 6
Source File: RelDecorrelator.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Fallback if none of the other {@code decorrelateRel} methods match. */
public Frame decorrelateRel(RelNode rel) {
  RelNode newRel = rel.copy(rel.getTraitSet(), rel.getInputs());

  if (rel.getInputs().size() > 0) {
    List<RelNode> oldInputs = rel.getInputs();
    List<RelNode> newInputs = new ArrayList<>();
    for (int i = 0; i < oldInputs.size(); ++i) {
      final Frame frame = getInvoke(oldInputs.get(i), rel);
      if (frame == null || !frame.corDefOutputs.isEmpty()) {
        // if input is not rewritten, or if it produces correlated
        // variables, terminate rewrite
        return null;
      }
      newInputs.add(frame.r);
      newRel.replaceInput(i, frame.r);
    }

    if (!Util.equalShallow(oldInputs, newInputs)) {
      newRel = rel.copy(rel.getTraitSet(), newInputs);
    }
  }

  // the output position should not change since there are no corVars
  // coming from below.
  return register(rel, newRel, identityMap(rel.getRowType().getFieldCount()),
      ImmutableSortedMap.of());
}
 
Example 7
Source File: HepPlanner.java    From Bats with Apache License 2.0 4 votes vote down vote up
private HepRelVertex addRelToGraph(
    RelNode rel) {
  // Check if a transformation already produced a reference
  // to an existing vertex.
  if (graph.vertexSet().contains(rel)) {
    return (HepRelVertex) rel;
  }

  // Recursively add children, replacing this rel's inputs
  // with corresponding child vertices.
  final List<RelNode> inputs = rel.getInputs();
  final List<RelNode> newInputs = new ArrayList<>();
  for (RelNode input1 : inputs) {
    HepRelVertex childVertex = addRelToGraph(input1);
    newInputs.add(childVertex);
  }

  if (!Util.equalShallow(inputs, newInputs)) {
    RelNode oldRel = rel;
    rel = rel.copy(rel.getTraitSet(), newInputs);
    onCopy(oldRel, rel);
  }
  // Compute digest first time we add to DAG,
  // otherwise can't get equivVertex for common sub-expression
  rel.recomputeDigest();

  // try to find equivalent rel only if DAG is allowed
  if (!noDag) {
    // Now, check if an equivalent vertex already exists in graph.
    String digest = rel.getDigest();
    HepRelVertex equivVertex = mapDigestToVertex.get(digest);
    if (equivVertex != null) {
      // Use existing vertex.
      return equivVertex;
    }
  }

  // No equivalence:  create a new vertex to represent this rel.
  HepRelVertex newVertex = new HepRelVertex(rel);
  graph.addVertex(newVertex);
  updateVertex(newVertex, rel);

  for (RelNode input : rel.getInputs()) {
    graph.addEdge(newVertex, (HepRelVertex) input);
  }

  nTransformations++;
  return newVertex;
}
 
Example 8
Source File: HepPlanner.java    From calcite with Apache License 2.0 4 votes vote down vote up
private HepRelVertex addRelToGraph(
    RelNode rel) {
  // Check if a transformation already produced a reference
  // to an existing vertex.
  if (graph.vertexSet().contains(rel)) {
    return (HepRelVertex) rel;
  }

  // Recursively add children, replacing this rel's inputs
  // with corresponding child vertices.
  final List<RelNode> inputs = rel.getInputs();
  final List<RelNode> newInputs = new ArrayList<>();
  for (RelNode input1 : inputs) {
    HepRelVertex childVertex = addRelToGraph(input1);
    newInputs.add(childVertex);
  }

  if (!Util.equalShallow(inputs, newInputs)) {
    RelNode oldRel = rel;
    rel = rel.copy(rel.getTraitSet(), newInputs);
    onCopy(oldRel, rel);
  }
  // Compute digest first time we add to DAG,
  // otherwise can't get equivVertex for common sub-expression
  rel.recomputeDigest();

  // try to find equivalent rel only if DAG is allowed
  if (!noDag) {
    // Now, check if an equivalent vertex already exists in graph.
    HepRelVertex equivVertex = mapDigestToVertex.get(rel.getRelDigest());
    if (equivVertex != null) {
      // Use existing vertex.
      return equivVertex;
    }
  }

  // No equivalence:  create a new vertex to represent this rel.
  HepRelVertex newVertex = new HepRelVertex(rel);
  graph.addVertex(newVertex);
  updateVertex(newVertex, rel);

  for (RelNode input : rel.getInputs()) {
    graph.addEdge(newVertex, (HepRelVertex) input);
  }

  nTransformations++;
  return newVertex;
}