Search in sources :

Example 6 with RexSubQuery

use of org.apache.calcite.rex.RexSubQuery in project flink by apache.

the class SubQueryDecorrelator method handleSubQuery.

private RexVisitorImpl<Void> handleSubQuery(final RelNode rel) {
    return new RexVisitorImpl<Void>(true) {

        @Override
        public Void visitSubQuery(RexSubQuery subQuery) {
            RelNode newRel = subQuery.rel;
            if (subQuery.getKind() == SqlKind.IN) {
                newRel = addProjectionForIn(subQuery.rel);
            }
            final Frame frame = decorrelator.getInvoke(newRel);
            if (frame != null && frame.c != null) {
                Frame target = frame;
                if (subQuery.getKind() == SqlKind.EXISTS) {
                    target = addProjectionForExists(frame);
                }
                final DecorrelateRexShuttle shuttle = new DecorrelateRexShuttle(rel.getRowType(), target.r.getRowType(), rel.getVariablesSet());
                final RexNode newCondition = target.c.accept(shuttle);
                Pair<RelNode, RexNode> newNodeAndCondition = new Pair<>(target.r, newCondition);
                subQueryMap.put(subQuery, newNodeAndCondition);
            }
            return null;
        }
    };
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RexVisitorImpl(org.apache.calcite.rex.RexVisitorImpl) RexSubQuery(org.apache.calcite.rex.RexSubQuery) RexNode(org.apache.calcite.rex.RexNode) Pair(org.apache.calcite.util.Pair)

Aggregations

RexSubQuery (org.apache.calcite.rex.RexSubQuery)6 RelNode (org.apache.calcite.rel.RelNode)5 RexNode (org.apache.calcite.rex.RexNode)4 RexCall (org.apache.calcite.rex.RexCall)2 RexVisitorImpl (org.apache.calcite.rex.RexVisitorImpl)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1 RelVisitor (org.apache.calcite.rel.RelVisitor)1 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)1 RexCorrelVariable (org.apache.calcite.rex.RexCorrelVariable)1 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)1 RexShuttle (org.apache.calcite.rex.RexShuttle)1 RelBuilder (org.apache.calcite.tools.RelBuilder)1 Pair (org.apache.calcite.util.Pair)1 FlinkHiveException (org.apache.flink.connectors.hive.FlinkHiveException)1 SubqueryConf (org.apache.hadoop.hive.ql.optimizer.calcite.SubqueryConf)1 HiveFilter (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter)1