This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new e4c3d64a66 feat: support upper and lower for stringview (#12138)
e4c3d64a66 is described below
commit e4c3d64a6683fbea6c0244c9668926fee24f7784
Author: Trent Hauck <[email protected]>
AuthorDate: Sat Aug 24 02:55:28 2024 -0700
feat: support upper and lower for stringview (#12138)
---
datafusion/functions/src/string/common.rs | 23 ++++++++++++++-
datafusion/functions/src/string/lower.rs | 2 +-
datafusion/functions/src/string/upper.rs | 2 +-
datafusion/sqllogictest/test_files/string_view.slt | 34 ++++++++++++++++++----
4 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/datafusion/functions/src/string/common.rs
b/datafusion/functions/src/string/common.rs
index 6f23a5ddd2..a5dc22b4d9 100644
--- a/datafusion/functions/src/string/common.rs
+++ b/datafusion/functions/src/string/common.rs
@@ -23,7 +23,7 @@ use std::sync::Arc;
use arrow::array::{
new_null_array, Array, ArrayAccessor, ArrayDataBuilder, ArrayIter,
ArrayRef,
GenericStringArray, GenericStringBuilder, OffsetSizeTrait, StringArray,
- StringViewArray,
+ StringBuilder, StringViewArray,
};
use arrow::buffer::{Buffer, MutableBuffer, NullBuffer};
use arrow::datatypes::DataType;
@@ -214,6 +214,23 @@ where
i64,
_,
>(array, op)?)),
+ DataType::Utf8View => {
+ let string_array = as_string_view_array(array)?;
+ let mut string_builder = StringBuilder::with_capacity(
+ string_array.len(),
+ string_array.get_array_memory_size(),
+ );
+
+ for str in string_array.iter() {
+ if let Some(str) = str {
+ string_builder.append_value(op(str));
+ } else {
+ string_builder.append_null();
+ }
+ }
+
+ Ok(ColumnarValue::Array(Arc::new(string_builder.finish())))
+ }
other => exec_err!("Unsupported data type {other:?} for function
{name}"),
},
ColumnarValue::Scalar(scalar) => match scalar {
@@ -225,6 +242,10 @@ where
let result = a.as_ref().map(|x| op(x));
Ok(ColumnarValue::Scalar(ScalarValue::LargeUtf8(result)))
}
+ ScalarValue::Utf8View(a) => {
+ let result = a.as_ref().map(|x| op(x));
+ Ok(ColumnarValue::Scalar(ScalarValue::Utf8(result)))
+ }
other => exec_err!("Unsupported data type {other:?} for function
{name}"),
},
}
diff --git a/datafusion/functions/src/string/lower.rs
b/datafusion/functions/src/string/lower.rs
index 29ca682c38..ca324e69c0 100644
--- a/datafusion/functions/src/string/lower.rs
+++ b/datafusion/functions/src/string/lower.rs
@@ -43,7 +43,7 @@ impl LowerFunc {
Self {
signature: Signature::uniform(
1,
- vec![Utf8, LargeUtf8],
+ vec![Utf8, LargeUtf8, Utf8View],
Volatility::Immutable,
),
}
diff --git a/datafusion/functions/src/string/upper.rs
b/datafusion/functions/src/string/upper.rs
index da31948fbc..593e33ab6b 100644
--- a/datafusion/functions/src/string/upper.rs
+++ b/datafusion/functions/src/string/upper.rs
@@ -40,7 +40,7 @@ impl UpperFunc {
Self {
signature: Signature::uniform(
1,
- vec![Utf8, LargeUtf8],
+ vec![Utf8, LargeUtf8, Utf8View],
Volatility::Immutable,
),
}
diff --git a/datafusion/sqllogictest/test_files/string_view.slt
b/datafusion/sqllogictest/test_files/string_view.slt
index 3b3d7b88a4..83c75b8df3 100644
--- a/datafusion/sqllogictest/test_files/string_view.slt
+++ b/datafusion/sqllogictest/test_files/string_view.slt
@@ -460,8 +460,6 @@ Xiangpeng
Raphael
NULL
-
-
### Initcap
query TT
@@ -501,7 +499,7 @@ SELECT
INITCAP(column1_large_utf8_lower) as c3
FROM test_lowercase;
----
-Andrew Andrew Andrew
+Andrew Andrew Andrew
Xiangpeng Xiangpeng Xiangpeng
Raphael Raphael Raphael
NULL NULL NULL
@@ -828,16 +826,42 @@ logical_plan
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]
## Ensure no casts for LOWER
-## TODO https://github.com/apache/datafusion/issues/11855
query TT
EXPLAIN SELECT
LOWER(column1_utf8view) as c1
FROM test;
----
logical_plan
-01)Projection: lower(CAST(test.column1_utf8view AS Utf8)) AS c1
+01)Projection: lower(test.column1_utf8view) AS c1
+02)--TableScan: test projection=[column1_utf8view]
+
+query T
+SELECT LOWER(column1_utf8view) as c1
+FROM test;
+----
+andrew
+xiangpeng
+raphael
+NULL
+
+## Ensure no casts for UPPER
+query TT
+EXPLAIN SELECT
+ UPPER(column1_utf8view) as c1
+FROM test;
+----
+logical_plan
+01)Projection: upper(test.column1_utf8view) AS c1
02)--TableScan: test projection=[column1_utf8view]
+query T
+SELECT UPPER(column1_utf8view) as c1
+FROM test;
+----
+ANDREW
+XIANGPENG
+RAPHAEL
+NULL
## Ensure no casts for LPAD
query TT
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]