/** * Replaces BaseTableRefs in tblRefs whose alias matches a view registered in the given analyzer * or its parent analyzers with a clone of the matching inline view. The cloned inline view * inherits the context-dependent attributes such as the on-clause, join hints, etc. from the * original BaseTableRef. * * <p>Matches views from the inside out, i.e., we first look in this analyzer then in the * parentAnalyzer then and its parent, etc., and finally consult the catalog for matching views * (the global scope). * * <p>This method is used for substituting views from WITH clauses and views from the catalog. */ public void substituteViews(Analyzer analyzer, List<TableRef> tblRefs) throws AuthorizationException, AnalysisException { for (int i = 0; i < tblRefs.size(); ++i) { if (!(tblRefs.get(i) instanceof BaseTableRef)) continue; BaseTableRef tblRef = (BaseTableRef) tblRefs.get(i); ViewRef viewDefinition = analyzer.findViewDefinition(tblRef, true); if (viewDefinition == null) continue; // Instantiate the view to replace the original BaseTableRef. ViewRef viewRef = viewDefinition.instantiate(tblRef); viewRef.getViewStmt().setIsExplain(isExplain_); tblRefs.set(i, viewRef); } }