@Override
  public void analyzeInternal(ASTNode root) throws SemanticException {

    SessionState ss = SessionState.get();
    Preconditions.checkNotNull(ss, "SessionState object must not be NULL");
    String queryName = getQueryName(root);
    if (ss.getPreparePlans().containsKey(queryName)) {
      // retrieve cached plan from session state
      SemanticAnalyzer cachedPlan = ss.getPreparePlans().get(queryName);

      // make copy of the plan
      createOperatorCopy(cachedPlan);

      // bind dynamic params
      Map<Integer, ASTNode> parameterMap = findParams(root);
      bindOperatorsWithDynamicParams(parameterMap);

      // reset prepare flag
      this.prepareQuery = false;

      // reset config
      String queryId = this.conf.getVar(HiveConf.ConfVars.HIVE_QUERY_ID);
      String queryString = this.conf.getVar(HiveConf.ConfVars.HIVE_QUERY_STRING);
      this.conf.syncFromConf(cachedPlan.getQueryState().getConf());
      this.conf.setVar(HiveConf.ConfVars.HIVE_QUERY_ID, queryId);
      this.conf.setVar(HiveConf.ConfVars.HIVE_QUERY_STRING, queryString);

      // set rest of the params
      this.inputs = cachedPlan.getInputs();
      this.outputs = cachedPlan.getOutputs();

      //lineage info
      this.setLineageInfo(cachedPlan.getLineageInfo());
      this.setTableAccessInfo(cachedPlan.getTableAccessInfo());
      this.setColumnAccessInfo(cachedPlan.getColumnAccessInfo());


      this.idToTableNameMap = new HashMap<String, String>(cachedPlan.getIdToTableNameMap());

      this.queryProperties = cachedPlan.getQueryProperties();
      this.setAutoCommitValue(cachedPlan.getAutoCommitValue());
      this.transactionalInQuery = cachedPlan.hasTransactionalInQuery();
      this.acidFileSinks.addAll(cachedPlan.getAcidFileSinks());
      this.initCtx(cachedPlan.getCtx());
      this.ctx.setCboInfo(cachedPlan.getCboInfo());
      this.setLoadFileWork(cachedPlan.getLoadFileWork());
      this.setLoadTableWork(cachedPlan.getLoadTableWork());

      this.setQB(cachedPlan.getQB());

      ParseContext pctxt = this.getParseContext();
      // partition pruner
      Transform ppr = new PartitionPruner();
      ppr.transform(pctxt);

      if (!ctx.getExplainLogical()) {
        TaskCompiler compiler = TaskCompilerFactory.getCompiler(conf, pctxt);
        compiler.init(queryState, console, db);
        compiler.compile(pctxt, rootTasks, inputs, outputs);
        fetchTask = pctxt.getFetchTask();
      }
    } else {
      throw new SemanticException("No existing plan found for the execute statement. "
          + "Please make sure to add one using prepare");
    }
  }
Given map of index and ASTNode this traverse all operators within all tasks
including Fetch Task and all root tasks to find and replace all dynamic expressions
ql/src/java/org/apache/hadoop/hive/ql/parse/ExecuteStatementAnalyzer.java