Search in sources :

Example 1 with RexVisitor

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);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RexVisitor(org.apache.calcite.rex.RexVisitor) RexInputRef(org.apache.calcite.rex.RexInputRef) RexVisitorImpl(org.apache.calcite.rex.RexVisitorImpl) RexNode(org.apache.calcite.rex.RexNode) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 RelNode (org.apache.calcite.rel.RelNode)1 RexInputRef (org.apache.calcite.rex.RexInputRef)1 RexNode (org.apache.calcite.rex.RexNode)1 RexVisitor (org.apache.calcite.rex.RexVisitor)1 RexVisitorImpl (org.apache.calcite.rex.RexVisitorImpl)1