void subqueryRestrictionsCheck(RowResolver parentQueryRR,
                                 boolean forHavingClause,
                                 String outerQueryAlias)
          throws SemanticException {
    ASTNode insertClause = getChildFromSubqueryAST("Insert", HiveParser.TOK_INSERT);

    ASTNode selectClause = (ASTNode) insertClause.getChild(1);


    int selectExprStart = 0;
    if ( selectClause.getChild(0).getType() == HiveParser.QUERY_HINT ) {
      selectExprStart = 1;
    }

    /*
     * Check.5.h :: For In and Not In the SubQuery must implicitly or
     * explicitly only contain one select item.
     */
    if ( operator.getType() != SubQueryType.EXISTS &&
            operator.getType() != SubQueryType.NOT_EXISTS &&
            selectClause.getChildCount() - selectExprStart > 1 ) {
      subQueryAST.setOrigin(originalSQASTOrigin);
      throw new SemanticException(ASTErrorUtils.getMsg(
          ErrorMsg.INVALID_SUBQUERY_EXPRESSION.getMsg(),
          subQueryAST, "SubQuery can contain only 1 item in Select List."));
    }

    boolean hasWindowing = false;

    // we need to know if aggregate is COUNT since IN corr subq with count aggregate
    // is not special cased later in subquery remove rule
    for(int i= selectExprStart; i < selectClause.getChildCount(); i++ ) {

      ASTNode selectItem = (ASTNode) selectClause.getChild(i);
      int r = SubQueryUtils.checkAggOrWindowing(selectItem);

      hasWindowing = hasWindowing | ( r == 3);
    }

    // figure out correlation and presence of non-equi join predicate
    boolean hasCorrelation = false;

    ASTNode whereClause = SubQueryUtils.subQueryWhere(insertClause);
    if ( whereClause != null ) {
      ASTNode searchCond = (ASTNode) whereClause.getChild(0);
      List<ASTNode> conjuncts = new ArrayList<ASTNode>();
      SubQueryUtils.extractConjuncts(searchCond, conjuncts);

      ConjunctAnalyzer conjunctAnalyzer =
          new ConjunctAnalyzer(parentQueryRR, forHavingClause, outerQueryAlias);

      for (ASTNode conjunctAST : conjuncts) {
        Conjunct conjunct = conjunctAnalyzer.analyzeConjunct(conjunctAST);
        if (conjunct.isCorrelated()) {
          hasCorrelation = true;
        }
      }
    }

    /*
     * Restriction.14.h :: Only Correlated Exists/Not exists Sub Queries can contain Windowing clauses.
     */
    if (operator.getType() != SubQueryType.EXISTS && operator.getType() != SubQueryType.NOT_EXISTS &&
        hasWindowing && hasCorrelation) {
      throw new CalciteSubquerySemanticException(ASTErrorUtils.getMsg(
          ErrorMsg.UNSUPPORTED_SUBQUERY_EXPRESSION.getMsg(),
          subQueryAST, "Only Correlated Exists/Not exists Sub Queries can contain Windowing clauses."));
    }

  }
@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