@Override
  public RexNode visitSubQuery(RexSubQuery subQuery) {

    RelNode newSubquery = subQuery.rel.accept(relShuttle);

    RexNode newSubQueryRex;
    switch (subQuery.op.kind) {
      case IN:
        newSubQueryRex = RexSubQuery.in(newSubquery, subQuery.operands);
        break;

      case EXISTS:
        newSubQueryRex = RexSubQuery.exists(newSubquery);
        break;

      case SCALAR_QUERY:
        newSubQueryRex = RexSubQuery.scalar(newSubquery);
        break;

      case SOME:
      case ALL:
        newSubQueryRex = RexSubQuery.some(newSubquery, subQuery.operands, (SqlQuantifyOperator) subQuery.op);
        break;

      default:
        throw new RuntimeException("Unsupported op.kind " + subQuery.op.kind);
    }

    return newSubQueryRex;
  }
Traverse expressions and tries to rewrite subQuery expressions to Materialized view scans.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveMaterializedViewASTSubQueryRewriteRexShuttle.java