private void setLoadFileLocation(
      final ParseContext pCtx, LoadFileDesc lfd) throws SemanticException {
    // CTAS; make the move task's destination directory the table's destination.
    DDLDescWithTableProperties ddlDesc = pCtx.getQueryProperties().isCTAS() ?
        pCtx.getCreateTable() : pCtx.getCreateViewDesc();

    FileSinkDesc dataSink = ddlDesc.getAndUnsetWriter();
    Long txnId = ddlDesc.getInitialWriteId();
    String loc = ddlDesc.getLocation();
    int stmtId = 0; // CTAS or CMV cannot be part of multi-txn stmt
    
    Path location = (loc == null) ? getDefaultCtasOrCMVLocation(pCtx) : new Path(loc);
    if (pCtx.getQueryProperties().isCTAS()) {
      CreateTableDesc ctd = pCtx.getCreateTable();
      if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.CREATE_TABLE_AS_EXTERNAL)) {
        ctd.getTblProps().put(hive_metastoreConstants.CTAS_LEGACY_CONFIG, "true"); // create as external table
      }
      try {
        Table table = ctd.toTable(conf);
        if (!ctd.isMaterialization()) {
          table = db.getTranslateTableDryrun(table.getTTable());
        }
        org.apache.hadoop.hive.metastore.api.Table tTable = table.getTTable();
        if (tTable.getSd() != null && tTable.getSd().getLocation() != null) {
          location = new Path(tTable.getSd().getLocation());
        }
        ctd.getTblProps().remove(hive_metastoreConstants.CTAS_LEGACY_CONFIG);
        ctd.fromTable(tTable);
      } catch (HiveException ex) {
        throw new SemanticException(ex);
      }
      pCtx.setCreateTable(ctd);
    }
    if (txnId != null) {
      dataSink.setDirName(location);
      location = new Path(location, AcidUtils.deltaSubdir(txnId, txnId, stmtId));
      lfd.setSourcePath(location);
      if (Utilities.FILE_OP_LOGGER.isTraceEnabled()) {
        Utilities.FILE_OP_LOGGER.trace("Setting MM CTAS to " + location);
      }
    }
    if (Utilities.FILE_OP_LOGGER.isTraceEnabled()) {
      Utilities.FILE_OP_LOGGER.trace("Location for LFD is being set to "
        + location + "; moving from " + lfd.getSourcePath());
    }
    lfd.setTargetDir(location);
  }
TaskCompiler is the base class for classes that compile
operator pipelines into tasks.
ql/src/java/org/apache/hadoop/hive/ql/parse/TaskCompiler.java