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 2add55241dc HIVE-28225: Iceberg: Delete on entire table fails on COW mode. (#5219). (Ayush Saxena, reviewed by Stamatis Zampetakis) 2add55241dc is described below commit 2add55241dccd44866fc65441500e7e466026a0b Author: Ayush Saxena <ayushsax...@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();