-
Notifications
You must be signed in to change notification settings - Fork 166
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
fix: Avoid null exception in removeSubquery #147
Conversation
@@ -47,10 +47,12 @@ public static synchronized void setSubquery(long planId, ScalarSubquery subquery | |||
} | |||
|
|||
public static synchronized void removeSubquery(long planId, ScalarSubquery subquery) { | |||
subqueryMap.get(planId).remove(subquery.exprId().id()); | |||
if (subqueryMap.containsKey(planId)) { | |||
subqueryMap.get(planId).remove(subquery.exprId().id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hit NPE here while working sort merge join PR. I think it is possible that the query plan has duplicate subqueries (e.g., reused subquery), so if it may try to do removal of subquery after the map was clean up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It maybe hard to create a test query without join to reproduce it. So I leave a test out here. But this change looks straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct to me.
One possible way to construct such cases:
val subquery =
new Column(ScalarSubquery(spark.range(10).selectExpr("max(id)").logicalPlan)).as("subquery")
val df = spark.range(1000).select($"id", subquery).filter("id == subquery")
Disclaimer: this case is not verified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Merged. Thanks. |
Which issue does this PR close?
Closes #.
Rationale for this change
In
CometScalarSubquery.removeSubquery
, we should make sure theplanId
is still insubqueryMap
before we go to delete subquery from it. Otherwise, null exception could be thrown.What changes are included in this PR?
How are these changes tested?