Skip to content
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

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

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.


if (subqueryMap.get(planId).isEmpty()) {
subqueryMap.remove(planId);
if (subqueryMap.get(planId).isEmpty()) {
subqueryMap.remove(planId);
}
}
}

Expand Down