try { HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); } catch (Exception exp) { client.dropTable(null, newName, true); HCatCreateTableDesc tableDesc2 = HCatCreateTableDesc .create(null, newName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc2); HCatTable newTable = client.getTable(null, newName);
@Test public void testCreateTableLike() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String tableName = "tableone"; String cloneTable = "tabletwo"; client.dropTable(null, tableName, true); client.dropTable(null, cloneTable, true); ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("id", Type.INT, "id columns")); cols.add(new HCatFieldSchema("value", Type.STRING, "id columns")); HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); // create a new table similar to previous one. client.createTableLike(null, tableName, cloneTable, true, false, null); List<String> tables = client.listTableNamesByPattern(null, "table*"); assertTrue(tables.size() == 2); client.close(); }
cols.add(new HCatFieldSchema("value", Type.STRING, "value comment")); HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(db, tableOne, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); HCatTable table1 = client.getTable(db, tableOne); tableThree, cols).fileFormat("orcfile").build(); client.createTable(tableDesc3); HCatTable table3 = client.getTable(db, tableThree);
public void createTable(String db, String table, String partitionCols) throws Exception { List<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("userid", Type.INT, "userid")); cols.add(new HCatFieldSchema("viewtime", Type.BIGINT, "view time")); cols.add(new HCatFieldSchema("pageurl", Type.STRING, "page url visited")); cols.add(new HCatFieldSchema("ip", Type.STRING, "IP Address of the User")); ArrayList<HCatFieldSchema> ptnCols = new ArrayList<HCatFieldSchema>(); for (String partitionCol : partitionCols.split(",")) { ptnCols.add(new HCatFieldSchema(partitionCol, Type.STRING, null)); } // Remove this once NotificationListener is fixed and available in HCat snapshot Map<String, String> tblProps = new HashMap<String, String>(); tblProps.put(HCatConstants.HCAT_MSGBUS_TOPIC_NAME, "hcat." + db + "." + table); HCatCreateTableDesc tableDesc = HCatCreateTableDesc.create(db, table, cols).fileFormat("textfile") .partCols(ptnCols).tblProps(tblProps ).build(); hcatClient.createTable(tableDesc); List<String> tables = hcatClient.listTableNamesByPattern(db, "*"); assertTrue(tables.contains(table)); }
public void createTable(String db, String table) throws Exception { List<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("userid", Type.INT, "userid")); cols.add(new HCatFieldSchema("viewtime", Type.BIGINT, "view time")); cols.add(new HCatFieldSchema("pageurl", Type.STRING, "page url visited")); cols.add(new HCatFieldSchema("ip", Type.STRING, "IP Address of the User")); // Remove this once NotificationListener is fixed and available in HCat snapshot Map<String, String> tblProps = new HashMap<String, String>(); tblProps.put(HCatConstants.HCAT_MSGBUS_TOPIC_NAME, "hcat." + db + "." + table); HCatCreateTableDesc tableDesc = HCatCreateTableDesc.create(db, table, cols).fileFormat("textfile") .tblProps(tblProps ).build(); hcatClient.createTable(tableDesc); List<String> tables = hcatClient.listTableNamesByPattern(db, "*"); assertTrue(tables.contains(table)); }
try { HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); client.dropTable(null, newName, true); HCatCreateTableDesc tableDesc2 = HCatCreateTableDesc .create(null, newName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc2); HCatTable newTable = client.getTable(null, newName);
@Test public void testRenameTable() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String tableName = "temptable"; String newName = "mytable"; client.dropTable(null, tableName, true); client.dropTable(null, newName, true); ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("id", Type.INT, "id columns")); cols.add(new HCatFieldSchema("value", Type.STRING, "id columns")); HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); client.renameTable(null, tableName, newName); try { client.getTable(null, tableName); } catch (HCatException exp) { assertTrue("Unexpected exception message: " + exp.getMessage(), exp.getMessage().contains("NoSuchObjectException while fetching table")); } HCatTable newTable = client.getTable(null, newName); assertTrue(newTable != null); assertTrue(newTable.getTableName().equals(newName)); client.close(); }