use of org.apache.calcite.rex.RexVisitor in project calcite by apache.
the class RelMdColumnOrigins method getColumnOrigins.
public Set<RelColumnOrigin> getColumnOrigins(Project rel, final RelMetadataQuery mq, int iOutputColumn) {
final RelNode input = rel.getInput();
RexNode rexNode = rel.getProjects().get(iOutputColumn);
if (rexNode instanceof RexInputRef) {
// Direct reference: no derivation added.
RexInputRef inputRef = (RexInputRef) rexNode;
return mq.getColumnOrigins(input, inputRef.getIndex());
}
// Anything else is a derivation, possibly from multiple
// columns.
final Set<RelColumnOrigin> set = new HashSet<>();
RexVisitor visitor = new RexVisitorImpl<Void>(true) {
public Void visitInputRef(RexInputRef inputRef) {
Set<RelColumnOrigin> inputSet = mq.getColumnOrigins(input, inputRef.getIndex());
if (inputSet != null) {
set.addAll(inputSet);
}
return null;
}
};
rexNode.accept(visitor);
return createDerivedColumnOrigins(set);
}
Aggregations