private RelNode genFilterRelNode(QB qb, ASTNode searchCond, RelNode srcRel,
        ImmutableMap<String, Integer> outerNameToPosMap, RowResolver outerRR, boolean forHavingClause)
        throws SemanticException {
      final Map<ASTNode, QBSubQueryParseInfo> subQueryToRelNode = new HashMap<>();
      boolean isSubQuery = genSubQueryRelNode(qb, searchCond, srcRel, forHavingClause, subQueryToRelNode);
      if(isSubQuery) {
        RexNode filterExpression = genRexNode(searchCond, relToHiveRR.get(srcRel),
                outerRR, subQueryToRelNode, forHavingClause, cluster.getRexBuilder());

        ImmutableMap<String, Integer> hiveColNameCalcitePosMap = this.relToHiveColNameCalcitePosMap
            .get(srcRel);
        filterExpression = new CorrelationConverter(
            new InputContext(srcRel.getRowType(), hiveColNameCalcitePosMap, relToHiveRR.get(srcRel)),
            outerNameToPosMap, outerRR, subqueryId).apply(filterExpression);

        RelNode filterRel = new HiveFilter(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION),
                srcRel, filterExpression);
        relToHiveColNameCalcitePosMap.put(filterRel, relToHiveColNameCalcitePosMap.get(srcRel));
        relToHiveRR.put(filterRel, relToHiveRR.get(srcRel));
        return filterRel;
      } else {
        return genFilterRelNode(searchCond, srcRel, outerNameToPosMap, outerRR, forHavingClause);
      }
    }
Shuttle that replaces certain references with correlation variables
if needed.
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java