StorageDescriptor sd = new StorageDescriptor();
tbl.setSd(sd);
sd.setCols(cols);
sd.setCompressed(false);
sd.setParameters(new HashMap<String, String>());
sd.setSerdeInfo(new SerDeInfo());
sd.getSerdeInfo().setName(tbl.getTableName());
sd.getSerdeInfo().setParameters(new HashMap<String, String>());
sd.getSerdeInfo().getParameters()
.put(serdeConstants.SERIALIZATION_FORMAT, "1");
sd.setSortCols(new ArrayList<Order>());
client.createTable(tbl);
if (isThriftClient) {
// the createTable() above does not update the location in the 'tbl'
// object when the client is a thrift client and the code below relies
// on the location being present in the 'tbl' object - so get the table
// from the metastore
tbl = client.getTable(dbName, tblName);
}
ArrayList<FieldSchema> viewCols = new ArrayList<FieldSchema>(1);
viewCols.add(new FieldSchema("income", serdeConstants.INT_TYPE_NAME, ""));
ArrayList<FieldSchema> viewPartitionCols = new ArrayList<FieldSchema>(1);
viewPartitionCols.add(new FieldSchema("name", serdeConstants.STRING_TYPE_NAME, ""));
Table view = new Table();
view.setDbName(dbName);
view.setTableName(viewName);
view.setTableType(TableType.VIRTUAL_VIEW.name());
view.setPartitionKeys(viewPartitionCols);
view.setViewOriginalText("SELECT income, name FROM " + tblName);
view.setViewExpandedText("SELECT `" + tblName + "`.`income`, `" + tblName +
"`.`name` FROM `" + dbName + "`.`" + tblName + "`");
StorageDescriptor viewSd = new StorageDescriptor();
view.setSd(viewSd);
viewSd.setCols(viewCols);
viewSd.setCompressed(false);
viewSd.setParameters(new HashMap<String, String>());
viewSd.setSerdeInfo(new SerDeInfo());
viewSd.getSerdeInfo().setParameters(new HashMap<String, String>());
client.createTable(view);
if (isThriftClient) {