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: [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]