use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testIcebergHMSPropertiesTranslation.
@Test
public void testIcebergHMSPropertiesTranslation() throws Exception {
Assume.assumeTrue("Iceberg - HMS property translation is only relevant for HiveCatalog", testTableType == TestTables.TestTableType.HIVE_CATALOG);
TableIdentifier identifier = TableIdentifier.of("default", "customers");
// Create HMS table with with a property to be translated
shell.executeStatement(String.format("CREATE EXTERNAL TABLE default.customers " + "STORED BY ICEBERG " + "TBLPROPERTIES ('%s'='%s', '%s'='%s', '%s'='%s')", InputFormatConfig.TABLE_SCHEMA, SchemaParser.toJson(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA), InputFormatConfig.PARTITION_SPEC, PartitionSpecParser.toJson(SPEC), InputFormatConfig.EXTERNAL_TABLE_PURGE, "false"));
// Check that HMS table prop was translated to equivalent Iceberg prop (purge -> gc.enabled)
org.apache.iceberg.Table icebergTable = testTables.loadTable(identifier);
Assert.assertEquals("false", icebergTable.properties().get(GC_ENABLED));
Assert.assertNull(icebergTable.properties().get(InputFormatConfig.EXTERNAL_TABLE_PURGE));
// Change Iceberg prop
icebergTable.updateProperties().set(GC_ENABLED, "true").commit();
// Check that Iceberg prop was translated to equivalent HMS prop (gc.enabled -> purge)
Map<String, String> hmsParams = shell.metastore().getTable("default", "customers").getParameters();
Assert.assertEquals("true", hmsParams.get(InputFormatConfig.EXTERNAL_TABLE_PURGE));
Assert.assertNull(hmsParams.get(GC_ENABLED));
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testCreateTableWithFormatV2ThroughTableProperty.
@Test
public void testCreateTableWithFormatV2ThroughTableProperty() {
TableIdentifier identifier = TableIdentifier.of("default", "customers");
shell.executeStatement("CREATE EXTERNAL TABLE customers (id int, name string) STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + " TBLPROPERTIES ('" + InputFormatConfig.CATALOG_NAME + "'='" + testTables.catalogName() + "', " + "'" + TableProperties.FORMAT_VERSION + "'='2')");
org.apache.iceberg.Table icebergTable = testTables.loadTable(identifier);
Assert.assertEquals("should create table using format v2", 2, ((BaseTable) icebergTable).operations().current().formatVersion());
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testCreateTableWithUnpartitionedSpec.
@Test
public void testCreateTableWithUnpartitionedSpec() {
TableIdentifier identifier = TableIdentifier.of("default", "customers");
// We need the location for HadoopTable based tests only
shell.executeStatement("CREATE EXTERNAL TABLE customers " + "STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + "TBLPROPERTIES ('" + InputFormatConfig.TABLE_SCHEMA + "'='" + SchemaParser.toJson(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA) + "', " + "'" + InputFormatConfig.PARTITION_SPEC + "'='" + PartitionSpecParser.toJson(PartitionSpec.unpartitioned()) + "', " + "'" + InputFormatConfig.CATALOG_NAME + "'='" + testTables.catalogName() + "')");
// Check the Iceberg table partition data
org.apache.iceberg.Table icebergTable = testTables.loadTable(identifier);
Assert.assertEquals(SPEC, icebergTable.spec());
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testCreateTableWithNotSupportedTypes.
@Test
public void testCreateTableWithNotSupportedTypes() {
TableIdentifier identifier = TableIdentifier.of("default", "not_supported_types");
// Can not create INTERVAL types from normal create table, so leave them out from this test
Map<String, Type> notSupportedTypes = ImmutableMap.of("TINYINT", Types.IntegerType.get(), "SMALLINT", Types.IntegerType.get(), "VARCHAR(1)", Types.StringType.get(), "CHAR(1)", Types.StringType.get());
for (String notSupportedType : notSupportedTypes.keySet()) {
AssertHelpers.assertThrows("should throw exception", IllegalArgumentException.class, "Unsupported Hive type", () -> {
shell.executeStatement("CREATE EXTERNAL TABLE not_supported_types " + "(not_supported " + notSupportedType + ") " + "STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
});
}
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testAlterTableProperties.
@Test
public void testAlterTableProperties() {
TableIdentifier identifier = TableIdentifier.of("default", "customers");
shell.executeStatement("CREATE EXTERNAL TABLE customers (" + "t_int INT, " + "t_string STRING) " + "STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
String propKey = "dummy";
String propValue = "dummy_val";
// add new property
shell.executeStatement(String.format("ALTER TABLE customers SET TBLPROPERTIES('%s'='%s')", propKey, propValue));
// Check the Iceberg table parameters
Table icebergTable = testTables.loadTable(identifier);
Assert.assertTrue(icebergTable.properties().containsKey(propKey));
Assert.assertEquals(icebergTable.properties().get(propKey), propValue);
// update existing property
propValue = "new_dummy_val";
shell.executeStatement(String.format("ALTER TABLE customers SET TBLPROPERTIES('%s'='%s')", propKey, propValue));
// Check the Iceberg table parameters
icebergTable.refresh();
Assert.assertTrue(icebergTable.properties().containsKey(propKey));
Assert.assertEquals(icebergTable.properties().get(propKey), propValue);
// remove existing property
shell.executeStatement(String.format("ALTER TABLE customers UNSET TBLPROPERTIES('%s'='%s')", propKey, propValue));
// Check the Iceberg table parameters
icebergTable.refresh();
Assert.assertFalse(icebergTable.properties().containsKey(propKey));
}
Aggregations