private void cleanupTbl(String dbName, String tblName, String typeName) throws NoSuchObjectException, MetaException, TException, InvalidOperationException { msc.dropTable(dbName, tblName); msc.dropType(typeName); }
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); } }
@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); }
@Test public void testSimpleTypeApi() throws Exception { try { client.dropType(ColumnType.INT_TYPE_NAME); Type typ1 = new Type(); typ1.setName(ColumnType.INT_TYPE_NAME); boolean ret = client.createType(typ1); assertTrue("Unable to create type", ret); Type typ1_2 = client.getType(ColumnType.INT_TYPE_NAME); assertNotNull(typ1_2); assertEquals(typ1.getName(), typ1_2.getName()); ret = client.dropType(ColumnType.INT_TYPE_NAME); assertTrue("unable to drop type integer", ret); boolean exceptionThrown = false; try { client.getType(ColumnType.INT_TYPE_NAME); } catch (NoSuchObjectException e) { exceptionThrown = true; } assertTrue("Expected NoSuchObjectException", exceptionThrown); } catch (Exception e) { System.err.println(StringUtils.stringifyException(e)); System.err.println("testSimpleTypeApi() failed."); throw e; } }
@Test public void testComplexTypeApi() throws Exception { try { client.dropType("Person"); assertEquals(typ1.getFields().get(1), typ1_2.getFields().get(1)); client.dropType("Family"); assertEquals(fam.getFields().get(1), fam2.getFields().get(1)); ret = client.dropType("Family"); assertTrue("unable to drop type Family", ret); ret = client.dropType("Person"); assertTrue("unable to drop type Person", ret);
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; }