You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ay...@apache.org on 2024/09/23 11:24:18 UTC
(hive) 03/03: HIVE-28225: Iceberg: Delete on entire table fails on COW mode. (#5219). (Ayush Saxena, reviewed by Stamatis Zampetakis)
This is an automated email from the ASF dual-hosted git repository.
ayushsaxena pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/hive.git
commit 8def11266ab2e8425f95aff6d94fa080c4af2038
Author: Ayush Saxena <ay...@apache.org>
AuthorDate: Wed May 1 12:56:41 2024 +0530
HIVE-28225: Iceberg: Delete on entire table fails on COW mode. (#5219). (Ayush Saxena, reviewed by Stamatis Zampetakis)
---
.../delete_iceberg_copy_on_write_unpartitioned.q | 7 ++++++-
.../delete_iceberg_copy_on_write_unpartitioned.q.out | 16 ++++++++++++++++
.../hive/ql/parse/rewrite/CopyOnWriteDeleteRewriter.java | 11 ++++++++---
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/iceberg/iceberg-handler/src/test/queries/positive/delete_iceberg_copy_on_write_unpartitioned.q b/iceberg/iceberg-handler/src/test/queries/positive/delete_iceberg_copy_on_write_unpartitioned.q
index 81520739823..c36b2fda4b2 100644
--- a/iceberg/iceberg-handler/src/test/queries/positive/delete_iceberg_copy_on_write_unpartitioned.q
+++ b/iceberg/iceberg-handler/src/test/queries/positive/delete_iceberg_copy_on_write_unpartitioned.q
@@ -47,4 +47,9 @@ insert into tbl_ice_with_nulls values
(1, 'ABC'),(2, 'CBS'),(3, null),(4, 'POPI'),(5, 'AQWR'),(6, 'POIU'),(7, 'SDF'),(9, null),(8,'POIKL'),(10, 'YUIO');
delete from tbl_ice_with_nulls where id in (select id from tbl_ice_with_nulls where id > 9) or name in (select name from tbl_ice_with_nulls where name = 'sdf');
-select * from tbl_ice_with_nulls order by id;
\ No newline at end of file
+select * from tbl_ice_with_nulls order by id;
+
+-- delete without where clause and disabled conversion to truncate
+set hive.optimize.delete.all=false;
+delete from tbl_ice_with_nulls;
+select * from tbl_ice_with_nulls;
\ No newline at end of file
diff --git a/iceberg/iceberg-handler/src/test/results/positive/delete_iceberg_copy_on_write_unpartitioned.q.out b/iceberg/iceberg-handler/src/test/results/positive/delete_iceberg_copy_on_write_unpartitioned.q.out
index 061d697e03f..4818bb08e44 100644
--- a/iceberg/iceberg-handler/src/test/results/positive/delete_iceberg_copy_on_write_unpartitioned.q.out
+++ b/iceberg/iceberg-handler/src/test/results/positive/delete_iceberg_copy_on_write_unpartitioned.q.out
@@ -1890,3 +1890,19 @@ POSTHOOK: Output: hdfs://### HDFS PATH ###
7 SDF
8 POIKL
9 NULL
+PREHOOK: query: delete from tbl_ice_with_nulls
+PREHOOK: type: QUERY
+PREHOOK: Input: default@tbl_ice_with_nulls
+PREHOOK: Output: default@tbl_ice_with_nulls
+POSTHOOK: query: delete from tbl_ice_with_nulls
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@tbl_ice_with_nulls
+POSTHOOK: Output: default@tbl_ice_with_nulls
+PREHOOK: query: select * from tbl_ice_with_nulls
+PREHOOK: type: QUERY
+PREHOOK: Input: default@tbl_ice_with_nulls
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: select * from tbl_ice_with_nulls
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@tbl_ice_with_nulls
+POSTHOOK: Output: hdfs://### HDFS PATH ###
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/CopyOnWriteDeleteRewriter.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/CopyOnWriteDeleteRewriter.java
index c1396199c8f..3a6ebb97b5f 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/CopyOnWriteDeleteRewriter.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/CopyOnWriteDeleteRewriter.java
@@ -22,6 +22,7 @@ import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.Context;
import org.apache.hadoop.hive.ql.metadata.HiveUtils;
import org.apache.hadoop.hive.ql.metadata.VirtualColumn;
+import org.apache.hadoop.hive.ql.parse.ASTNode;
import org.apache.hadoop.hive.ql.parse.ParseUtils;
import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.apache.hadoop.hive.ql.parse.rewrite.sql.COWWithClauseBuilder;
@@ -44,9 +45,13 @@ public class CopyOnWriteDeleteRewriter implements Rewriter<DeleteStatement> {
public ParseUtils.ReparseResult rewrite(Context context, DeleteStatement deleteBlock)
throws SemanticException {
- Tree wherePredicateNode = deleteBlock.getWhereTree().getChild(0);
- String whereClause = context.getTokenRewriteStream().toString(
- wherePredicateNode.getTokenStartIndex(), wherePredicateNode.getTokenStopIndex());
+ ASTNode whereTree = deleteBlock.getWhereTree();
+ String whereClause = "true";
+ if (whereTree != null) {
+ Tree wherePredicateNode = whereTree.getChild(0);
+ whereClause = context.getTokenRewriteStream()
+ .toString(wherePredicateNode.getTokenStartIndex(), wherePredicateNode.getTokenStopIndex());
+ }
String filePathCol = HiveUtils.unparseIdentifier(VirtualColumn.FILE_PATH.getName(), conf);
MultiInsertSqlGenerator sqlGenerator = sqlGeneratorFactory.createSqlGenerator();