conf.set("import.destination.table", tblDesc.getTableName());
for (AddPartitionDesc addPartitionDesc : partitionDescs) {
addPartitionDesc.setTableName(tblDesc.getTableName());
}
}
Warehouse wh = new Warehouse(conf);
try {
Table table = db.getTable(tblDesc.getTableName());
checkTable(table, tblDesc);
LOG.debug("table " + tblDesc.getTableName()
+ " exists: metadata checked");
tableExists = true;
conf.set("import.destination.dir", table.getDataLocation().toString());
if (table.isPartitioned()) {
LOG.debug("table partitioned");
for (AddPartitionDesc addPartitionDesc : partitionDescs) {
if (db.getPartition(table, addPartitionDesc.getPartSpec(), false) == null) {
rootTasks.add(addSinglePartition(fromURI, fs, tblDesc, table, wh, addPartitionDesc));
} else {
throw new SemanticException(
ErrorMsg.PARTITION_EXISTS
.getMsg(partSpecToString(addPartitionDesc.getPartSpec())));
}
}
} else {
LOG.debug("table non-partitioned");
checkTargetLocationEmpty(fs, new Path(table.getDataLocation()
.toString()));
loadTable(fromURI, table);
}
outputs.add(new WriteEntity(table));
} catch (InvalidTableException e) {
LOG.debug("table " + tblDesc.getTableName() + " does not exist");
Task<?> t = TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
tblDesc), conf);
Table table = new Table(dbname, tblDesc.getTableName());
conf.set("import.destination.dir",
wh.getTablePath(db.getDatabase(db.getCurrentDatabase()),
tblDesc.getTableName()).toString());
if ((tblDesc.getPartCols() != null) && (tblDesc.getPartCols().size() != 0)) {
for (AddPartitionDesc addPartitionDesc : partitionDescs) {
t.addDependentTask(
addSinglePartition(fromURI, fs, tblDesc, table, wh, addPartitionDesc));
}
} else {
LOG.debug("adding dependent CopyWork/MoveWork for table");
if (tblDesc.isExternal() && (tblDesc.getLocation() == null)) {
LOG.debug("Importing in place, no emptiness check, no copying/loading");
Path dataPath = new Path(fromURI.toString(), "data");
tblDesc.setLocation(dataPath.toString());
} else {
Path tablePath = null;
if (tblDesc.getLocation() != null) {
tablePath = new Path(tblDesc.getLocation());
} else {
tablePath = wh.getTablePath(db.getDatabase(db.getCurrentDatabase()), tblDesc.getTableName());
}
checkTargetLocationEmpty(fs, tablePath);
t.addDependentTask(loadTable(fromURI, table));
}
}