@Test
  public void testInsertOverwriteOnEmptyV2Table() throws IOException {
    // Create a V2 table with merge-on-read.
    TableIdentifier target = TableIdentifier.of("default", "target");
    Map<String, String> opTypes = ImmutableMap.of(
        TableProperties.DELETE_MODE, HiveIcebergStorageHandler.MERGE_ON_READ,
        TableProperties.MERGE_MODE, HiveIcebergStorageHandler.MERGE_ON_READ,
        TableProperties.UPDATE_MODE, HiveIcebergStorageHandler.MERGE_ON_READ);

    Table table = testTables.createTable(shell, target.name(), HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA,
        fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, 2, opTypes);

    // Insert some data.
    List<Record> newRecords = TestHelper.RecordsBuilder.newInstance(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA)
        .add(3L, "ABC", "DBAK")
        .add(4L, "XYZ", "RDBS")
        .add(5L, "CBO", "HIVE")
        .add(6L, "HADOOP", "HDFS")
        .build();
    shell.executeStatement(testTables.getInsertQuery(newRecords, target, false));

    // Perform some deletes & updates.
    shell.executeStatement("update target set first_name='WXYZ' where customer_id=1");
    shell.executeStatement("delete from target where customer_id%2=0");

    // Change the partition and then insert some more data.
    shell.executeStatement("ALTER TABLE target SET PARTITION SPEC(TRUNCATE(2, last_name))");
    newRecords = TestHelper.RecordsBuilder.newInstance(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA)
        .add(7L, "Mike", "Taylor")
        .add(8L, "Christy", "Hubert")
        .add(9L, "RDBMS", "Talk")
        .add(10L, "Notification", "Hub")
        .add(11L, "Vector", "HDFS")
        .build();
    shell.executeStatement(testTables.getInsertQuery(newRecords, target, false));

    // Perform some deletes & updates.
    shell.executeStatement("update target set first_name='RDBMSV2' where customer_id=9");
    shell.executeStatement("delete from target where customer_id%2=0 AND customer_id>6");

    Table icebergTable = testTables.loadTable(target);
    // There should be some delete files, due to our delete & update operations.
    Assert.assertNotEquals("0", icebergTable.currentSnapshot().summary().get(SnapshotSummary.TOTAL_DELETE_FILES_PROP));

    long preTruncateSnapshotId = icebergTable.currentSnapshot().snapshotId();
    List<Object[]> result =
        shell.executeStatement(String.format("SELECT * FROM %s order by customer_id", target.name()));

    // Truncate the table
    shell.executeStatement("TRUNCATE TABLE target");

    // Do an insert-overwrite and this should be successful because the table is empty.
    shell.executeStatement(
        "INSERT OVERWRITE TABLE target select * from target FOR SYSTEM_VERSION AS OF " + preTruncateSnapshotId);

    HiveIcebergTestUtils.validateData(table,
        HiveIcebergTestUtils.valueForRow(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, result), 0);
    icebergTable = testTables.loadTable(target);

    // There should be no delete files, they should have been merged with the data files
    Assert.assertEquals("0", icebergTable.currentSnapshot().summary().get(SnapshotSummary.TOTAL_DELETE_FILES_PROP));
  }
Testing map-reduce inserts.
@throws IOException If there is an underlying IOException
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergInserts.java