zhaodong created HIVE-29783:
-------------------------------

             Summary: Iceberg CoW MERGE INTO missing column ambiguity check
                 Key: HIVE-29783
                 URL: https://issues.apache.org/jira/browse/HIVE-29783
             Project: Hive
          Issue Type: Bug
         Environment: hadoop:3.3.6

hive:4.2.0
            Reporter: zhaodong
         Attachments: 111.png, 222.png, 333.png

Description:
When executing a MERGE INTO statement on an Iceberg Copy-on-Write (CoW) table, 
if the ON condition contains an unqualified column name that exists in both the 
target and source tables, Hive fails to throw a semantic ambiguity exception. 
Instead, it executes the statement without any errors but returns incorrect 
query results.
In contrast, the same statement executed on an Iceberg Merge-on-Read (MoR) 
table correctly throws a SemanticException: Column a Found in more than One 
Tables/Subqueries.

Steps to Reproduce:
1.Create an ORC source table and insert test data:

CREATE TABLE testorc (a INT, b INT) STORED AS ORC;
INSERT INTO testorc VALUES (9, 10);

2.Create Iceberg MoR and CoW target tables and insert identical test data:

CREATE TABLE testmor (a INT, b INT) 
STORED BY iceberg
STORED AS ORC 
TBLPROPERTIES (
  'format-version' = '1',
  'write.delete.mode' = 'merge-on-read',
  'write.update.mode' = 'merge-on-read',
  'write.merge.mode' = 'merge-on-read'
);

CREATE TABLE testcow (a INT, b INT) 
STORED BY iceberg
STORED AS ORC 
TBLPROPERTIES (
  'format-version' = '1',
  'write.delete.mode' = 'copy-on-write',
  'write.update.mode' = 'copy-on-write',
  'write.merge.mode' = 'copy-on-write'
);

INSERT INTO testmor VALUES (9, 3), (2, 3);
INSERT INTO testcow VALUES (9, 3), (2, 3);

3.Execute MERGE INTO with an unqualified column a in the ON condition:

-- Test 1: MoR table (Correct behavior)
MERGE INTO testmor 
USING testorc 
ON a = testorc.a 
WHEN MATCHED THEN UPDATE SET b = testorc.b;
-- Expected: SemanticException: Column a Found in more than One 
Tables/Subqueries

-- Test 2: CoW table (Buggy behavior)
MERGE INTO testcow  
USING testorc 
ON a = testorc.a 
WHEN MATCHED THEN UPDATE SET b = testorc.b;
-- Actual: Executes successfully without throwing an exception.

4.Verify the data in the CoW table:

SELECT * FROM testcow;

Expected Behavior:
The CoW table should behave consistently with the MoR table and throw a 
SemanticException indicating that column a is ambiguous.

Actual Behavior:
The CoW table execution succeeds silently, but the data is corrupted. The query 
SELECT * FROM testcow; returns:
(9, 10), (2, 10)
The row (2, 3) was incorrectly updated to (2, 10) .



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to