deniskuzZ commented on code in PR #6925:
URL: https://github.com/apache/hive/pull/6925#discussion_r4742517004


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergCRUD.java:
##########
@@ -761,9 +767,44 @@ public void 
testUpdateStatementWithPartitionAndSchemaEvolution() {
     HiveIcebergTestUtils.validateData(expected, 
HiveIcebergTestUtils.valueForRow(newSchema, objects), 0);
   }
 
+  @Test
+  public void testDeleteFromFilesOfSpecWithDroppedSource() throws IOException {
+    Assume.assumeTrue(formatVersion >= 2 && testTableType == 
TestTableType.HIVE_CATALOG);
+    // Iceberg partition statistics fail once a partition source is dropped
+    shell.setHiveSessionValue("hive.iceberg.stats.source", "metastore");
+    shell.executeStatement(String.format("CREATE EXTERNAL TABLE dropped (id 
int, name string, region string) " +
+        "PARTITIONED BY SPEC (region) STORED BY ICEBERG STORED AS %s 
TBLPROPERTIES ('format-version'='%d')",
+        fileFormat, formatVersion));
+    shell.executeStatement("INSERT INTO dropped VALUES (1, 'a', 'eu'), (2, 
'b', 'us'), (3, 'c', 'eu'), (4, 'd', 'us')");
+    shell.executeStatement("ALTER TABLE dropped SET PARTITION SPEC (bucket(2, 
id))");
+    shell.executeStatement("INSERT INTO dropped VALUES (5, 'e', 'eu'), (6, 
'f', 'us')");
+    shell.executeStatement("ALTER TABLE dropped DROP COLUMN region");
+
+    // deleting from files of the old spec fails before writing; deleting from 
files of the new spec works
+    IllegalArgumentException failure = 
Assert.assertThrows(IllegalArgumentException.class,
+        () -> shell.executeStatement("DELETE FROM dropped WHERE id IN (1, 
5)"));
+    Assert.assertTrue(failure.getMessage(), failure.getMessage().contains(
+        "Cannot delete from the data files of partition spec 0: the source 
column of a partition field was dropped"));
+    Assert.assertEquals(List.of("1:a", "2:b", "3:c", "4:d", "5:e", "6:f"),
+        rows(testTables.loadTable(TableIdentifier.of("default", "dropped"))));
+    shell.executeStatement("DELETE FROM dropped WHERE id IN (5, 6)");
+    Assert.assertEquals(List.of("1:a", "2:b", "3:c", "4:d"),
+        rows(testTables.loadTable(TableIdentifier.of("default", "dropped"))));
+  }
+
+  // reads with Iceberg: Hive cannot plan a query once a partition source is 
dropped

Review Comment:
   Iceberg allows dropping the source column of a partition spec that is no 
longer the default: when the schema changes, TableMetadata checks only the 
current spec.
   Iceberg can still read the table, which is how this test reads it. Hive 
fails because of a separate bug that this PR doesn't touch. A scan without a 
filter (SELECT , COUNT()) lists all partitions through 
`IcebergTableUtil.buildPartitionsFilter`, which groups the partition fields of 
every spec by source column name. The dropped column has no name, so it fails 
with an NPE in Collectors.groupingBy.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to