kasakrisz commented on code in PR #6925:
URL: https://github.com/apache/hive/pull/6925#discussion_r4740856294
##########
iceberg/iceberg-handler/src/test/queries/positive/query_iceberg_virtualcol.q:
##########
@@ -4,11 +4,11 @@ insert into tbl_ice values (1, 'one', 50), (2, 'two', 50),
(3, 'three', 50), (4,
select tbl_ice.ROW__POSITION from tbl_ice;
-select a, c, tbl_ice.PARTITION__SPEC__ID, tbl_ice.PARTITION__HASH,
tbl_ice.ROW__POSITION from tbl_ice
Review Comment:
Can PARTITION__KEY be projected?
##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/view/materialized/alter/rebuild/NonNativeAcidMaterializedViewASTBuilder.java:
##########
@@ -53,14 +55,24 @@ public void appendDeleteSelectNodes(ASTNode selectNode,
String tableName) {
selectedColumns.add(selectExpr.getChild(selectExpr.getChildCount() -
1).getText());
}
- for (FieldSchema fieldSchema :
mvTable.getStorageHandler().acidSelectColumns(mvTable,
Context.Operation.DELETE)) {
- if (!selectedColumns.contains(fieldSchema.getName())) {
+ for (String column : deleteSelectColumns()) {
+ if (!selectedColumns.contains(column)) {
ParseDriver.adaptor.addChild(selectNode, wrapIntoSelExpr(
- createQualifiedColumnNode(tableName, fieldSchema.getName())));
+ createQualifiedColumnNode(tableName, column)));
}
}
}
+ // the incremental rebuild is a MERGE; in merge-on-read, its deletes select
the virtual columns only
+ private List<String> deleteSelectColumns() {
Review Comment:
Could you please check if the changes in this file work with the changes
introduced by #6986?
##########
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:
Shouldn't this be unsupported by Hive, since, based on the comment, it can't
read such tables?
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/sql/NonNativeAcidMultiInsertSqlGenerator.java:
##########
@@ -59,8 +59,7 @@ private void appendAcidSelectColumns(
List<FieldSchema> acidSelectColumns =
targetTable.getStorageHandler().acidSelectColumns(targetTable, operation);
for (FieldSchema fieldSchema : acidSelectColumns) {
boolean deletedRowId = markRowIdAsDeleted &&
fieldSchema.equals(targetTable.getStorageHandler().getRowId());
- String identifier = deletedRowId ?
- deletedRowIdExpr :
HiveUtils.unparseIdentifier(fieldSchema.getName(), this.conf);
+ String identifier = selectExpr(fieldSchema.getName(), deletedRowId,
deletedRowIdExpr);
Review Comment:
nit: I prefer the original code because the method has two distinct return
types based on its boolean parameter.
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/sql/NonNativeAcidMultiInsertSqlGenerator.java:
##########
@@ -69,14 +68,18 @@ private void appendAcidSelectColumns(
if (!markRowIdAsDeleted) {
queryStr.append(" AS ");
}
- String prefixedIdentifier = deletedRowId ?
- deletedRowIdExpr : HiveUtils.unparseIdentifier(deletePrefix +
fieldSchema.getName(), this.conf);
+ String prefixedIdentifier = selectExpr(deletePrefix +
fieldSchema.getName(), deletedRowId, deletedRowIdExpr);
Review Comment:
nit: I prefer the original code because the method has two distinct return
types based on its boolean parameter.
##########
iceberg/iceberg-handler/src/test/queries/positive/query_iceberg_virtualcol.q:
##########
@@ -4,11 +4,11 @@ insert into tbl_ice values (1, 'one', 50), (2, 'two', 50),
(3, 'three', 50), (4,
select tbl_ice.ROW__POSITION from tbl_ice;
-select a, c, tbl_ice.PARTITION__SPEC__ID, tbl_ice.PARTITION__HASH,
tbl_ice.ROW__POSITION from tbl_ice
-order by tbl_ice.PARTITION__HASH, tbl_ice.ROW__POSITION desc;
Review Comment:
Is it possible to order by PARTITION__KEY?
--
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]