You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Jefffrey (via GitHub)" <gi...@apache.org> on 2026/05/28 01:18:50 UTC
Re: [PR] perf: array-free fast paths for `ScalarValue::cast_to` [datafusion]
Jefffrey commented on code in PR #22576:
URL: https://github.com/apache/datafusion/pull/22576#discussion_r3314772478
##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -4224,6 +4224,33 @@ impl ScalarValue {
cast_options: &CastOptions<'static>,
) -> Result<Self> {
let source_type = self.data_type();
+
+ // Fast path: an identical target type needs no conversion at all.
+ if &source_type == target_type {
+ return Ok(self.clone());
+ }
+
+ // Fast path: conversions among the string types (`Utf8`, `LargeUtf8`,
+ // `Utf8View`) are value-preserving, so we can rewrap the string
+ // directly instead of building a single-row array and invoking the
+ // arrow cast kernel.
+ if matches!(
+ (&source_type, target_type),
+ (
+ DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View,
+ DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View,
+ )
+ ) {
Review Comment:
```suggestion
if source_type.is_string() && target_type.is_string() {
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org