fe/src/main/java/com/cloudera/impala/analysis/WithClause.java
/**
   * Analyzes WITH-clause views at the same level from left to right.
   * Nested WITH clauses are analyzed bottom up as follows. Each nested WITH clause
   * establishes a new scope. In each nested scope we gather base-table references and
   * attempt to resolve them against visible views according to the scoping rules.
   * Base tables that cannot be matched against a visible view are
   * propagated upwards to the parent scope to detect recursive references
   * at the parent's level.
   *
   * The visible WITH-clause views are propagated top down by creating a child analyzer
   * in every new scope. The unresolved table references are propagated bottom up.
   */
Analyzes WITH-clause views at the same level from left to right.
Nested WITH clauses are analyzed bottom up as follows. Each nested WITH clause
establishes a new scope. In each nested scope we gather base-table references and
attempt to resolve them against visible views according to the scoping rules.
Base tables that cannot be matched against a visible view are
propagated upwards to the parent scope to detect recursive references
at the parent's level.

The visible WITH-clause views are propagated top down by creating a child analyzer
in every new scope. The unresolved table references are propagated bottom up.
Analyzes WITH - clause views at the same level from left to right . Nested WITH clauses are analyzed bottom up as follows . Each nested WITH clause establishes a new scope . In each nested scope we gather base - table references and attempt to resolve them against visible views according to the scoping rules . Base tables that cannot be matched against a visible view are propagated upwards to the parent scope to detect recursive references at the parent ' s level . The visible WITH - clause views are propagated top down by creating a child analyzer in every new scope . The unresolved table references are propagated bottom up .
private void analyzeWithClause(Analyzer analyzer, WithClause withClause,
      ArrayList<BaseTableRef> unresolvedTableRefs)
      throws AnalysisException, AuthorizationException {
    Analyzer tmpAnalyzer = new Analyzer(analyzer, analyzer.getUser());
    for (ViewRef view: withClause.views_) {
      ArrayList<BaseTableRef> localUnresolvedTableRefs = Lists.newArrayList();
      analyzeQueryStmt(tmpAnalyzer, view.getViewStmt(), localUnresolvedTableRefs);
      for (BaseTableRef baseTblRef: localUnresolvedTableRefs) {
        if (baseTblRef.getName().isFullyQualified()) continue;
        if (baseTblRef.getName().getTbl().equalsIgnoreCase(view.getAlias())) {
          throw new AnalysisException(
              String.format("Unsupported recursive reference to table '%s' in WITH " +
                  "clause.", view.getAlias()));
        }
        if (tmpAnalyzer.findViewDefinition(baseTblRef, false) == null) {
          unresolvedTableRefs.add(baseTblRef);
        }
      }
      tmpAnalyzer.registerWithClauseView(view);
    }
  }
private void analyzeWithClause ( Analyzer analyzer , WithClause withClause , ArrayList < BaseTableRef > unresolvedTableRefs ) throws AnalysisException , AuthorizationException { Analyzer tmpAnalyzer = new Analyzer ( analyzer , analyzer . getUser ( ) ) ; for ( ViewRef view : withClause . views_ ) { ArrayList < BaseTableRef > localUnresolvedTableRefs = Lists . newArrayList ( ) ; analyzeQueryStmt ( tmpAnalyzer , view . getViewStmt ( ) , localUnresolvedTableRefs ) ; for ( BaseTableRef baseTblRef : localUnresolvedTableRefs ) { if ( baseTblRef . getName ( ) . isFullyQualified ( ) ) continue ; if ( baseTblRef . getName ( ) . getTbl ( ) . equalsIgnoreCase ( view . getAlias ( ) ) ) { throw new AnalysisException ( String . format ( "Unsupported recursive reference to table '%s' in WITH " + "clause." , view . getAlias ( ) ) ) ; } if ( tmpAnalyzer . findViewDefinition ( baseTblRef , false ) == null ) { unresolvedTableRefs . add ( baseTblRef ) ; } } tmpAnalyzer . registerWithClauseView ( view ) ; } }
Analyzes WITH-clause views at the same level from left to right.
Analyzes WITH - clause views at the same level from left to right .
// Create a new child analyzer to register views into. // Gather all unresolved table references from all child scopes // of the view's query statement. // Check for recursive references to current view. // Fully-qualified tables cannot be references to WITH-clause views. // If there are no matching WITH-clause views then propagate the base table // to the parent scope as an unresolved table. // Register view so that the next view definition at this level may reference it.