use of org.apache.iceberg.Transaction in project hive by apache.
the class HiveCreateReplaceTableTest method testReplaceTableTxn.
@Test
public void testReplaceTableTxn() {
catalog.createTable(TABLE_IDENTIFIER, SCHEMA, SPEC, tableLocation, Maps.newHashMap());
Assert.assertTrue("Table should exist", catalog.tableExists(TABLE_IDENTIFIER));
Transaction txn = catalog.newReplaceTableTransaction(TABLE_IDENTIFIER, SCHEMA, false);
txn.commitTransaction();
Table table = catalog.loadTable(TABLE_IDENTIFIER);
PartitionSpec v1Expected = PartitionSpec.builderFor(table.schema()).alwaysNull("id", "id").withSpecId(1).build();
Assert.assertEquals("Table should have a spec with one void field", v1Expected, table.spec());
}
use of org.apache.iceberg.Transaction in project hive by apache.
the class HiveCreateReplaceTableTest method testCreateOrReplaceTableTxnTableExists.
@Test
public void testCreateOrReplaceTableTxnTableExists() {
catalog.createTable(TABLE_IDENTIFIER, SCHEMA, SPEC, tableLocation, Maps.newHashMap());
Assert.assertTrue("Table should exist", catalog.tableExists(TABLE_IDENTIFIER));
Transaction txn = catalog.newReplaceTableTransaction(TABLE_IDENTIFIER, SCHEMA, true);
txn.commitTransaction();
Table table = catalog.loadTable(TABLE_IDENTIFIER);
PartitionSpec v1Expected = PartitionSpec.builderFor(table.schema()).alwaysNull("id", "id").withSpecId(1).build();
Assert.assertEquals("Table should have a spec with one void field", v1Expected, table.spec());
}
use of org.apache.iceberg.Transaction in project hive by apache.
the class HiveCreateReplaceTableTest method testCreateTableTxnTableCreatedConcurrently.
@Test
public void testCreateTableTxnTableCreatedConcurrently() {
Assert.assertFalse("Table should not exist", catalog.tableExists(TABLE_IDENTIFIER));
Transaction txn = catalog.newCreateTableTransaction(TABLE_IDENTIFIER, SCHEMA, SPEC, tableLocation, Maps.newHashMap());
// create the table concurrently
catalog.createTable(TABLE_IDENTIFIER, SCHEMA, SPEC);
Assert.assertTrue("Table should be created", catalog.tableExists(TABLE_IDENTIFIER));
AssertHelpers.assertThrows("Create table txn should fail", AlreadyExistsException.class, "Table already exists: hivedb.tbl", txn::commitTransaction);
}
use of org.apache.iceberg.Transaction in project hive by apache.
the class HiveCreateReplaceTableTest method testReplaceTableTxnTableModifiedConcurrently.
@Test
public void testReplaceTableTxnTableModifiedConcurrently() {
Table table = catalog.createTable(TABLE_IDENTIFIER, SCHEMA, SPEC, tableLocation, Maps.newHashMap());
Assert.assertTrue("Table should exist", catalog.tableExists(TABLE_IDENTIFIER));
Transaction txn = catalog.newReplaceTableTransaction(TABLE_IDENTIFIER, SCHEMA, SPEC, false);
// update the table concurrently
table.updateProperties().set("another-prop", "another-value").commit();
txn.updateProperties().set("prop", "value").commit();
txn.commitTransaction();
// the replace should still succeed
table = catalog.loadTable(TABLE_IDENTIFIER);
Assert.assertNull("Table props should be updated", table.properties().get("another-prop"));
Assert.assertEquals("Table props should match", "value", table.properties().get("prop"));
}
use of org.apache.iceberg.Transaction in project hive by apache.
the class TestHiveCatalog method testCreateTableTxnBuilder.
@Test
public void testCreateTableTxnBuilder() throws Exception {
Schema schema = new Schema(required(1, "id", Types.IntegerType.get(), "unique ID"), required(2, "data", Types.StringType.get()));
TableIdentifier tableIdent = TableIdentifier.of(DB_NAME, "tbl");
String location = temp.newFolder("tbl").toString();
try {
Transaction txn = catalog.buildTable(tableIdent, schema).withLocation(location).createTransaction();
txn.commitTransaction();
Table table = catalog.loadTable(tableIdent);
Assert.assertEquals(location, table.location());
Assert.assertEquals(2, table.schema().columns().size());
Assert.assertTrue(table.spec().isUnpartitioned());
} finally {
catalog.dropTable(tableIdent);
}
}
Aggregations