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

[SPARK-51119][SQL][FOLLOW-UP] Add fallback to ResolveDefaultColumnsUtil existenceDefaultValues #49962

Closed
wants to merge 3 commits into from

Conversation

szehon-ho
Copy link
Contributor

What changes were proposed in this pull request?

The original change in #49840 was too optimistic and assumes that all column EXISTS_DEFAULT are already resolved and column folded. However, if there is bad EXISTS_DEFAULT metadata (an unresolved expression is persisted) it will break. Add fallback to use the original logic in that case.

Why are the changes needed?

There are some cases where bad EXISTS_DEFAULT metadata is persisted by external catalogs, due to some bugs such as #49942 or other problems.

Does this PR introduce any user-facing change?

No, it should handle bad metadata better.

How was this patch tested?

Add unit test

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the SQL label Feb 14, 2025
@szehon-ho szehon-ho force-pushed the SPARK-51119-follow-2 branch from 6f13efb to 64b62ca Compare February 15, 2025 00:18
log"with ${MDC(COLUMN_DATA_TYPE_SOURCE, field.dataType)}, " +
log"falling back to full analysis.")

field.getExistenceDefaultValue().map { text: String =>
Copy link
Contributor

Choose a reason for hiding this comment

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

is this just the passed in defaultSQL?

Copy link
Contributor Author

@szehon-ho szehon-ho Feb 19, 2025

Choose a reason for hiding this comment

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

You are right, I guess I can re-use it or re-derive the redundant argument, i just changed to re-derive it as its a bit easier to get the method signature, but lmk if you prefer the first.

@szehon-ho
Copy link
Contributor Author

I re-ran the failing test and its green on the build link, but somehow still shows red on the PR.

s" field name: ${field.name}, value: $defaultSQL")
}
// sanity check
if (!literal.resolved) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think def analyze already did this check?

Copy link
Contributor Author

@szehon-ho szehon-ho Feb 20, 2025

Choose a reason for hiding this comment

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

Yea the original code for resolving existenceDefaultValues, which called analyze(), went through this check. It's even indicated as extra in the comments.

https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/ResolveDefaultColumnsUtil.scala#L310

So I was just keeping the original behavior, do you suggest to remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, lets me know if its better

@szehon-ho szehon-ho closed this Feb 21, 2025
@szehon-ho szehon-ho reopened this Feb 21, 2025
@cloud-fan
Copy link
Contributor

thanks, merging to master/4.0!

@cloud-fan cloud-fan closed this in 4ffc398 Feb 21, 2025
cloud-fan pushed a commit that referenced this pull request Feb 21, 2025
…il existenceDefaultValues

### What changes were proposed in this pull request?
 The original change in #49840 was too optimistic and assumes that all column EXISTS_DEFAULT are already resolved and column folded.  However, if there is bad EXISTS_DEFAULT metadata (an unresolved expression is persisted) it will break.  Add fallback to use the original logic in that case.

### Why are the changes needed?
There are some cases where bad EXISTS_DEFAULT metadata is persisted by external catalogs, due to some bugs such as #49942 or other problems.

### Does this PR introduce _any_ user-facing change?
No, it should handle bad metadata better.

### How was this patch tested?
Add unit test

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #49962 from szehon-ho/SPARK-51119-follow-2.

Authored-by: Szehon Ho <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit 4ffc398)
Signed-off-by: Wenchen Fan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants