tbl_sort_bucket += "INTO " + tbl.getNumBuckets() + " BUCKETS";
}
// Row format (SerDe)
String tbl_row_format = "";
StorageDescriptor sd = tbl.getTTable().getSd();
SerDeInfo serdeInfo = sd.getSerdeInfo();
tbl_row_format += "ROW FORMAT";
if (tbl.getStorageHandler() == null) {
if (serdeInfo.getParametersSize() > 1) {
// There is a "serialization.format" property by default,
// even with a delimited row format.
// But our result will only cover the following four delimiters.
tbl_row_format += " DELIMITED \n";
Map<String, String> delims = serdeInfo.getParameters();
// Warn:
// If the four delimiters all exist in a CREATE TABLE query,
// this following order needs to be strictly followed,
// or the query will fail with a ParseException.
if (delims.containsKey(serdeConstants.FIELD_DELIM)) {
tbl_row_format += " FIELDS TERMINATED BY '" +
escapeHiveCommand(StringEscapeUtils.escapeJava(delims.get(
serdeConstants.FIELD_DELIM))) + "' \n";
}
if (delims.containsKey(serdeConstants.COLLECTION_DELIM)) {
tbl_row_format += " COLLECTION ITEMS TERMINATED BY '" +
escapeHiveCommand(StringEscapeUtils.escapeJava(delims.get(
serdeConstants.COLLECTION_DELIM))) + "' \n";
}
if (delims.containsKey(serdeConstants.MAPKEY_DELIM)) {
tbl_row_format += " MAP KEYS TERMINATED BY '" +
escapeHiveCommand(StringEscapeUtils.escapeJava(delims.get(
serdeConstants.MAPKEY_DELIM))) + "' \n";
}
if (delims.containsKey(serdeConstants.LINE_DELIM)) {
tbl_row_format += " LINES TERMINATED BY '" +
escapeHiveCommand(StringEscapeUtils.escapeJava(delims.get(
serdeConstants.LINE_DELIM))) + "' \n";
}
}
else {
tbl_row_format += " SERDE \n '" +
escapeHiveCommand(serdeInfo.getSerializationLib()) + "' \n";
}
tbl_row_format += "STORED AS INPUTFORMAT \n '" +
escapeHiveCommand(sd.getInputFormat()) + "' \n";
tbl_row_format += "OUTPUTFORMAT \n '" +
escapeHiveCommand(sd.getOutputFormat()) + "'";
}
else {
duplicateProps.add(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_STORAGE);
tbl_row_format += " SERDE \n '" +
escapeHiveCommand(serdeInfo.getSerializationLib()) + "' \n";
tbl_row_format += "STORED BY \n '" + escapeHiveCommand(tbl.getParameters().get(
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_STORAGE)) + "' \n";
// SerDe Properties
if (serdeInfo.getParametersSize() > 0) {
tbl_row_format += "WITH SERDEPROPERTIES ( \n";
List<String> serdeCols = new ArrayList<String>();
for (Map.Entry<String, String> entry : serdeInfo.getParameters().entrySet()) {
serdeCols.add(" '" + entry.getKey() + "'='"
+ escapeHiveCommand(StringEscapeUtils.escapeJava(entry.getValue())) + "'");
}
tbl_row_format += StringUtils.join(serdeCols, ", \n");
tbl_row_format += ")";
}
}
String tbl_location = " '" + escapeHiveCommand(sd.getLocation()) + "'";
// Table properties
String tbl_properties = "";
Map<String, String> properties = tbl.getParameters();
if (properties.size() > 0) {