private Map<String, CTEClause> getMaterializationMetadata(QB qb) throws SemanticException {
    if (qb.isCTAS()) {
      return null;
    }
    Map<String, CTEClause> materializationAliasToCTEs = new HashMap<>(this.aliasToCTEs);
    try {
      gatherCTEReferences(qb, rootClause, materializationAliasToCTEs);
      int threshold = HiveConf.getIntVar(conf, HiveConf.ConfVars.HIVE_CTE_MATERIALIZE_THRESHOLD);
      for (CTEClause cte : Sets.newHashSet(materializationAliasToCTEs.values())) {
        if (threshold >= 0 && cte.reference >= threshold) {
          cte.materialize = !HiveConf.getBoolVar(conf, ConfVars.HIVE_CTE_MATERIALIZE_FULL_AGGREGATE_ONLY)
              || cte.qbExpr.getQB().getParseInfo().isFullyAggregate();
        }
      }
    } catch (HiveException e) {
      LOG.error("Failed to get Materialization Metadata", e);
      if (e instanceof SemanticException) {
        throw (SemanticException)e;
      }
      throw new SemanticException(e.getMessage(), e);
    }
    return materializationAliasToCTEs;
  }
This is phase1 of supporting specifying schema in insert statement
insert into foo(z,y) select a,b from bar;
@see #handleInsertStatementSpec(java.util.List, String, RowResolver, QB, ASTNode)
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java