コード例 #1
0
ファイル: SelectStmt.java プロジェクト: vthacker/impala-port
  @Override
  public void analyze(Analyzer analyzer) throws AnalysisException, InternalException {
    // start out with table refs to establish aliases
    TableRef leftTblRef = null; // the one to the left of tblRef
    for (TableRef tblRef : tableRefs) {
      tblRef.setLeftTblRef(leftTblRef);
      tblRef.analyze(analyzer);
      leftTblRef = tblRef;
    }

    // populate selectListExprs, aliasSMap, and colNames
    for (SelectListItem item : selectList.getItems()) {
      if (item.isStar()) {
        TableName tblName = item.getTblName();
        if (tblName == null) {
          expandStar(analyzer);
        } else {
          expandStar(analyzer, tblName);
        }
      } else {
        resultExprs.add(item.getExpr());
        SlotRef aliasRef = new SlotRef(null, item.toColumnLabel());
        if (aliasSMap.lhs.contains(aliasRef)) {
          // If we have already seen this alias, it refers to more than one column and
          // therefore is ambiguous.
          ambiguousAliasList.add(aliasRef);
        }
        aliasSMap.lhs.add(aliasRef);
        aliasSMap.rhs.add(item.getExpr().clone(null));
        colLabels.add(item.toColumnLabel());
      }
    }

    // analyze selectListExprs
    Expr.analyze(resultExprs, analyzer);

    if (whereClause != null) {
      whereClause.analyze(analyzer);
      if (whereClause.contains(AggregateExpr.class)) {
        throw new AnalysisException("aggregation function not allowed in WHERE clause");
      }
      whereClause.checkReturnsBool("WHERE clause", false);
      analyzer.registerConjuncts(whereClause, null, true);
    }

    createSortInfo(analyzer);
    analyzeAggregation(analyzer);

    // Substitute expressions to the underlying inline view expressions
    substituteInlineViewExprs(analyzer);

    if (aggInfo != null) {
      LOG.debug("post-analysis " + aggInfo.debugString());
    }
  }
コード例 #2
0
ファイル: SelectStmt.java プロジェクト: nealsid/Impala
  /** Creates resultExprs and baseTblResultExprs. */
  @Override
  public void analyze(Analyzer analyzer) throws AnalysisException, AuthorizationException {
    super.analyze(analyzer);

    // Replace BaseTableRefs with ViewRefs.
    substituteViews(analyzer, tableRefs_);

    // start out with table refs to establish aliases
    TableRef leftTblRef = null; // the one to the left of tblRef
    for (TableRef tblRef : tableRefs_) {
      tblRef.setLeftTblRef(leftTblRef);
      try {
        tblRef.analyze(analyzer);
      } catch (AnalysisException e) {
        // Only re-throw the exception if no tables are missing.
        if (analyzer.getMissingTbls().isEmpty()) throw e;
      }
      leftTblRef = tblRef;
    }

    // All tableRefs have been analyzed, but at least one table was found missing.
    // There is no reason to proceed with analysis past this point.
    if (!analyzer.getMissingTbls().isEmpty()) {
      throw new AnalysisException("Found missing tables. Aborting analysis.");
    }

    // populate selectListExprs, aliasSMap, and colNames
    for (int i = 0; i < selectList_.getItems().size(); ++i) {
      SelectListItem item = selectList_.getItems().get(i);
      if (item.isStar()) {
        TableName tblName = item.getTblName();
        if (tblName == null) {
          expandStar(analyzer);
        } else {
          expandStar(analyzer, tblName);
        }
      } else {
        // Analyze the resultExpr before generating a label to ensure enforcement
        // of expr child and depth limits (toColumn() label may call toSql()).
        item.getExpr().analyze(analyzer);
        resultExprs_.add(item.getExpr());
        String label = item.toColumnLabel(i, analyzer.useHiveColLabels());
        SlotRef aliasRef = new SlotRef(null, label);
        if (aliasSmap_.containsMappingFor(aliasRef)) {
          // If we have already seen this alias, it refers to more than one column and
          // therefore is ambiguous.
          ambiguousAliasList_.add(aliasRef);
        }
        aliasSmap_.addMapping(aliasRef, item.getExpr().clone(null));
        colLabels_.add(label);
      }
    }

    if (whereClause_ != null) {
      whereClause_.analyze(analyzer);
      if (whereClause_.contains(Expr.isAggregatePredicate())) {
        throw new AnalysisException("aggregate function not allowed in WHERE clause");
      }
      whereClause_.checkReturnsBool("WHERE clause", false);
      analyzer.registerConjuncts(whereClause_, null, true);
    }

    createSortInfo(analyzer);
    analyzeAggregation(analyzer);

    // Remember the SQL string before inline-view expression substitution.
    sqlString_ = toSql();

    resolveInlineViewRefs(analyzer);

    if (aggInfo_ != null) LOG.debug("post-analysis " + aggInfo_.debugString());
  }