@Test public void testGetMessageBusTopicName() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String dbName = "testGetMessageBusTopicName_DBName"; String tableName = "testGetMessageBusTopicName_TableName"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); String messageBusTopicName = "MY.topic.name"; Map<String, String> tableProperties = new HashMap<String, String>(1); tableProperties.put(HCatConstants.HCAT_MSGBUS_TOPIC_NAME, messageBusTopicName); client.createTable(HCatCreateTableDesc.create(dbName, tableName, Arrays.asList(new HCatFieldSchema("foo", Type.STRING, ""))).tblProps(tableProperties).build()); assertEquals("MessageBus topic-name doesn't match!", messageBusTopicName, client.getMessageBusTopicName(dbName, tableName)); client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.close(); } catch (Exception exception) { LOG.error("Unexpected exception.", exception); assertTrue("Unexpected exception:" + exception.getMessage(), false); } }
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)); }
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)); }