use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergTruncateTable method testTruncateTableWithPartitionSpec.
@Test
public void testTruncateTableWithPartitionSpec() throws IOException, TException, InterruptedException {
// Create an Iceberg table with some record and try to run a truncate table command with partition
// spec. The command should fail as the table is unpartitioned in Hive. Then check if the
// initial data and the table statistics are not changed.
String databaseName = "default";
String tableName = "customers";
TableIdentifier identifier = TableIdentifier.of(databaseName, tableName);
Table icebergTable = testTables.createTable(shell, tableName, HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
shell.executeStatement("ALTER TABLE " + identifier + " SET TBLPROPERTIES('external.table.purge'='true')");
shell.executeStatement("ANALYZE TABLE " + identifier + " COMPUTE STATISTICS");
AssertHelpers.assertThrows("should throw exception", IllegalArgumentException.class, "Using partition spec in query is unsupported for non-native table backed by: " + "org.apache.iceberg.mr.hive.HiveIcebergStorageHandler", () -> {
shell.executeStatement("TRUNCATE " + identifier + " PARTITION (customer_id=1)");
});
List<Object[]> rows = shell.executeStatement("SELECT * FROM " + identifier);
HiveIcebergTestUtils.validateData(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, HiveIcebergTestUtils.valueForRow(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, rows), 0);
icebergTable = testTables.loadTable(TableIdentifier.of(databaseName, tableName));
validateBasicStats(icebergTable, databaseName, tableName);
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergTruncateTable method testTruncateEmptyTable.
@Test
public void testTruncateEmptyTable() throws IOException, TException, InterruptedException {
// Create an empty Iceberg table and execute a truncate table command on it.
String databaseName = "default";
String tableName = "customers";
TableIdentifier identifier = TableIdentifier.of(databaseName, tableName);
Table icebergTable = testTables.createTable(shell, tableName, HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, fileFormat, null);
// Set the 'external.table.purge' table property on the table
String alterTableCommand = "ALTER TABLE " + identifier + " SET TBLPROPERTIES('external.table.purge'='true')";
shell.executeStatement(alterTableCommand);
shell.executeStatement("ANALYZE TABLE " + identifier + " COMPUTE STATISTICS");
shell.executeStatement("TRUNCATE " + identifier);
icebergTable = testTables.loadTable(TableIdentifier.of(databaseName, tableName));
Map<String, String> summary = icebergTable.currentSnapshot().summary();
for (String key : STATS_MAPPING.values()) {
Assert.assertEquals("0", summary.get(key));
}
List<Object[]> rows = shell.executeStatement("SELECT * FROM " + identifier);
Assert.assertEquals(0, rows.size());
validateBasicStats(icebergTable, databaseName, tableName);
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergTruncateTable method testTruncateTableExternalPurgeFalse.
@Test
public void testTruncateTableExternalPurgeFalse() throws IOException, TException, InterruptedException {
// Create an Iceberg table with some records in it and set the 'external.table.purge' table property
// to false and try to run a truncate table command on it. The command should fail with a SemanticException.
// Then check if the data is not deleted from the table and also the statistics are not changed.
String databaseName = "default";
String tableName = "customers";
TableIdentifier identifier = TableIdentifier.of(databaseName, tableName);
Table icebergTable = testTables.createTable(shell, tableName, HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
shell.executeStatement("ALTER TABLE " + identifier + " SET TBLPROPERTIES('external.table.purge'='false')");
shell.executeStatement("ANALYZE TABLE " + identifier + " COMPUTE STATISTICS");
AssertHelpers.assertThrows("should throw exception", IllegalArgumentException.class, "Cannot truncate non-managed table", () -> {
shell.executeStatement("TRUNCATE " + identifier);
});
List<Object[]> rows = shell.executeStatement("SELECT * FROM " + identifier);
HiveIcebergTestUtils.validateData(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, HiveIcebergTestUtils.valueForRow(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, rows), 0);
icebergTable = testTables.loadTable(TableIdentifier.of(databaseName, tableName));
validateBasicStats(icebergTable, databaseName, tableName);
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStatistics method testStatsWithInsertOverwrite.
@Test
public void testStatsWithInsertOverwrite() {
TableIdentifier identifier = TableIdentifier.of("default", "customers");
shell.setHiveSessionValue(HiveConf.ConfVars.HIVESTATSAUTOGATHER.varname, true);
testTables.createTable(shell, identifier.name(), HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, PartitionSpec.unpartitioned(), fileFormat, ImmutableList.of());
String insert = testTables.getInsertQuery(HiveIcebergStorageHandlerTestUtils.OTHER_CUSTOMER_RECORDS, identifier, true);
shell.executeStatement(insert);
checkColStat(identifier.name(), "customer_id", true);
checkColStatMinMaxValue(identifier.name(), "customer_id", 3, 5);
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testCreateTableWithNotSupportedTypesWithAutoConversion.
@Test
public void testCreateTableWithNotSupportedTypesWithAutoConversion() {
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());
shell.setHiveSessionValue(InputFormatConfig.SCHEMA_AUTO_CONVERSION, "true");
for (String notSupportedType : notSupportedTypes.keySet()) {
shell.executeStatement("CREATE EXTERNAL TABLE not_supported_types (not_supported " + notSupportedType + ") " + "STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
org.apache.iceberg.Table icebergTable = testTables.loadTable(identifier);
Assert.assertEquals(notSupportedTypes.get(notSupportedType), icebergTable.schema().columns().get(0).type());
shell.executeStatement("DROP TABLE not_supported_types");
}
}
Aggregations