alamb opened a new pull request, #22574: URL: https://github.com/apache/datafusion/pull/22574
## Which issue does this PR close? - Follow-up to #22562 (addresses [this review comment](https://github.com/apache/datafusion/pull/22562#discussion_r3312280456)). ## Rationale for this change #22562 fixes `LIKE 'prefix%'` pruning on `Utf8View`/`LargeUtf8` columns by casting the synthesized bound literal to the column type via `try_cast_literal_to_type`. As @alamb noted, that path re-allocates the prefix string: `string_literal_as` wraps an already-owned `String` in `ScalarValue::Utf8`, and the borrowing `try_cast_literal_to_type` copies it again through `to_string()`. This PR adds an owned-input variant so the string can be **moved** into the target type instead of copied. ## What changes are included in this PR? - Add `try_cast_literal_to_type_owned(value: ScalarValue, target_type) -> Result<ScalarValue, ScalarValue>` in `datafusion-expr-common`. It moves owned string values between `Utf8`/`LargeUtf8`/`Utf8View` without re-allocating, and otherwise falls back to the existing borrowing implementation. On an unsupported cast it returns the original value (`Err`) so callers can recover it without cloning. - Use it in `string_literal_as` (LIKE prefix pruning), eliminating the redundant `to_string()`. - Unit tests for the new function (string moves, dictionary wrapping, numeric fallback, unsupported-cast recovery). Behavior is otherwise unchanged — dictionary and all other cast targets still go through the existing logic, and the `prune_like_prefix` regression test from #22562 still passes. > [!NOTE] > This is **stacked on #22562** (its commits are included here). It will need a rebase onto `main` once #22562 merges, and will conflict in `string_literal_as` — that's expected and will be resolved then. ## Are these changes tested? Yes — new unit tests in `casts.rs`; existing `prune_like_prefix` row-group pruning test continues to pass. ## Are there any user-facing changes? A new public function `try_cast_literal_to_type_owned` is added to `datafusion-expr-common`. No existing API changes; no behavior 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]
