This is an automated email from the ASF dual-hosted git repository.
ayushsaxena pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 77ca0350911 HIVE-28172: Iceberg: Truncate should work for V1 tables
with partition evolution. (#5179). (Ayush Saxena, reviewed by Sourabh Badhya)
77ca0350911 is described below
commit 77ca03509112655e81d3e56b71c938d548da8b7c
Author: Ayush Saxena <[email protected]>
AuthorDate: Thu Apr 4 14:19:13 2024 +0530
HIVE-28172: Iceberg: Truncate should work for V1 tables with partition
evolution. (#5179). (Ayush Saxena, reviewed by Sourabh Badhya)
---
.../iceberg/mr/hive/HiveIcebergStorageHandler.java | 6 ---
...cate_table_partition_spec_with_part_evolution.q | 6 ---
.../iceberg_truncate_partition_with_evolution.q | 10 ++++
..._table_partition_spec_with_part_evolution.q.out | 32 ------------
...iceberg_truncate_partition_with_evolution.q.out | 59 ++++++++++++++++++++++
5 files changed, 69 insertions(+), 44 deletions(-)
diff --git
a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java
b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java
index a71fd80a316..f704a5b81c3 100644
---
a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java
+++
b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java
@@ -1832,12 +1832,6 @@ public class HiveIcebergStorageHandler implements
HiveStoragePredicateHandler, H
break;
}
}
-
- boolean isV2Table = IcebergTableUtil.isV2Table(hmsTable.getParameters());
- if (!result && !isV2Table) {
- throw new SemanticException("Truncate conversion to delete is not
possible since its not an Iceberg V2 table." +
- " Consider converting the table to Iceberg's V2 format
specification.");
- }
return result;
}
diff --git
a/iceberg/iceberg-handler/src/test/queries/negative/truncate_table_partition_spec_with_part_evolution.q
b/iceberg/iceberg-handler/src/test/queries/negative/truncate_table_partition_spec_with_part_evolution.q
deleted file mode 100644
index 6864149545c..00000000000
---
a/iceberg/iceberg-handler/src/test/queries/negative/truncate_table_partition_spec_with_part_evolution.q
+++ /dev/null
@@ -1,6 +0,0 @@
--- Truncate table on an partitioned Iceberg V1 table with partition evolution
must result in an exception since deletes are not possible on Iceberg V1 table.
-create external table test_truncate_part_evolution (id int, value string)
stored by iceberg stored as orc tblproperties ('format-version'='1');
-insert into test_truncate_part_evolution values (1,
'one'),(2,'two'),(3,'three'),(4,'four'),(5,'five');
-alter table test_truncate_part_evolution set partition spec(id);
-alter table test_truncate_part_evolution set
tblproperties('external.table.purge'='true');
-truncate test_truncate_part_evolution partition(id=1);
diff --git
a/iceberg/iceberg-handler/src/test/queries/positive/iceberg_truncate_partition_with_evolution.q
b/iceberg/iceberg-handler/src/test/queries/positive/iceberg_truncate_partition_with_evolution.q
index 0f3a7524b91..d19f34c4524 100644
---
a/iceberg/iceberg-handler/src/test/queries/positive/iceberg_truncate_partition_with_evolution.q
+++
b/iceberg/iceberg-handler/src/test/queries/positive/iceberg_truncate_partition_with_evolution.q
@@ -106,9 +106,19 @@ truncate table test_ice_double_date partition (a =
33678499.377556738, b = '2022
select * from test_ice_double_date;
select `partition` from default.test_ice_double_date.partitions;
+-- create a v1 table
+create external table test_truncate_part_evolution (id int, value string)
stored by iceberg stored as orc tblproperties ('format-version'='1');
+insert into test_truncate_part_evolution values (1,
'one'),(2,'two'),(3,'three'),(4,'four'),(5,'five');
+alter table test_truncate_part_evolution set partition spec(id);
+alter table test_truncate_part_evolution set
tblproperties('external.table.purge'='true');
+truncate test_truncate_part_evolution partition(id=1);
+
+select * from test_truncate_part_evolution;
+
drop table test_ice_int;
drop table test_ice_bigint;
drop table test_ice_str;
drop table test_ice_date;
drop table test_ice_double;
drop table test_ice_double_date;
+drop table test_truncate_part_evolution;
diff --git
a/iceberg/iceberg-handler/src/test/results/negative/truncate_table_partition_spec_with_part_evolution.q.out
b/iceberg/iceberg-handler/src/test/results/negative/truncate_table_partition_spec_with_part_evolution.q.out
deleted file mode 100644
index 241854bbea4..00000000000
---
a/iceberg/iceberg-handler/src/test/results/negative/truncate_table_partition_spec_with_part_evolution.q.out
+++ /dev/null
@@ -1,32 +0,0 @@
-PREHOOK: query: create external table test_truncate_part_evolution (id int,
value string) stored by iceberg stored as orc tblproperties
('format-version'='1')
-PREHOOK: type: CREATETABLE
-PREHOOK: Output: database:default
-PREHOOK: Output: default@test_truncate_part_evolution
-POSTHOOK: query: create external table test_truncate_part_evolution (id int,
value string) stored by iceberg stored as orc tblproperties
('format-version'='1')
-POSTHOOK: type: CREATETABLE
-POSTHOOK: Output: database:default
-POSTHOOK: Output: default@test_truncate_part_evolution
-PREHOOK: query: insert into test_truncate_part_evolution values (1,
'one'),(2,'two'),(3,'three'),(4,'four'),(5,'five')
-PREHOOK: type: QUERY
-PREHOOK: Input: _dummy_database@_dummy_table
-PREHOOK: Output: default@test_truncate_part_evolution
-POSTHOOK: query: insert into test_truncate_part_evolution values (1,
'one'),(2,'two'),(3,'three'),(4,'four'),(5,'five')
-POSTHOOK: type: QUERY
-POSTHOOK: Input: _dummy_database@_dummy_table
-POSTHOOK: Output: default@test_truncate_part_evolution
-PREHOOK: query: alter table test_truncate_part_evolution set partition spec(id)
-PREHOOK: type: ALTERTABLE_SETPARTSPEC
-PREHOOK: Input: default@test_truncate_part_evolution
-POSTHOOK: query: alter table test_truncate_part_evolution set partition
spec(id)
-POSTHOOK: type: ALTERTABLE_SETPARTSPEC
-POSTHOOK: Input: default@test_truncate_part_evolution
-POSTHOOK: Output: default@test_truncate_part_evolution
-PREHOOK: query: alter table test_truncate_part_evolution set
tblproperties('external.table.purge'='true')
-PREHOOK: type: ALTERTABLE_PROPERTIES
-PREHOOK: Input: default@test_truncate_part_evolution
-PREHOOK: Output: default@test_truncate_part_evolution
-POSTHOOK: query: alter table test_truncate_part_evolution set
tblproperties('external.table.purge'='true')
-POSTHOOK: type: ALTERTABLE_PROPERTIES
-POSTHOOK: Input: default@test_truncate_part_evolution
-POSTHOOK: Output: default@test_truncate_part_evolution
-FAILED: SemanticException Truncate conversion to delete is not possible since
its not an Iceberg V2 table. Consider converting the table to Iceberg's V2
format specification.
diff --git
a/iceberg/iceberg-handler/src/test/results/positive/iceberg_truncate_partition_with_evolution.q.out
b/iceberg/iceberg-handler/src/test/results/positive/iceberg_truncate_partition_with_evolution.q.out
index 3217a146827..5bae58604a6 100644
---
a/iceberg/iceberg-handler/src/test/results/positive/iceberg_truncate_partition_with_evolution.q.out
+++
b/iceberg/iceberg-handler/src/test/results/positive/iceberg_truncate_partition_with_evolution.q.out
@@ -1309,6 +1309,55 @@ POSTHOOK: type: QUERY
POSTHOOK: Input: default@test_ice_double_date
POSTHOOK: Output: hdfs://### HDFS PATH ###
{"a":null,"b":null}
+PREHOOK: query: create external table test_truncate_part_evolution (id int,
value string) stored by iceberg stored as orc tblproperties
('format-version'='1')
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@test_truncate_part_evolution
+POSTHOOK: query: create external table test_truncate_part_evolution (id int,
value string) stored by iceberg stored as orc tblproperties
('format-version'='1')
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@test_truncate_part_evolution
+PREHOOK: query: insert into test_truncate_part_evolution values (1,
'one'),(2,'two'),(3,'three'),(4,'four'),(5,'five')
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+PREHOOK: Output: default@test_truncate_part_evolution
+POSTHOOK: query: insert into test_truncate_part_evolution values (1,
'one'),(2,'two'),(3,'three'),(4,'four'),(5,'five')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+POSTHOOK: Output: default@test_truncate_part_evolution
+PREHOOK: query: alter table test_truncate_part_evolution set partition spec(id)
+PREHOOK: type: ALTERTABLE_SETPARTSPEC
+PREHOOK: Input: default@test_truncate_part_evolution
+POSTHOOK: query: alter table test_truncate_part_evolution set partition
spec(id)
+POSTHOOK: type: ALTERTABLE_SETPARTSPEC
+POSTHOOK: Input: default@test_truncate_part_evolution
+POSTHOOK: Output: default@test_truncate_part_evolution
+PREHOOK: query: alter table test_truncate_part_evolution set
tblproperties('external.table.purge'='true')
+PREHOOK: type: ALTERTABLE_PROPERTIES
+PREHOOK: Input: default@test_truncate_part_evolution
+PREHOOK: Output: default@test_truncate_part_evolution
+POSTHOOK: query: alter table test_truncate_part_evolution set
tblproperties('external.table.purge'='true')
+POSTHOOK: type: ALTERTABLE_PROPERTIES
+POSTHOOK: Input: default@test_truncate_part_evolution
+POSTHOOK: Output: default@test_truncate_part_evolution
+PREHOOK: query: truncate test_truncate_part_evolution partition(id=1)
+PREHOOK: type: QUERY
+PREHOOK: Output: default@test_truncate_part_evolution@id=1
+POSTHOOK: query: truncate test_truncate_part_evolution partition(id=1)
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@test_truncate_part_evolution@id=1
+PREHOOK: query: select * from test_truncate_part_evolution
+PREHOOK: type: QUERY
+PREHOOK: Input: default@test_truncate_part_evolution
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: select * from test_truncate_part_evolution
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@test_truncate_part_evolution
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+2 two
+3 three
+4 four
+5 five
PREHOOK: query: drop table test_ice_int
PREHOOK: type: DROPTABLE
PREHOOK: Input: default@test_ice_int
@@ -1369,3 +1418,13 @@ POSTHOOK: type: DROPTABLE
POSTHOOK: Input: default@test_ice_double_date
POSTHOOK: Output: database:default
POSTHOOK: Output: default@test_ice_double_date
+PREHOOK: query: drop table test_truncate_part_evolution
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@test_truncate_part_evolution
+PREHOOK: Output: database:default
+PREHOOK: Output: default@test_truncate_part_evolution
+POSTHOOK: query: drop table test_truncate_part_evolution
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@test_truncate_part_evolution
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@test_truncate_part_evolution