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

   ## Which issue does this PR close?
   
   - N/A (performance improvement). Spun out of review discussion on #22562.
   
   ## Rationale for this change
   
   `ScalarValue::cast_to_with_options` always builds a single-row array and 
runs the arrow cast kernel, even for trivial conversions. For two very common 
cases — casting a value to its own type, and converting between the string 
types — that array allocation and kernel dispatch is pure overhead.
   
   ## What changes are included in this PR?
   
   Two array-free fast paths in `cast_to_with_options` that produce **exactly** 
the same result as the existing array + arrow-kernel path:
   
   - **identity** casts (`source_type == target_type`) clone the value directly
   - conversions among the **string types** (`Utf8` / `LargeUtf8` / `Utf8View`) 
are value-preserving and just rewrap the string
   
   Everything else still goes through the existing arrow path, so behavior is 
unchanged.
   
   Test changes:
   - `check_scalar_cast` now also calls `cast_to` and asserts it agrees with 
the arrow cast kernel, so `cast_round_trip` actually exercises the new fast 
paths (and `cast_to` generally).
   - Extended `cast_round_trip` with the successful-cast type combinations 
covered by `try_cast_literal_to_type` (identity, numeric widen/narrow, 
int↔decimal, decimal rescale, timestamp unit/tz, int64↔timestamp, string 
conversions, dictionary unwrap, binary→fixed-size-binary).
   
   ## Are these changes tested?
   
   Yes — see above; full `datafusion-common` lib tests pass, plus 
`datafusion-optimizer` / `datafusion-expr` (cast-heavy) suites.
   
   ## Are there any user-facing changes?
   
   No. `cast_to` / `cast_to_with_options` return the same results as before, 
just faster for these cases. No API changes.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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