choplin opened a new pull request, #23063:
URL: https://github.com/apache/datafusion/pull/23063

   ## Which issue does this PR close?
   
   - Closes #14431
   
   ## Rationale for this change
   
   When a scalar or aggregate function is called with argument types that don't 
match any supported signature (e.g. `SELECT sum('a')`), the error message is a 
raw text dump with no source location. This PR attaches a `Diagnostic` so 
downstream consumers can highlight the offending call site in the original SQL 
query.
   
   ## What changes are included in this PR?
   
   - Add `spans: Spans` field to `ScalarFunction` and `AggregateFunction` so 
function-call source locations survive planning and optimization.
   - Populate spans from sqlparser in the SQL planner when `collect_spans` is 
enabled, following the same pattern used for `Column`.
   - In `verify_function_arguments`, attach a `Diagnostic` with:
     - **message**: the function name (`invalid argument type(s) for 'sum'`)
     - **span**: the function call site in the original SQL
     - **note**: the actual argument types (`called with argument type(s): 
Utf8`)
     - **help**: the candidate signatures (`candidate function(s): 
sum(Decimal), sum(UInt64), ...`)
   - Update all pattern matches, tree-node transforms, and serialization code 
for the new `spans` field.
   
   ## Are there any user-facing changes?
   
   No breaking API changes. `ScalarFunction` and `AggregateFunction` gain a 
`spans: Spans` field, but `Spans` is ignored in `PartialEq` / `Hash` and 
defaults to empty, so existing code using `ScalarFunction::new_udf` / 
`AggregateFunction::new_udf` is unaffected.
   
   When an error occurs, a diagnositc is attached in the error message.
   
   **Before** (no `Diagnostic` attached):
   ```text
   Error during planning: No function matches the given name and argument types 
'sum(Utf8)'. You might need to add explicit type casts.
        Candidate functions:
        sum(Decimal)
        sum(UInt64)
        sum(Int64)
        sum(Float64)
        sum(Duration)
   ```
   
   **After** (same error message, with `Diagnostic` now attached):
   ```text
   Error during planning: No function matches the given name and argument types 
'sum(Utf8)'. You might need to add explicit type casts.
        Candidate functions:
        sum(Decimal)
        sum(UInt64)
        sum(Int64)
        sum(Float64)
        sum(Duration)
   
   Diagnostic:
     message: invalid argument type(s) for 'sum'
     span:    1:8 - 1:11
     note:    called with argument type(s): Utf8
     help:    candidate function(s): sum(Decimal), sum(UInt64), sum(Int64), 
sum(Float64), sum(Duration)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to