@Test public void testTruncateTableUnpartitioned() throws Exception { // Unpartitioned table Path dataFile = new Path(testTables[0].getSd().getLocation() + "/dataFile"); client.truncateTable(testTables[0].getDbName(), testTables[0].getTableName(), null); Assert.assertTrue("Location should exist", metaStore.isPathExists(new Path(testTables[0].getSd().getLocation()))); Assert.assertFalse("DataFile should be removed", metaStore.isPathExists(dataFile)); }
@Test public void testTruncateTablePartitioned() throws Exception { // Partitioned table - delete specific partitions a0, a2 List<String> partitionsToDelete = new ArrayList<>(); partitionsToDelete.add("test_part_col=a0"); partitionsToDelete.add("test_part_col=a2"); client.truncateTable(partitionedTable.getDbName(), partitionedTable.getTableName(), partitionsToDelete); Assert.assertTrue("Location should exist", metaStore.isPathExists(new Path(testTables[0].getSd().getLocation()))); List<Partition> partitions = client.listPartitions(partitionedTable.getDbName(), partitionedTable.getTableName(), (short)-1); for(Partition partition : partitions) { Path dataFile = new Path(partition.getSd().getLocation() + "/dataFile"); if (partition.getValues().contains("a0") || partition.getValues().contains("a2")) { // a0, a2 should be empty Assert.assertFalse("DataFile should be removed", metaStore.isPathExists(dataFile)); } else { // Others (a1) should be kept Assert.assertTrue("DataFile should not be removed", metaStore.isPathExists(dataFile)); } } }
@Test public void truncateTableBogusCatalog() throws TException { try { List<String> partNames = client.listPartitionNames(partitionedTable.getDbName(), partitionedTable.getTableName(), (short) -1); client.truncateTable("nosuch", partitionedTable.getDbName(), partitionedTable.getTableName(), partNames); Assert.fail(); // For reasons I don't understand and am too lazy to debug at the moment the // NoSuchObjectException gets swallowed by a TApplicationException in remote mode. } catch (TApplicationException|NoSuchObjectException e) { //NOP } }
@Test public void testTruncateTablePartitionedDeleteAll() throws Exception { // Partitioned table - delete all client.truncateTable(partitionedTable.getDbName(), partitionedTable.getTableName(), null); Assert.assertTrue("Location should exist", metaStore.isPathExists(new Path(testTables[0].getSd().getLocation()))); List<Partition> partitions = client.listPartitions(partitionedTable.getDbName(), partitionedTable.getTableName(), (short)-1); for(Partition partition : partitions) { Path dataFile = new Path(partition.getSd().getLocation() + "/dataFile"); Assert.assertFalse("Every dataFile should be removed", metaStore.isPathExists(dataFile)); } }
? null : getPartitionNames(table.getDbName(), table.getTableName(), partSpec, (short) -1)); if (snapshot == null) { getMSC().truncateTable(table.getDbName(), table.getTableName(), partNames); } else { getMSC().truncateTable(table.getDbName(), table.getTableName(), partNames, snapshot.getValidWriteIdList(), snapshot.getWriteId());
for (String partVal : partVals) partNames.add("pcol1=" + partVal); client.truncateTable(dbName, tableNames[0], partNames);
for (String partVal : partVals) partNames.add("pcol1=" + partVal); client.truncateTable(catName, dbName, tableNames[0], partNames); client.truncateTable(DEFAULT_DATABASE_NAME, tableNames[0], partNames); Assert.fail(); } catch (NoSuchObjectException|TApplicationException e) {