@Override public void dropTable(String dbname, String name, boolean deleteData, boolean ignoreUnknownTab, boolean ifPurge) throws TException { dropTable(getDefaultCatalog(conf), dbname, name, deleteData, ignoreUnknownTab, ifPurge); }
private void dropTestTables() { try { client.dropTable(dbName, tblName); } catch (TException e) { // ignored } }
@Override public void dropTable(String dbname, String name, boolean deleteData, boolean ignoreUnknownTab) throws MetaException, TException, NoSuchObjectException, UnsupportedOperationException { dropTable(getDefaultCatalog(conf), dbname, name, deleteData, ignoreUnknownTab, null); }
@Override public void dropTable(String dbname, String name) throws TException { dropTable(getDefaultCatalog(conf), dbname, name, true, true, null); }
@Override public void dropTable(String catName, String dbName, String tableName, boolean deleteData, boolean ignoreUnknownTable, boolean ifPurge) throws TException { //build new environmentContext with ifPurge; EnvironmentContext envContext = null; if(ifPurge){ Map<String, String> warehouseOptions; warehouseOptions = new HashMap<>(); warehouseOptions.put("ifPurge", "TRUE"); envContext = new EnvironmentContext(warehouseOptions); } dropTable(catName, dbName, tableName, deleteData, ignoreUnknownTable, envContext); }
private void silentDropDatabase(String dbName) throws MetaException, TException { try { for (String tableName : msc.getTables(dbName, "*")) { msc.dropTable(dbName, tableName); } } catch (NoSuchObjectException e) { } }
private void cleanupTbl(String dbName, String tblName, String typeName) throws NoSuchObjectException, MetaException, TException, InvalidOperationException { msc.dropTable(dbName, tblName); msc.dropType(typeName); }
@Override protected void tearDown() throws Exception { try { super.tearDown(); client.dropTable(dbName, tblName); client.dropDatabase(dbName); client.close(); } catch (Throwable e) { LOG.error("Unable to close metastore", e); throw new Exception(e); } }
@After public void deleteTable() throws Exception { try { String databaseName = (dbName == null) ? Warehouse.DEFAULT_DATABASE_NAME : dbName; client.dropTable(databaseName, tableName); // in case of external table, drop the table contents as well if (isTableExternal() && (externalTableLocation != null)) { if (fs.exists(new Path(externalTableLocation))) { fs.delete(new Path(externalTableLocation), true); } } } catch (Exception e) { e.printStackTrace(); throw e; } }
private static void silentDropDatabase(String dbName) throws TException { try { for (String tableName : client.getTables(dbName, "*")) { client.dropTable(dbName, tableName); } client.dropDatabase(dbName); } catch (NoSuchObjectException|InvalidOperationException e) { // NOP } }
private void cleanUp(String dbName, String tableName, String typeName) throws Exception { if(dbName != null && tableName != null) { client.dropTable(dbName, tableName); } if(dbName != null) { silentDropDatabase(dbName); } if(typeName != null) { client.dropType(typeName); } }
private static void silentDropDatabase(String dbName) throws TException { try { for (String tableName : client.getTables(dbName, "*")) { client.dropTable(dbName, tableName); } client.dropDatabase(dbName); } catch (NoSuchObjectException ignore) { } catch (InvalidOperationException ignore) { } }
private static void initalizeTables() throws Exception { for (String table : tableNames) { try { if (hmsc.getTable(DATABASE, table) != null) { hmsc.dropTable(DATABASE, table); } } catch (NoSuchObjectException ignored) { } } for (int i = 0; i < tableNames.length; i++) { createTable(tableNames[i], tablePerms[i]); } }
@Test public void testDropTable() throws Throwable { // create a table with multiple partitions String dbName = "compdb"; String tblName = "comptbl"; String typeName = "Person"; cleanUp(dbName, tblName, typeName); List<List<String>> values = new ArrayList<>(); values.add(makeVals("2008-07-01 14:13:12", "14")); values.add(makeVals("2008-07-01 14:13:12", "15")); values.add(makeVals("2008-07-02 14:13:12", "15")); values.add(makeVals("2008-07-03 14:13:12", "151")); createMultiPartitionTableSchema(dbName, tblName, typeName, values); client.dropTable(dbName, tblName); client.dropType(typeName); boolean exceptionThrown = false; try { client.getTable(dbName, tblName); } catch(Exception e) { assertEquals("table should not have existed", NoSuchObjectException.class, e.getClass()); exceptionThrown = true; } assertTrue("Table " + tblName + " should have been dropped ", exceptionThrown); }
private void createTestTables() throws TException { if (client.tableExists(dbName, tblName)) { LOG.info("Table is already existing. Dropping it and then recreating"); client.dropTable(dbName, tblName);
private void createTable(String dbName, String tableName) throws Exception { String databaseName = (dbName == null) ? Warehouse.DEFAULT_DATABASE_NAME : dbName; try { msc.dropTable(databaseName, tableName); } catch (Exception e) { } // can fail with NoSuchObjectException Table tbl = new Table(); tbl.setDbName(databaseName); tbl.setTableName(tableName); tbl.setTableType("MANAGED_TABLE"); StorageDescriptor sd = new StorageDescriptor(); sd.setCols(getTableColumns()); tbl.setPartitionKeys(getPartitionKeys()); tbl.setSd(sd); sd.setBucketCols(new ArrayList<String>(2)); 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.getSerdeInfo().setSerializationLib(ColumnarSerDe.class.getName()); sd.setInputFormat(RCFileInputFormat.class.getName()); sd.setOutputFormat(RCFileOutputFormat.class.getName()); Map<String, String> tableParams = new HashMap<String, String>(); tbl.setParameters(tableParams); msc.createTable(tbl); }
private Table getTable(String dbName, String tblName, String typeName) throws NoSuchObjectException, MetaException, TException, AlreadyExistsException, InvalidObjectException { msc.dropTable(dbName, tblName); silentDropDatabase(dbName); msc.dropType(typeName); Type typ1 = new Type(); typ1.setName(typeName); typ1.setFields(new ArrayList<FieldSchema>(1)); typ1.getFields().add(new FieldSchema("name", serdeConstants.STRING_TYPE_NAME, "")); msc.createType(typ1); Table tbl = new Table(); tbl.setDbName(dbName); tbl.setTableName(tblName); StorageDescriptor sd = new StorageDescriptor(); sd.setSerdeInfo(new SerDeInfo()); sd.getSerdeInfo().setName(tblName); sd.getSerdeInfo().setParameters(new HashMap<String, String>()); sd.getSerdeInfo().setSerializationLib(LazySimpleSerDe.class.getName()); sd.setInputFormat(HiveInputFormat.class.getName()); sd.setOutputFormat(HiveOutputFormat.class.getName()); tbl.setSd(sd); sd.setCols(typ1.getFields()); sd.setSerdeInfo(new SerDeInfo()); return tbl; }
@Test public void testCreateTableSettingId() throws Exception { String dbName = "createDb"; String tblName = "createTbl"; client.dropTable(dbName, tblName); silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName) .create(client, conf); Table table = new TableBuilder() .setDbName(dbName) .setTableName(tblName) .addCol("foo", "string") .addCol("bar", "string") .build(conf); table.setId(1); try { client.createTable(table); Assert.fail("An error should happen when setting the id" + " to create a table"); } catch (InvalidObjectException e) { Assert.assertTrue(e.getMessage().contains("Id shouldn't be set")); Assert.assertTrue(e.getMessage().contains(tblName)); } }
@Test(expected = MetaException.class) public void testGetSchemaWithNoClassDefFoundError() throws TException { String dbName = "testDb"; String tblName = "testTable"; client.dropTable(dbName, tblName); silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName) .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) .setTableName(tblName) .addCol("name", ColumnType.STRING_TYPE_NAME, "") .setSerdeLib("no.such.class") .create(client, conf); client.getSchema(dbName, tblName); }
@Test public void testCreateAndGetTableWithDriver() throws Exception { String dbName = "createDb"; String tblName = "createTbl"; client.dropTable(dbName, tblName); silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName) .create(client, conf); createTable(dbName, tblName); Table tblRead = client.getTable(dbName, tblName); Assert.assertTrue(tblRead.isSetId()); long firstTableId = tblRead.getId(); createTable(dbName, tblName + "_2"); Table tblRead2 = client.getTable(dbName, tblName + "_2"); Assert.assertTrue(tblRead2.isSetId()); Assert.assertNotEquals(firstTableId, tblRead2.getId()); }