use of org.apache.iceberg.HasTableOperations in project hive by apache.
the class HiveTableTest method testDropTable.
@Test
public void testDropTable() throws IOException {
Table table = catalog.loadTable(TABLE_IDENTIFIER);
GenericRecordBuilder recordBuilder = new GenericRecordBuilder(AvroSchemaUtil.convert(schema, "test"));
List<GenericData.Record> records = Lists.newArrayList(recordBuilder.set("id", 1L).build(), recordBuilder.set("id", 2L).build(), recordBuilder.set("id", 3L).build());
String location1 = table.location().replace("file:", "") + "/data/file1.avro";
try (FileAppender<GenericData.Record> writer = Avro.write(Files.localOutput(location1)).schema(schema).named("test").build()) {
for (GenericData.Record rec : records) {
writer.add(rec);
}
}
String location2 = table.location().replace("file:", "") + "/data/file2.avro";
try (FileAppender<GenericData.Record> writer = Avro.write(Files.localOutput(location2)).schema(schema).named("test").build()) {
for (GenericData.Record rec : records) {
writer.add(rec);
}
}
DataFile file1 = DataFiles.builder(table.spec()).withRecordCount(3).withPath(location1).withFileSizeInBytes(Files.localInput(location2).getLength()).build();
DataFile file2 = DataFiles.builder(table.spec()).withRecordCount(3).withPath(location2).withFileSizeInBytes(Files.localInput(location1).getLength()).build();
// add both data files
table.newAppend().appendFile(file1).appendFile(file2).commit();
// delete file2
table.newDelete().deleteFile(file2.path()).commit();
String manifestListLocation = table.currentSnapshot().manifestListLocation().replace("file:", "");
List<ManifestFile> manifests = table.currentSnapshot().allManifests();
Assert.assertTrue("Drop (table and data) should return true and drop the table", catalog.dropTable(TABLE_IDENTIFIER));
Assert.assertFalse("Table should not exist", catalog.tableExists(TABLE_IDENTIFIER));
Assert.assertFalse("Table data files should not exist", new File(location1).exists());
Assert.assertFalse("Table data files should not exist", new File(location2).exists());
Assert.assertFalse("Table manifest list files should not exist", new File(manifestListLocation).exists());
for (ManifestFile manifest : manifests) {
Assert.assertFalse("Table manifest files should not exist", new File(manifest.path().replace("file:", "")).exists());
}
Assert.assertFalse("Table metadata file should not exist", new File(((HasTableOperations) table).operations().current().metadataFileLocation().replace("file:", "")).exists());
}
use of org.apache.iceberg.HasTableOperations in project hive by apache.
the class TestHiveCommitLocks method before.
@Before
public void before() throws Exception {
Table table = catalog.loadTable(TABLE_IDENTIFIER);
ops = (HiveTableOperations) ((HasTableOperations) table).operations();
String dbName = TABLE_IDENTIFIER.namespace().level(0);
String tableName = TABLE_IDENTIFIER.name();
metadataV1 = ops.current();
table.updateSchema().addColumn("n", Types.IntegerType.get()).commit();
ops.refresh();
metadataV2 = ops.current();
Assert.assertEquals(2, ops.current().schema().columns().size());
spyOps = spy(new HiveTableOperations(overriddenHiveConf, spyCachedClientPool, ops.io(), catalog.name(), dbName, tableName));
}
Aggregations