for (FieldSchema fsc : partCols) {
partColNames.add(fsc.getName());
}
List<Partition> partitions = rv.getValue();
for (Partition partition : partitions) {
AddPartitionDesc partDesc = new AddPartitionDesc(dbname, tblDesc.getTableName(),
EximUtil.makePartSpec(tblDesc.getPartCols(), partition.getValues()),
partition.getSd().getLocation(), partition.getParameters());
partDesc.setInputFormat(partition.getSd().getInputFormat());
partDesc.setOutputFormat(partition.getSd().getOutputFormat());
partDesc.setNumBuckets(partition.getSd().getNumBuckets());
partDesc.setCols(partition.getSd().getCols());
partDesc.setSerializationLib(partition.getSd().getSerdeInfo().getSerializationLib());
partDesc.setSerdeParams(partition.getSd().getSerdeInfo().getParameters());
partDesc.setBucketCols(partition.getSd().getBucketCols());
partDesc.setSortCols(partition.getSd().getSortCols());
partDesc.setLocation(new Path(fromPath,
Warehouse.makePartName(tblDesc.getPartCols(), partition.getValues())).toString());
partitionDescs.add(partDesc);
}
} catch (IOException e) {
throw new SemanticException(ErrorMsg.INVALID_PATH.getMsg(), e);
}
LOG.debug("metadata read and parsed");
for (int i = 1; i < ast.getChildCount(); ++i) {
ASTNode child = (ASTNode) ast.getChild(i);
switch (child.getToken().getType()) {
case HiveParser.KW_EXTERNAL:
tblDesc.setExternal(true);
break;
case HiveParser.TOK_TABLELOCATION:
String location = unescapeSQLString(child.getChild(0).getText());
location = EximUtil.relativeToAbsolutePath(conf, location);
tblDesc.setLocation(location);
break;
case HiveParser.TOK_TAB:
Tree tableTree = child.getChild(0);
// initialize destination table/partition
String tableName = getUnescapedName((ASTNode)tableTree);
tblDesc.setTableName(tableName);
// get partition metadata if partition specified
LinkedHashMap<String, String> partSpec = new LinkedHashMap<String, String>();
if (child.getChildCount() == 2) {
ASTNode partspec = (ASTNode) child.getChild(1);
// partSpec is a mapping from partition column name to its value.
for (int j = 0; j < partspec.getChildCount(); ++j) {
ASTNode partspec_val = (ASTNode) partspec.getChild(j);
String val = null;
String colName = unescapeIdentifier(partspec_val.getChild(0)
.getText().toLowerCase());
if (partspec_val.getChildCount() < 2) { // DP in the form of T
// partition (ds, hr)
throw new SemanticException(
ErrorMsg.INVALID_PARTITION
.getMsg(" - Dynamic partitions not allowed"));
} else { // in the form of T partition (ds="2010-03-03")
val = stripQuotes(partspec_val.getChild(1).getText());
}
partSpec.put(colName, val);
}
boolean found = false;
for (Iterator<AddPartitionDesc> partnIter = partitionDescs
.listIterator(); partnIter.hasNext();) {
AddPartitionDesc addPartitionDesc = partnIter.next();
if (!found && addPartitionDesc.getPartSpec().equals(partSpec)) {
found = true;
} else {
partnIter.remove();
}
}
if (!found) {
throw new SemanticException(
ErrorMsg.INVALID_PARTITION
.getMsg(" - Specified partition not found in import directory"));
}
}
}
}
if (tblDesc.getTableName() == null) {
throw new SemanticException(ErrorMsg.NEED_TABLE_SPECIFICATION.getMsg());
} else {
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()