* @throws HiveException Throws this exception if an unexpected error occurs.
*/
private int createTable(Hive db, createTableDesc crtTbl) throws HiveException {
// create the table
Table tbl = new Table(crtTbl.getTableName());
StorageDescriptor tblStorDesc = tbl.getTTable().getSd();
if (crtTbl.getBucketCols() != null)
tblStorDesc.setBucketCols(crtTbl.getBucketCols());
if (crtTbl.getSortCols() != null)
tbl.setSortCols(crtTbl.getSortCols());
if (crtTbl.getPartCols() != null)
tbl.setPartCols(crtTbl.getPartCols());
if (crtTbl.getNumBuckets() != -1)
tblStorDesc.setNumBuckets(crtTbl.getNumBuckets());
if (crtTbl.getSerName() != null) {
tbl.setSerializationLib(crtTbl.getSerName());
if (crtTbl.getMapProp() != null) {
Iterator<Map.Entry<String, String>> iter = crtTbl.getMapProp()
.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, String> m = (Map.Entry<String, String>) iter.next();
tbl.setSerdeParam(m.getKey(), m.getValue());
}
}
} else {
if (crtTbl.getFieldDelim() != null) {
tbl.setSerdeParam(Constants.FIELD_DELIM, crtTbl.getFieldDelim());
tbl.setSerdeParam(Constants.SERIALIZATION_FORMAT, crtTbl
.getFieldDelim());
}
if (crtTbl.getCollItemDelim() != null)
tbl
.setSerdeParam(Constants.COLLECTION_DELIM, crtTbl
.getCollItemDelim());
if (crtTbl.getMapKeyDelim() != null)
tbl.setSerdeParam(Constants.MAPKEY_DELIM, crtTbl.getMapKeyDelim());
if (crtTbl.getLineDelim() != null)
tbl.setSerdeParam(Constants.LINE_DELIM, crtTbl.getLineDelim());
}
/**
* We use LazySimpleSerDe by default.
*
* If the user didn't specify a SerDe, and any of the columns are not simple types,
* we will have to use DynamicSerDe instead.
*/
if (crtTbl.getSerName() == null) {
LOG.info("Default to LazySimpleSerDe for table " + crtTbl.getTableName() );
tbl.setSerializationLib(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class.getName());
}
if (crtTbl.getComment() != null)
tbl.setProperty("comment", crtTbl.getComment());
if (crtTbl.getLocation() != null)
tblStorDesc.setLocation(crtTbl.getLocation());
tbl.setInputFormatClass(crtTbl.getInputFormat());
tbl.setOutputFormatClass(crtTbl.getOutputFormat());
if (crtTbl.isExternal())