Skip to content

HIVE-28917: NPE in merge statement when checking nullability of joini… #5781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

soumyakanti3578
Copy link
Contributor

@soumyakanti3578 soumyakanti3578 commented Apr 22, 2025

…ng column in matched clause

What changes were proposed in this pull request?

When TOK_FROM is not present in the AST for MERGE statements, return DestClausePrefix.MERGE.

Why are the changes needed?

Without this we could get an NPE as explained in HIVE-28917

Does this PR introduce any user-facing change?

No

How was this patch tested?

mvn test -pl itests/qtest-iceberg -Piceberg -Pitests -Dtest=TestIcebergNegativeCliDriver -Dtest.output.overwrite=true -Dqfile="merge_with_null_check_on_joining_col.q"

Comment on lines 4 to 5
merge into target as t using source as s on t.a = s.a
when matched and t.a is null then delete;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a SQL perspective the query is perfectly valid so there is no reason to throw an error or exception. The query is probably useless cause indeed the when matched and t.a is null is always false but this is not a SQL error. The expected result is to simply leave the target table unchanged.


int tokFromIdx = query.getFirstChildWithType(HiveParser.TOK_FROM).getChildIndex();
ASTNode from = (ASTNode) query.getFirstChildWithType(HiveParser.TOK_FROM);
assert from != null : "Couldn't find a child of type FROM in the AST";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertions should never be used for user-level errors. Despite the fact that they are disabled in production environments (and thus a user will never encounter) stack-traces and other information associated with the assertion/exception are for developers to help diagnose and fix a problem. Problems with the SQL syntax should be user-level errors with appropriate error codes and localization.

However, as I mentioned previously the MERGE statement addressed here is valid SQL so it shouldn't lead to failures or exceptions of any kind.

@soumyakanti3578 soumyakanti3578 requested a review from zabetak April 24, 2025 16:21
@soumyakanti3578 soumyakanti3578 marked this pull request as ready for review April 24, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants