Skip to content

[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
apache:masterfrom
mikhailnik-db:spark-56862-sql-udf-origin
Closed

[SPARK-56862][SQL] Preserve SQL UDF call-site origin in input Cast for runtime error context#55980
mikhailnik-db wants to merge 1 commit into
apache:masterfrom
mikhailnik-db:spark-56862-sql-udf-origin

Conversation

@mikhailnik-db
Copy link
Copy Markdown
Contributor

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 Casts 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)

@cloud-fan
Copy link
Copy Markdown
Contributor

thanks, merging to master/4.x/4.2!

@cloud-fan cloud-fan closed this in dc27d73 May 19, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants