diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/ImportSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/ImportSemanticAnalyzer.java index 549d24f..b261b90 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/ImportSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/ImportSemanticAnalyzer.java @@ -317,10 +317,9 @@ private CreateTableDesc getBaseCreateTableDescFromTable(String dbName, return tblDesc; } - private Task loadTable(URI fromURI, Table table, boolean replace) { - Path dataPath = new Path(fromURI.toString(), "data"); - Path tmpPath = ctx.getExternalTmpPath(new Path(fromURI)); - Task copyTask = TaskFactory.get(new CopyWork(dataPath, + private Task loadTable(Path srcPath, Table table, boolean replace, Path tgtPath) { + Path tmpPath = ctx.getExternalTmpPath(tgtPath); + Task copyTask = TaskFactory.get(new CopyWork(srcPath, tmpPath, false), conf); LoadTableDesc loadTableWork = new LoadTableDesc(tmpPath, Utilities.getTableDesc(table), new TreeMap(), @@ -389,7 +388,8 @@ private CreateTableDesc getBaseCreateTableDescFromTable(String dbName, LOG.debug("adding dependent CopyWork/AddPart/MoveWork for partition " + partSpecToString(partSpec.getPartSpec()) + " with source location: " + srcLocation); - Path tmpPath = ctx.getExternalTmpPath(new Path(fromURI)); + Path tgtLocation = new Path(partSpec.getLocation()); + Path tmpPath = ctx.getExternalTmpPath(tgtLocation); Task copyTask = TaskFactory.get(new CopyWork(new Path(srcLocation), tmpPath, false), conf); Task addPartTask = TaskFactory.get(new DDLWork(getInputs(), @@ -430,7 +430,8 @@ private void fixLocationInPartSpec( tgtPath = new Path(tblDesc.getLocation(), Warehouse.makePartPath(partSpec.getPartSpec())); } - checkTargetLocationEmpty(fs, tgtPath, replicationSpec); + FileSystem tgtFs = FileSystem.get(tgtPath.toUri(), conf); + checkTargetLocationEmpty(tgtFs, tgtPath, replicationSpec); partSpec.setLocation(tgtPath.toString()); } @@ -706,8 +707,10 @@ private void createRegularImportTasks( } else { LOG.debug("table non-partitioned"); // ensure if destination is not empty only for regular import - checkTargetLocationEmpty(fs, new Path(table.getDataLocation().toString()), replicationSpec); - loadTable(fromURI, table, false); + Path tgtPath = new Path(table.getDataLocation().toString()); + FileSystem tgtFs = FileSystem.get(tgtPath.toUri(), conf); + checkTargetLocationEmpty(tgtFs, tgtPath, replicationSpec); + loadTable(new Path(fromURI), table, false, tgtPath); } // Set this to read because we can't overwrite any existing partitions outputs.add(new WriteEntity(table, WriteEntity.WriteType.DDL_NO_LOCK)); @@ -740,8 +743,9 @@ private void createRegularImportTasks( } else { tablePath = wh.getTablePath(parentDb, tblDesc.getTableName()); } - checkTargetLocationEmpty(fs, tablePath, replicationSpec); - t.addDependentTask(loadTable(fromURI, table, false)); + FileSystem tgtFs = FileSystem.get(tablePath.toUri(), conf); + checkTargetLocationEmpty(tgtFs, tablePath, replicationSpec); + t.addDependentTask(loadTable(new Path(fromURI), table, false, tablePath)); } } rootTasks.add(t); @@ -812,7 +816,7 @@ private void createReplImportTasks( } } else { LOG.debug("adding dependent CopyWork/MoveWork for table"); - t.addDependentTask(loadTable(fromURI, table, true)); + t.addDependentTask(loadTable(new Path(fromURI), table, true, new Path(tblDesc.getLocation()))); } } if (dr == null){ @@ -867,7 +871,7 @@ private void createReplImportTasks( return; // silently return, table is newer than our replacement. } if (!replicationSpec.isMetadataOnly()) { - loadTable(fromURI, table, true); // repl-imports are replace-into + loadTable(new Path(fromURI), table, true, new Path(fromURI)); // repl-imports are replace-into } else { rootTasks.add(alterTableTask(tblDesc)); }