示例#1
0
  @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
 /**
  * Expand "<tbl>.*" select list item.
  *
  * @param analyzer
  * @param tblName
  * @throws AnalysisException
  */
 private void expandStar(Analyzer analyzer, TableName tblName) throws AnalysisException {
   TupleDescriptor d = analyzer.getDescriptor(tblName);
   if (d == null) {
     throw new AnalysisException("unknown table: " + tblName.toString());
   }
   expandStar(analyzer, tblName.toString(), d);
 }
示例#3
0
 /** Expand "<tbl>.*" select list item. */
 private void expandStar(Analyzer analyzer, TableName tblName)
     throws AnalysisException, AuthorizationException {
   TupleDescriptor tupleDesc = analyzer.getDescriptor(tblName);
   if (tupleDesc == null) {
     throw new AnalysisException("unknown table: " + tblName.toString());
   }
   expandStar(analyzer, tblName, tupleDesc);
 }
示例#4
0
 /** Expand "*" select list item. */
 private void expandStar(Analyzer analyzer) throws AnalysisException {
   if (tableRefs.isEmpty()) {
     throw new AnalysisException("'*' expression in select list requires FROM clause.");
   }
   // expand in From clause order
   for (TableRef tableRef : tableRefs) {
     expandStar(analyzer, tableRef.getAlias(), tableRef.getDesc());
   }
 }
示例#5
0
  /** 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());
  }