return new Builder(dbName, tableName, columns);
}
Table toHiveTable(HiveConf conf) throws HCatException {
Table newTable = new Table();
newTable.setDbName(dbName);
newTable.setTableName(tableName);
if (tblProps != null) {
newTable.setParameters(tblProps);
}
if (isExternal) {
newTable.putToParameters("EXTERNAL", "TRUE");
newTable.setTableType(TableType.EXTERNAL_TABLE.toString());
} else {
newTable.setTableType(TableType.MANAGED_TABLE.toString());
}
StorageDescriptor sd = new StorageDescriptor();
sd.setSerdeInfo(new SerDeInfo());
if (location != null) {
sd.setLocation(location);
}
if (this.comment != null) {
newTable.putToParameters("comment", comment);
}
if (!StringUtils.isEmpty(fileFormat)) {
sd.setInputFormat(inputformat);
sd.setOutputFormat(outputformat);
if (serde != null) {
sd.getSerdeInfo().setSerializationLib(serde);
} else {
LOG.info("Using LazySimpleSerDe for table " + tableName);
sd.getSerdeInfo()
.setSerializationLib(
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class
.getName());
}
} else {
try {
LOG.info("Creating instance of storage handler to get input/output, serder info.");
HiveStorageHandler sh = HiveUtils.getStorageHandler(conf,
storageHandler);
sd.setInputFormat(sh.getInputFormatClass().getName());
sd.setOutputFormat(sh.getOutputFormatClass().getName());
sd.getSerdeInfo().setSerializationLib(
sh.getSerDeClass().getName());
newTable.putToParameters(
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_STORAGE,
storageHandler);
} catch (HiveException e) {
throw new HCatException(
"Exception while creating instance of storage handler",
e);
}
}
newTable.setSd(sd);
if (this.partCols != null) {
ArrayList<FieldSchema> hivePtnCols = new ArrayList<FieldSchema>();
for (HCatFieldSchema fs : this.partCols) {
hivePtnCols.add(HCatSchemaUtils.getFieldSchema(fs));
}
newTable.setPartitionKeys(hivePtnCols);
}
if (this.cols != null) {
ArrayList<FieldSchema> hiveTblCols = new ArrayList<FieldSchema>();
for (HCatFieldSchema fs : this.cols) {
hiveTblCols.add(HCatSchemaUtils.getFieldSchema(fs));
}
newTable.getSd().setCols(hiveTblCols);
}
if (this.bucketCols != null) {
newTable.getSd().setBucketCols(bucketCols);
newTable.getSd().setNumBuckets(numBuckets);
}
if (this.sortCols != null) {
newTable.getSd().setSortCols(sortCols);
}
newTable.setCreateTime((int) (System.currentTimeMillis() / 1000));
newTable.setLastAccessTimeIsSet(false);
return newTable;
}