Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement native support StringView for Octet Length #11906

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion datafusion/functions/src/string/octet_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl OctetLengthFunc {
Self {
signature: Signature::uniform(
1,
vec![Utf8, LargeUtf8],
vec![Utf8, LargeUtf8, Utf8View],
Volatility::Immutable,
),
}
Expand Down Expand Up @@ -84,6 +84,9 @@ impl ScalarUDFImpl for OctetLengthFunc {
ScalarValue::LargeUtf8(v) => Ok(ColumnarValue::Scalar(
ScalarValue::Int64(v.as_ref().map(|x| x.len() as i64)),
)),
ScalarValue::Utf8View(v) => Ok(ColumnarValue::Scalar(
ScalarValue::Int32(v.as_ref().map(|x| x.len() as i32)),
)),
_ => unreachable!(),
},
}
Expand Down Expand Up @@ -176,6 +179,36 @@ mod tests {
Int32,
Int32Array
);
test_function!(
OctetLengthFunc::new(),
&[ColumnarValue::Scalar(ScalarValue::Utf8View(Some(
String::from("joséjoséjoséjosé")
)))],
Ok(Some(20)),
i32,
Int32,
Int32Array
);
test_function!(
OctetLengthFunc::new(),
&[ColumnarValue::Scalar(ScalarValue::Utf8View(Some(
String::from("josé")
)))],
Ok(Some(5)),
i32,
Int32,
Int32Array
);
test_function!(
OctetLengthFunc::new(),
&[ColumnarValue::Scalar(ScalarValue::Utf8View(Some(
String::from("")
)))],
Ok(Some(0)),
i32,
Int32,
Int32Array
);

Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions datafusion/sqllogictest/test_files/string_view.slt
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,13 @@ logical_plan


## Ensure no casts for OCTET_LENGTH
## TODO https://github.com/apache/datafusion/issues/11858
query TT
EXPLAIN SELECT
OCTET_LENGTH(column1_utf8view) as c1
FROM test;
----
logical_plan
01)Projection: octet_length(CAST(test.column1_utf8view AS Utf8)) AS c1
01)Projection: octet_length(test.column1_utf8view) AS c1
02)--TableScan: test projection=[column1_utf8view]

## Ensure no casts for OVERLAY
Expand Down