This is an automated email from the ASF dual-hosted git repository.
kasakrisz 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 4b286e18a2e HIVE-29496: Subsequent transactional materialized view
rebuild fails when source tables are iceberg tables (#6434)
4b286e18a2e is described below
commit 4b286e18a2e1dcf56fa364345b6ce9c48c3b9a0c
Author: Krisztian Kasa <[email protected]>
AuthorDate: Thu Apr 30 06:39:36 2026 +0200
HIVE-29496: Subsequent transactional materialized view rebuild fails when
source tables are iceberg tables (#6434)
---
.../src/test/queries/positive/mv_iceberg_orc9.q | 28 ++++
.../test/results/positive/mv_iceberg_orc9.q.out | 156 +++++++++++++++++++++
.../AlterMaterializedViewRebuildAnalyzer.java | 4 +
3 files changed, 188 insertions(+)
diff --git
a/iceberg/iceberg-handler/src/test/queries/positive/mv_iceberg_orc9.q
b/iceberg/iceberg-handler/src/test/queries/positive/mv_iceberg_orc9.q
new file mode 100644
index 00000000000..ed9d1b25c0e
--- /dev/null
+++ b/iceberg/iceberg-handler/src/test/queries/positive/mv_iceberg_orc9.q
@@ -0,0 +1,28 @@
+-- Test subsequent rebuild of transactional MV when source table is Iceberg.
+
+-- SORT_QUERY_RESULTS
+set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+set hive.support.concurrency=true;
+
+create table ice_basetable (a int, b string) stored by iceberg;
+insert into ice_basetable values (1, 'alfred'),(2, 'bob'),(2, 'bonnie'),(3,
'calvin'),(3, 'charlie');
+
+create materialized view mv_acid STORED AS ORC TBLPROPERTIES
('transactional'='true') as
+select b, a from ice_basetable;
+
+create materialized view mv_insert_only STORED AS ORC TBLPROPERTIES
('transactional'='true', 'transactional_properties'='insert_only') as
+select b, a from ice_basetable;
+
+select * from mv_acid;
+select * from mv_insert_only;
+
+insert into ice_basetable values (5, 'amia');
+alter materialized view mv_acid rebuild;
+alter materialized view mv_insert_only rebuild;
+
+insert into ice_basetable values (4, 'mania');
+alter materialized view mv_acid rebuild;
+alter materialized view mv_insert_only rebuild;
+
+select * from mv_acid;
+select * from mv_insert_only;
diff --git
a/iceberg/iceberg-handler/src/test/results/positive/mv_iceberg_orc9.q.out
b/iceberg/iceberg-handler/src/test/results/positive/mv_iceberg_orc9.q.out
new file mode 100644
index 00000000000..d4b8f3eb9a5
--- /dev/null
+++ b/iceberg/iceberg-handler/src/test/results/positive/mv_iceberg_orc9.q.out
@@ -0,0 +1,156 @@
+PREHOOK: query: create table ice_basetable (a int, b string) stored by iceberg
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@ice_basetable
+POSTHOOK: query: create table ice_basetable (a int, b string) stored by iceberg
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@ice_basetable
+PREHOOK: query: insert into ice_basetable values (1, 'alfred'),(2, 'bob'),(2,
'bonnie'),(3, 'calvin'),(3, 'charlie')
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+PREHOOK: Output: default@ice_basetable
+POSTHOOK: query: insert into ice_basetable values (1, 'alfred'),(2, 'bob'),(2,
'bonnie'),(3, 'calvin'),(3, 'charlie')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+POSTHOOK: Output: default@ice_basetable
+PREHOOK: query: create materialized view mv_acid STORED AS ORC TBLPROPERTIES
('transactional'='true') as
+select b, a from ice_basetable
+PREHOOK: type: CREATE_MATERIALIZED_VIEW
+PREHOOK: Input: default@ice_basetable
+PREHOOK: Output: database:default
+PREHOOK: Output: default@mv_acid
+POSTHOOK: query: create materialized view mv_acid STORED AS ORC TBLPROPERTIES
('transactional'='true') as
+select b, a from ice_basetable
+POSTHOOK: type: CREATE_MATERIALIZED_VIEW
+POSTHOOK: Input: default@ice_basetable
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@mv_acid
+POSTHOOK: Lineage: mv_acid.a SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:a, type:int, comment:null), ]
+POSTHOOK: Lineage: mv_acid.b SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:b, type:string, comment:null), ]
+PREHOOK: query: create materialized view mv_insert_only STORED AS ORC
TBLPROPERTIES ('transactional'='true',
'transactional_properties'='insert_only') as
+select b, a from ice_basetable
+PREHOOK: type: CREATE_MATERIALIZED_VIEW
+PREHOOK: Input: default@ice_basetable
+PREHOOK: Output: database:default
+PREHOOK: Output: default@mv_insert_only
+POSTHOOK: query: create materialized view mv_insert_only STORED AS ORC
TBLPROPERTIES ('transactional'='true',
'transactional_properties'='insert_only') as
+select b, a from ice_basetable
+POSTHOOK: type: CREATE_MATERIALIZED_VIEW
+POSTHOOK: Input: default@ice_basetable
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@mv_insert_only
+POSTHOOK: Lineage: mv_insert_only.a SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:a, type:int, comment:null), ]
+POSTHOOK: Lineage: mv_insert_only.b SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:b, type:string, comment:null), ]
+PREHOOK: query: select * from mv_acid
+PREHOOK: type: QUERY
+PREHOOK: Input: default@mv_acid
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: select * from mv_acid
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@mv_acid
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+alfred 1
+bob 2
+bonnie 2
+calvin 3
+charlie 3
+PREHOOK: query: select * from mv_insert_only
+PREHOOK: type: QUERY
+PREHOOK: Input: default@mv_insert_only
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: select * from mv_insert_only
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@mv_insert_only
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+alfred 1
+bob 2
+bonnie 2
+calvin 3
+charlie 3
+PREHOOK: query: insert into ice_basetable values (5, 'amia')
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+PREHOOK: Output: default@ice_basetable
+POSTHOOK: query: insert into ice_basetable values (5, 'amia')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+POSTHOOK: Output: default@ice_basetable
+PREHOOK: query: alter materialized view mv_acid rebuild
+PREHOOK: type: ALTER_MATERIALIZED_VIEW_REBUILD
+PREHOOK: Input: default@ice_basetable
+PREHOOK: Output: default@mv_acid
+POSTHOOK: query: alter materialized view mv_acid rebuild
+POSTHOOK: type: ALTER_MATERIALIZED_VIEW_REBUILD
+POSTHOOK: Input: default@ice_basetable
+POSTHOOK: Output: default@mv_acid
+POSTHOOK: Lineage: mv_acid.a SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:a, type:int, comment:null), ]
+POSTHOOK: Lineage: mv_acid.b SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:b, type:string, comment:null), ]
+PREHOOK: query: alter materialized view mv_insert_only rebuild
+PREHOOK: type: ALTER_MATERIALIZED_VIEW_REBUILD
+PREHOOK: Input: default@ice_basetable
+PREHOOK: Output: default@mv_insert_only
+POSTHOOK: query: alter materialized view mv_insert_only rebuild
+POSTHOOK: type: ALTER_MATERIALIZED_VIEW_REBUILD
+POSTHOOK: Input: default@ice_basetable
+POSTHOOK: Output: default@mv_insert_only
+POSTHOOK: Lineage: mv_insert_only.a SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:a, type:int, comment:null), ]
+POSTHOOK: Lineage: mv_insert_only.b SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:b, type:string, comment:null), ]
+PREHOOK: query: insert into ice_basetable values (4, 'mania')
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+PREHOOK: Output: default@ice_basetable
+POSTHOOK: query: insert into ice_basetable values (4, 'mania')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+POSTHOOK: Output: default@ice_basetable
+PREHOOK: query: alter materialized view mv_acid rebuild
+PREHOOK: type: ALTER_MATERIALIZED_VIEW_REBUILD
+PREHOOK: Input: default@ice_basetable
+PREHOOK: Output: default@mv_acid
+POSTHOOK: query: alter materialized view mv_acid rebuild
+POSTHOOK: type: ALTER_MATERIALIZED_VIEW_REBUILD
+POSTHOOK: Input: default@ice_basetable
+POSTHOOK: Output: default@mv_acid
+POSTHOOK: Lineage: mv_acid.a SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:a, type:int, comment:null), ]
+POSTHOOK: Lineage: mv_acid.b SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:b, type:string, comment:null), ]
+PREHOOK: query: alter materialized view mv_insert_only rebuild
+PREHOOK: type: ALTER_MATERIALIZED_VIEW_REBUILD
+PREHOOK: Input: default@ice_basetable
+PREHOOK: Output: default@mv_insert_only
+POSTHOOK: query: alter materialized view mv_insert_only rebuild
+POSTHOOK: type: ALTER_MATERIALIZED_VIEW_REBUILD
+POSTHOOK: Input: default@ice_basetable
+POSTHOOK: Output: default@mv_insert_only
+POSTHOOK: Lineage: mv_insert_only.a SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:a, type:int, comment:null), ]
+POSTHOOK: Lineage: mv_insert_only.b SIMPLE
[(ice_basetable)ice_basetable.FieldSchema(name:b, type:string, comment:null), ]
+PREHOOK: query: select * from mv_acid
+PREHOOK: type: QUERY
+PREHOOK: Input: default@mv_acid
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: select * from mv_acid
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@mv_acid
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+alfred 1
+amia 5
+bob 2
+bonnie 2
+calvin 3
+charlie 3
+mania 4
+PREHOOK: query: select * from mv_insert_only
+PREHOOK: type: QUERY
+PREHOOK: Input: default@mv_insert_only
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: select * from mv_insert_only
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@mv_insert_only
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+alfred 1
+amia 5
+bob 2
+bonnie 2
+calvin 3
+charlie 3
+mania 4
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/ddl/view/materialized/alter/rebuild/AlterMaterializedViewRebuildAnalyzer.java
b/ql/src/java/org/apache/hadoop/hive/ql/ddl/view/materialized/alter/rebuild/AlterMaterializedViewRebuildAnalyzer.java
index a0cf25fbbaf..4469c4f71ad 100644
---
a/ql/src/java/org/apache/hadoop/hive/ql/ddl/view/materialized/alter/rebuild/AlterMaterializedViewRebuildAnalyzer.java
+++
b/ql/src/java/org/apache/hadoop/hive/ql/ddl/view/materialized/alter/rebuild/AlterMaterializedViewRebuildAnalyzer.java
@@ -35,6 +35,7 @@
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.api.LockMaterializationRebuildRequest;
import org.apache.hadoop.hive.metastore.api.LockState;
+import org.apache.hadoop.hive.metastore.api.TxnType;
import org.apache.hadoop.hive.ql.Context;
import org.apache.hadoop.hive.ql.ErrorMsg;
import org.apache.hadoop.hive.ql.QueryProperties;
@@ -213,6 +214,9 @@ private ASTNode getRewrittenAST(TableName tableName) throws
SemanticException {
HiveTxnManager txnManager = getTxnMgr();
LockState state;
try {
+ if (!txnManager.isTxnOpen()) {
+ txnManager.openTxn(ctx, conf.getUser(),
TxnType.MATER_VIEW_REBUILD);
+ }
state = txnManager.acquireMaterializationRebuildLock(new
LockMaterializationRebuildRequest(tableName.getCat(),
tableName.getDb(), tableName.getTable(),
txnManager.getCurrentTxnId())).getState();
} catch (LockException e) {