Java源码示例:org.apache.calcite.rel.RelVisitor
示例1
/** Returns whether relational expression {@code target} occurs within a
* relational expression {@code ancestor}. */
public static boolean contains(RelNode ancestor, final RelNode target) {
if (ancestor == target) {
// Short-cut common case.
return true;
}
try {
new RelVisitor() {
@Override
public void visit(RelNode node, int ordinal, RelNode parent) {
if (node == target) {
throw Util.FoundOne.NULL;
}
super.visit(node, ordinal, parent);
}
// CHECKSTYLE: IGNORE 1
}.go(ancestor);
return false;
} catch (Util.FoundOne e) {
return true;
}
}
示例2
public List<String> getTables(RelNode relNode) {
final List<String> result = new ArrayList<>();
final Set<RelOptTable> usedTables = new LinkedHashSet<RelOptTable>();
new RelVisitor() {
@Override
public void visit(RelNode node, int ordinal, RelNode parent) {
if (node instanceof TableScan) {
usedTables.add(node.getTable());
}
super.visit(node, ordinal, parent);
}
// CHECKSTYLE: IGNORE 1
}.go(relNode);
for (RelOptTable tbl : usedTables) {
result.add(StringUtils.join(tbl.getQualifiedName(), "."));
}
return result;
}
示例3
/** Returns whether relational expression {@code target} occurs within a
* relational expression {@code ancestor}. */
public static boolean contains(RelNode ancestor, final RelNode target) {
if (ancestor == target) {
// Short-cut common case.
return true;
}
try {
new RelVisitor() {
public void visit(RelNode node, int ordinal, RelNode parent) {
if (node == target) {
throw Util.FoundOne.NULL;
}
super.visit(node, ordinal, parent);
}
// CHECKSTYLE: IGNORE 1
}.go(ancestor);
return false;
} catch (Util.FoundOne e) {
return true;
}
}
示例4
private void setInitialImportance() {
RelVisitor visitor =
new RelVisitor() {
int depth = 0;
final Set<RelSubset> visitedSubsets = new HashSet<>();
public void visit(
RelNode p,
int ordinal,
RelNode parent) {
if (p instanceof RelSubset) {
RelSubset subset = (RelSubset) p;
if (visitedSubsets.contains(subset)) {
return;
}
if (subset != root) {
Double importance = Math.pow(0.9, (double) depth);
ruleQueue.updateImportance(subset, importance);
}
visitedSubsets.add(subset);
depth++;
for (RelNode rel : subset.getRels()) {
visit(rel, -1, subset);
}
depth--;
} else {
super.visit(p, ordinal, parent);
}
}
};
visitor.go(root);
}
示例5
/**
* Sets a {@link RelVisitor} going on a given relational expression, and
* returns the result.
*/
public static void go(RelVisitor visitor, RelNode p) {
try {
visitor.go(p);
} catch (Exception e) {
throw new RuntimeException("while visiting tree", e);
}
}
示例6
/**
* Sets a {@link RelVisitor} going on a given relational expression, and
* returns the result.
*/
public static void go(
RelVisitor visitor,
RelNode p) {
try {
visitor.go(p);
} catch (Exception e) {
throw new RuntimeException("while visiting tree", e);
}
}