Search in sources :

Example 61 with TableIdentifier

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);
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Table(org.apache.iceberg.Table) Test(org.junit.Test)

Example 62 with TableIdentifier

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);
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Table(org.apache.iceberg.Table) Test(org.junit.Test)

Example 63 with TableIdentifier

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);
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Table(org.apache.iceberg.Table) Test(org.junit.Test)

Example 64 with TableIdentifier

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);
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Test(org.junit.Test)

Example 65 with TableIdentifier

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");
    }
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Type(org.apache.iceberg.types.Type) Table(org.apache.iceberg.Table) Test(org.junit.Test)

Aggregations

TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)87 Test (org.junit.Test)69 Table (org.apache.iceberg.Table)56 PartitionSpec (org.apache.iceberg.PartitionSpec)27 Schema (org.apache.iceberg.Schema)25 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)16 BaseTable (org.apache.iceberg.BaseTable)15 UpdateSchema (org.apache.iceberg.UpdateSchema)15 List (java.util.List)13 NoSuchTableException (org.apache.iceberg.exceptions.NoSuchTableException)13 ArrayList (java.util.ArrayList)11 ImmutableList (org.apache.iceberg.relocated.com.google.common.collect.ImmutableList)11 IOException (java.io.IOException)10 Map (java.util.Map)10 Types (org.apache.iceberg.types.Types)10 HashMap (java.util.HashMap)9 Path (org.apache.hadoop.fs.Path)9 TableProperties (org.apache.iceberg.TableProperties)9 Collections (java.util.Collections)8 Properties (java.util.Properties)8