public static void setupDeferredContextFromMetadata(DeferredWorkContext deferredContext) throws HiveException {

    deferredContext.table = ImportSemanticAnalyzer.tableIfExists(deferredContext.tblDesc, deferredContext.hive);
    if (deferredContext.table == null) {
      deferredContext.table = ImportSemanticAnalyzer.createNewTableMetadataObject(deferredContext.tblDesc, true);
    }

    if (deferredContext.inReplScope) {
      deferredContext.isSkipTrash = MetaStoreUtils.isSkipTrash(deferredContext.table.getParameters());
      if (deferredContext.table.isTemporary()) {
        deferredContext.needRecycle = false;
      } else {
        org.apache.hadoop.hive.metastore.api.Database db = deferredContext.hive.getDatabase(deferredContext.table.getDbName());
        deferredContext.needRecycle = db != null && ReplChangeManager.shouldEnableCm(db, deferredContext.table.getTTable());
      }
    }

    if (AcidUtils.isTransactionalTable(deferredContext.table)) {
      String mmSubdir = deferredContext.replace ? AcidUtils.baseDir(deferredContext.writeId) :
              AcidUtils.deltaSubdir(deferredContext.writeId, deferredContext.writeId, deferredContext.stmtId);
      deferredContext.destPath = new Path(deferredContext.tgtPath, mmSubdir);
      /*
         CopyTask will copy files from the 'archive' to a delta_x_x in the table/partition
         directory, i.e. the final destination for these files.  This has to be a copy to preserve
         the archive.  MoveTask is optimized to do a 'rename' if files are on the same FileSystem.
         So setting 'loadPath' this way will make
         {@link Hive#loadTable(Path, String, LoadTableDesc.LoadFileType, boolean, boolean, boolean,
         boolean, Long, int, boolean, boolean)}
          skip the unnecessary file (rename) operation but it will perform other things.
      */
      deferredContext.loadPath = deferredContext.tgtPath;
      deferredContext.loadFileType = LoadTableDesc.LoadFileType.KEEP_EXISTING;
    } else {
      deferredContext.destPath = deferredContext.loadPath = deferredContext.ctx.getExternalTmpPath(deferredContext.tgtPath);
      deferredContext.loadFileType = deferredContext.replace ? LoadTableDesc.LoadFileType.REPLACE_ALL : LoadTableDesc.LoadFileType.OVERWRITE_EXISTING;
    }
    deferredContext.isCalculated = true;
  }
The same code is used from both the "repl load" as well as "import".
Given that "repl load" now supports two modes "repl load dbName [location]" and
"repl load [location]" in which case the database name has to be taken from the table metadata
by default and then over-ridden if something specified on the command line.
<p>
hence for import to work correctly we have to pass in the sessionState default Db via the
parsedDbName parameter
ql/src/java/org/apache/hadoop/hive/ql/parse/ImportSemanticAnalyzer.java