@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(); }
public void dropTable(String db, String table, boolean ifExists) throws Exception { hcatClient.dropTable(db, table, ifExists); List<String> tables = hcatClient.listTableNamesByPattern(db, "*"); assertFalse(tables.contains(table)); }
private boolean exists(URI uri, HCatClient client, boolean closeClient) throws HCatAccessorException { try { boolean flag; HCatURI hcatURI = new HCatURI(uri.toString()); if (!hcatURI.getPartitionMap().isEmpty()) { List<HCatPartition> partitions = client.getPartitions(hcatURI.getDb(), hcatURI.getTable(), hcatURI.getPartitionMap()); flag = partitions != null && !partitions.isEmpty(); } else { List<String> tables = client.listTableNamesByPattern(hcatURI.getDb(), hcatURI.getTable()); flag = tables != null && !tables.isEmpty(); } return (flag); } catch (ConnectionFailureException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } catch (HCatException e) { throw new HCatAccessorException(ErrorCode.E0902, e); } catch (URISyntaxException e) { throw new HCatAccessorException(ErrorCode.E0902, e); } finally { closeQuietly(client, null, closeClient); } }
private boolean exists(URI uri, HCatClient client, boolean closeClient) throws HCatAccessorException { try { boolean flag; HCatURI hcatURI = new HCatURI(uri.toString()); if (!hcatURI.getPartitionMap().isEmpty()) { List<HCatPartition> partitions = client.getPartitions(hcatURI.getDb(), hcatURI.getTable(), hcatURI.getPartitionMap()); flag = partitions != null && !partitions.isEmpty(); } else { List<String> tables = client.listTableNamesByPattern(hcatURI.getDb(), hcatURI.getTable()); flag = tables != null && !tables.isEmpty(); } return (flag); } catch (ConnectionFailureException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } catch (HCatException e) { throw new HCatAccessorException(ErrorCode.E0902, e); } catch (URISyntaxException e) { throw new HCatAccessorException(ErrorCode.E0902, e); } finally { closeQuietly(client, null, closeClient); } }
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)); }