void buildJoinCondition(RowResolver outerQueryRR, RowResolver sqRR,
      boolean forHavingClause,
      String outerQueryAlias) throws SemanticException {
    ASTNode parentQueryJoinCond = null;

    if ( parentQueryExpression != null ) {

      ColumnInfo outerQueryCol = null;
      try {
        outerQueryCol = outerQueryRR.getExpression(parentQueryExpression);
      } catch(SemanticException se) {
        // ignore
      }

      ASTNode parentExpr = parentQueryExpression;
      if (!forHavingClause) {
        Set<String> aliases = outerQueryRR.getRslvMap().keySet();
        if (notInCheck != null) {
          aliases.remove(notInCheck.getAlias());
        }
        String tableAlias = aliases.size() == 1 ? aliases.iterator().next() : null;
        parentExpr =
                SubQueryUtils.setQualifiedColumnReferences(parentExpr, tableAlias);
        if (parentExpr == null) {
          subQueryAST.setOrigin(originalSQASTOrigin);
          throw new SemanticException(ASTErrorUtils.getMsg(
              ErrorMsg.UNSUPPORTED_SUBQUERY_EXPRESSION.getMsg(),
                  parentQueryExpression,
                  "Correlating expression contains ambiguous column references."));
        }
      }

      parentQueryJoinCond = SubQueryUtils.buildOuterQryToSQJoinCond(
         parentExpr,
         alias,
         sqRR);

      if ( outerQueryCol != null ) {
        rewriteCorrConjunctForHaving(parentQueryJoinCond, true,
            outerQueryAlias, outerQueryRR, outerQueryCol);
      }
      subQueryDiagnostic.addJoinCondition(parentQueryJoinCond, outerQueryCol != null, true);
    }
    joinConditionAST = SubQueryUtils.andAST(parentQueryJoinCond, joinConditionAST);
    setJoinType();

    if ( joinType == JoinType.LEFTOUTER ) {
      if ( operator.getType() == SubQueryType.NOT_EXISTS && hasCorrelation ) {
        postJoinConditionAST = SubQueryUtils.buildPostJoinNullCheck(subQueryJoinAliasExprs);
      } else if ( operator.getType() == SubQueryType.NOT_IN ) {
        postJoinConditionAST = SubQueryUtils.buildOuterJoinPostCond(alias, sqRR);
      }
    }

  }
@param parentQueryRR
@param forHavingClause
@param outerQueryAlias
@return true if it is correlated scalar subquery with an aggregate
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/parse/QBSubQuery.java