/** * Builds the create database descriptor. * * @return An instance of HCatCreateDBDesc * @throws HCatException */ public HCatCreateDBDesc build() throws HCatException { if (this.dbName == null) { throw new HCatException("Database name cannot be null."); } HCatCreateDBDesc desc = new HCatCreateDBDesc(this.dbName); desc.comment = this.innerComment; desc.locationUri = this.innerLoc; desc.dbProperties = this.innerDBProps; desc.ifNotExits = this.ifNotExists; return desc; }
@Override public void createDatabase(HCatCreateDBDesc dbInfo) throws HCatException { try { hmsClient.createDatabase(dbInfo.toHiveDb()); } catch (AlreadyExistsException exp) { if (!dbInfo.getIfNotExists()) { throw new HCatException( "AlreadyExistsException while creating database", exp); } } catch (InvalidObjectException exp) { throw new HCatException( "InvalidObjectException while creating database", exp); } catch (MetaException exp) { throw new HCatException("MetaException while creating database", exp); } catch (TException exp) { throw new ConnectionFailureException( "TException while creating database", exp); } }
@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); } }
@Override public void createDatabase(HCatCreateDBDesc dbInfo) throws HCatException { try { hmsClient.createDatabase(dbInfo.toHiveDb()); } catch (AlreadyExistsException exp) { if (!dbInfo.getIfNotExists()) { throw new HCatException( "AlreadyExistsException while creating database", exp); } } catch (InvalidObjectException exp) { throw new HCatException( "InvalidObjectException while creating database", exp); } catch (MetaException exp) { throw new HCatException("MetaException while creating database", exp); } catch (TException exp) { throw new ConnectionFailureException( "TException while creating database", exp); } }
@Test public void testDatabaseLocation() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String dbName = "locationDB"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); HCatCreateDBDesc dbDesc = HCatCreateDBDesc.create(dbName) .ifNotExists(true).location("/tmp/" + dbName).build(); client.createDatabase(dbDesc); HCatDatabase newDB = client.getDatabase(dbName); assertTrue(newDB.getLocation().matches(".*/tmp/" + dbName)); client.close(); }
/** * Builds the create database descriptor. * * @return An instance of HCatCreateDBDesc * @throws HCatException */ public HCatCreateDBDesc build() throws HCatException { if (this.dbName == null) { throw new HCatException("Database name cannot be null."); } HCatCreateDBDesc desc = new HCatCreateDBDesc(this.dbName); desc.comment = this.innerComment; desc.locationUri = this.innerLoc; desc.dbProperties = this.innerDBProps; desc.ifNotExits = this.ifNotExists; return desc; }
@Override public void createDatabase(HCatCreateDBDesc dbInfo) throws HCatException { try { hmsClient.createDatabase(dbInfo.toHiveDb()); } catch (AlreadyExistsException exp) { if (!dbInfo.getIfNotExists()) { throw new HCatException( "AlreadyExistsException while creating database", exp); } } catch (InvalidObjectException exp) { throw new HCatException( "InvalidObjectException while creating database", exp); } catch (MetaException exp) { throw new HCatException("MetaException while creating database", exp); } catch (TException exp) { throw new ConnectionFailureException( "TException while creating database", exp); } }
@Test public void testPartitionSchema() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); final String dbName = "myDb"; final String tableName = "myTable"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); List<HCatFieldSchema> columnSchema = Arrays.asList(new HCatFieldSchema("foo", Type.INT, ""), new HCatFieldSchema("bar", Type.STRING, "")); List<HCatFieldSchema> partitionSchema = Arrays.asList(new HCatFieldSchema("dt", Type.STRING, ""), new HCatFieldSchema("grid", Type.STRING, "")); client.createTable(HCatCreateTableDesc.create(dbName, tableName, columnSchema).partCols(partitionSchema).build()); HCatTable table = client.getTable(dbName, tableName); List<HCatFieldSchema> partitionColumns = table.getPartCols(); assertArrayEquals("Didn't get expected partition-schema back from the HCatTable.", partitionSchema.toArray(), partitionColumns.toArray()); client.dropDatabase(dbName, false, HCatClient.DropDBMode.CASCADE); } catch (Exception unexpected) { LOG.error("Unexpected exception!", unexpected); assertTrue("Unexpected exception! " + unexpected.getMessage(), false); } }
/** * Builds the create database descriptor. * * @return An instance of HCatCreateDBDesc * @throws HCatException */ public HCatCreateDBDesc build() throws HCatException { if (this.dbName == null) { throw new HCatException("Database name cannot be null."); } HCatCreateDBDesc desc = new HCatCreateDBDesc(this.dbName); desc.comment = this.innerComment; desc.locationUri = this.innerLoc; desc.dbProperties = this.innerDBProps; desc.ifNotExits = this.ifNotExists; return desc; }
@Override public void createDatabase(HCatCreateDBDesc dbInfo) throws HCatException { try { hmsClient.createDatabase(dbInfo.toHiveDb()); } catch (AlreadyExistsException exp) { if (!dbInfo.getIfNotExists()) { throw new HCatException( "AlreadyExistsException while creating database", exp); } } catch (InvalidObjectException exp) { throw new HCatException( "InvalidObjectException while creating database", exp); } catch (MetaException exp) { throw new HCatException("MetaException while creating database", exp); } catch (TException exp) { throw new ConnectionFailureException( "TException while creating database", exp); } }
@Test public void testUpdateTableSchema() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); final String dbName = "testUpdateTableSchema_DBName"; final String tableName = "testUpdateTableSchema_TableName"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); List<HCatFieldSchema> oldSchema = Arrays.asList(new HCatFieldSchema("foo", Type.INT, ""), new HCatFieldSchema("bar", Type.STRING, "")); client.createTable(HCatCreateTableDesc.create(dbName, tableName, oldSchema).build()); List<HCatFieldSchema> newSchema = Arrays.asList(new HCatFieldSchema("completely", Type.DOUBLE, ""), new HCatFieldSchema("new", Type.STRING, ""), new HCatFieldSchema("fields", Type.STRING, "")); client.updateTableSchema(dbName, tableName, newSchema); assertArrayEquals(newSchema.toArray(), client.getTable(dbName, tableName).getCols().toArray()); client.dropDatabase(dbName, false, HCatClient.DropDBMode.CASCADE); } catch (Exception exception) { LOG.error("Unexpected exception.", exception); assertTrue("Unexpected exception: " + exception.getMessage(), false); } }
/** * Builds the create database descriptor. * * @return An instance of HCatCreateDBDesc * @throws HCatException */ public HCatCreateDBDesc build() throws HCatException { if (this.dbName == null) { throw new HCatException("Database name cannot be null."); } HCatCreateDBDesc desc = new HCatCreateDBDesc(this.dbName); desc.comment = this.innerComment; desc.locationUri = this.innerLoc; desc.dbProperties = this.innerDBProps; desc.ifNotExits = this.ifNotExists; return desc; }
client.createDatabase(HCatCreateDBDesc.create(dbName).build());
client.createDatabase(HCatCreateDBDesc.create(dbName).build()); List<HCatFieldSchema> columnSchema = Arrays.asList(new HCatFieldSchema("foo", Type.INT, ""), new HCatFieldSchema("bar", Type.STRING, ""));
client.createDatabase(HCatCreateDBDesc.create(dbName).build()); List<HCatFieldSchema> columnSchema = Arrays.asList(new HCatFieldSchema("foo", Type.INT, ""), new HCatFieldSchema("bar", Type.STRING, ""));
client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); HCatCreateDBDesc dbDesc = HCatCreateDBDesc.create(dbName) .ifNotExists(true).build(); client.createDatabase(dbDesc);
client.dropDatabase(db, true, HCatClient.DropDBMode.CASCADE); HCatCreateDBDesc dbDesc = HCatCreateDBDesc.create(db).ifNotExists(false) .build(); client.createDatabase(dbDesc);
client.createDatabase(HCatCreateDBDesc.create(dbName).ifNotExists(false).build());
@Test public void testDropDatabaseCommand() throws HCatException { String dbName = "cmd_testdb"; int evid = 999; Command testCmd = new DropDatabaseCommand(dbName, evid); assertEquals(evid,testCmd.getEventId()); assertEquals(1, testCmd.get().size()); assertEquals(true,testCmd.isRetriable()); assertEquals(false,testCmd.isUndoable()); CommandTestUtils.testCommandSerialization(testCmd); client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).ifNotExists(false).build()); HCatDatabase db = client.getDatabase(dbName); assertNotNull(db); LOG.info("About to run :"+testCmd.get().get(0)); driver.run(testCmd.get().get(0)); Exception onfe = null; try { HCatDatabase db_del = client.getDatabase(dbName); } catch (Exception e) { onfe = e; } assertNotNull(onfe); assertTrue(onfe instanceof ObjectNotFoundException); }
client.createDatabase(HCatCreateDBDesc.create(dbName).ifNotExists(false).build());