[SPARK-56862][SQL] Preserve SQL UDF call-site origin in input Cast for runtime error context#55980
Closed
mikhailnik-db wants to merge 1 commit into
Closed
[SPARK-56862][SQL] Preserve SQL UDF call-site origin in input Cast for runtime error context#55980mikhailnik-db wants to merge 1 commit into
mikhailnik-db wants to merge 1 commit into
Conversation
…r runtime error context
cloud-fan
approved these changes
May 19, 2026
Contributor
|
thanks, merging to master/4.x/4.2! |
cloud-fan
pushed a commit
that referenced
this pull request
May 19, 2026
…r runtime error context
### What changes were proposed in this pull request?
Wrap `resolve(f)` in `Analyzer.ResolveSQLFunctions.rewriteSQLFunctions` with `CurrentOrigin.withOrigin(f.origin) { ... }` so that the input-binding `Cast`s constructed inside `SessionCatalog.makeSQLFunctionPlan` capture the SQL UDF call-site position in their `queryContext` snapshot.
### Why are the changes needed?
Without this change, runtime errors raised inside a SQL UDF input-binding `Cast` (`CAST_INVALID_INPUT`, arithmetic overflow, number-format errors, ...) lose their query context. Users see an empty `fragment` instead of the call site that triggered the error, defeating the purpose of `queryContext` for SQL UDF debugging.
### Does this PR introduce _any_ user-facing change?
Yes. correctly filled queryContext for SQL UDFs
### How was this patch tested?
Regenerated sql/core/src/test/resources/sql-tests/results/sql-udf.sql.out.
The diff shows 8 previously empty queryContext entries gaining
startIndex, stopIndex, and a populated fragment; nothing else
changed.
### Was this patch authored or co-authored using generative AI tooling?
Claude Code (Opus 4.7)
Closes #55980 from mikhailnik-db/spark-56862-sql-udf-origin.
Authored-by: Mikhail NIkoliukin <mikhail.nikoliukin@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit dc27d73)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
cloud-fan
pushed a commit
that referenced
this pull request
May 19, 2026
…r runtime error context
### What changes were proposed in this pull request?
Wrap `resolve(f)` in `Analyzer.ResolveSQLFunctions.rewriteSQLFunctions` with `CurrentOrigin.withOrigin(f.origin) { ... }` so that the input-binding `Cast`s constructed inside `SessionCatalog.makeSQLFunctionPlan` capture the SQL UDF call-site position in their `queryContext` snapshot.
### Why are the changes needed?
Without this change, runtime errors raised inside a SQL UDF input-binding `Cast` (`CAST_INVALID_INPUT`, arithmetic overflow, number-format errors, ...) lose their query context. Users see an empty `fragment` instead of the call site that triggered the error, defeating the purpose of `queryContext` for SQL UDF debugging.
### Does this PR introduce _any_ user-facing change?
Yes. correctly filled queryContext for SQL UDFs
### How was this patch tested?
Regenerated sql/core/src/test/resources/sql-tests/results/sql-udf.sql.out.
The diff shows 8 previously empty queryContext entries gaining
startIndex, stopIndex, and a populated fragment; nothing else
changed.
### Was this patch authored or co-authored using generative AI tooling?
Claude Code (Opus 4.7)
Closes #55980 from mikhailnik-db/spark-56862-sql-udf-origin.
Authored-by: Mikhail NIkoliukin <mikhail.nikoliukin@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit dc27d73)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Wrap
resolve(f)inAnalyzer.ResolveSQLFunctions.rewriteSQLFunctionswithCurrentOrigin.withOrigin(f.origin) { ... }so that the input-bindingCasts constructed insideSessionCatalog.makeSQLFunctionPlancapture the SQL UDF call-site position in theirqueryContextsnapshot.Why are the changes needed?
Without this change, runtime errors raised inside a SQL UDF input-binding
Cast(CAST_INVALID_INPUT, arithmetic overflow, number-format errors, ...) lose their query context. Users see an emptyfragmentinstead of the call site that triggered the error, defeating the purpose ofqueryContextfor SQL UDF debugging.Does this PR introduce any user-facing change?
Yes. correctly filled queryContext for SQL UDFs
How was this patch tested?
Regenerated sql/core/src/test/resources/sql-tests/results/sql-udf.sql.out.
The diff shows 8 previously empty queryContext entries gaining
startIndex, stopIndex, and a populated fragment; nothing else
changed.
Was this patch authored or co-authored using generative AI tooling?
Claude Code (Opus 4.7)