You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "devanbenz (via GitHub)" <gi...@apache.org> on 2024/09/04 02:10:24 UTC
[PR] Update concat_ws scalar function to support Utf8View [datafusion]
devanbenz opened a new pull request, #12309:
URL: https://github.com/apache/datafusion/pull/12309
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #11837
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#discussion_r1754908840
##########
datafusion/sqllogictest/test_files/string_view.slt:
##########
@@ -796,7 +796,7 @@ EXPLAIN SELECT
FROM test;
----
logical_plan
-01)Projection: concat_ws(Utf8(", "), CAST(test.column1_utf8view AS Utf8), CAST(test.column2_utf8view AS Utf8)) AS c
+01)Projection: concat_ws(Utf8(", "), test.column1_utf8view, test.column2_utf8view) AS c
Review Comment:
❤️
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#issuecomment-2346704111
Thanks again @devanbenz and @2010YOUY01
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "devanbenz (via GitHub)" <gi...@apache.org>.
devanbenz commented on code in PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#discussion_r1745784247
##########
datafusion/functions/src/string/concat_ws.rs:
##########
@@ -46,9 +45,8 @@ impl Default for ConcatWsFunc {
impl ConcatWsFunc {
pub fn new() -> Self {
- use DataType::*;
Self {
- signature: Signature::variadic(vec![Utf8], Volatility::Immutable),
+ signature: Signature::variadic_any(Volatility::Immutable),
Review Comment:
@alamb having a few issues with the `signature` here. I'm assuming that `variadic` will allow for a vector of common types but it effectively will coerce the other types in to whatever the first type is? In this case the separator is generally always a `Utf8` type which then causes the subsequent parameters to be cast to a utf8.
```
pub fn new() -> Self {
use DataType::*;
Self {
signature: Signature::variadic(
vec![Utf8, Utf8View, LargeUtf8],
Volatility::Immutable,
),
}
}
```
Is there something similar to:
`Exact(Utf8, variadic([utf8, utf8view, largeutf8]))` ?
Looking through the type signatures I don't see an established way to do that (that I'm aware of). Any suggestions?
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#discussion_r1750029406
##########
datafusion/functions/src/string/concat_ws.rs:
##########
@@ -155,21 +169,53 @@ impl ScalarUDFImpl for ConcatWsFunc {
let mut columns = Vec::with_capacity(args.len() - 1);
for arg in &args[1..] {
match arg {
- ColumnarValue::Scalar(ScalarValue::Utf8(maybe_value)) => {
+ ColumnarValue::Scalar(ScalarValue::Utf8(maybe_value))
+ | ColumnarValue::Scalar(ScalarValue::LargeUtf8(maybe_value))
+ | ColumnarValue::Scalar(ScalarValue::Utf8View(maybe_value)) => {
if let Some(s) = maybe_value {
data_size += s.len() * len;
columns.push(ColumnarValueRef::Scalar(s.as_bytes()));
}
}
ColumnarValue::Array(array) => {
- let string_array = as_string_array(array)?;
- data_size += string_array.values().len();
- let column = if array.is_nullable() {
- ColumnarValueRef::NullableArray(string_array)
- } else {
- ColumnarValueRef::NonNullableArray(string_array)
+ match array.data_type() {
+ DataType::Utf8 => {
+ let string_array = as_string_array(array)?;
+
+ data_size += string_array.values().len();
+ let column = if array.is_nullable() {
+ ColumnarValueRef::NullableArray(string_array)
+ } else {
+ ColumnarValueRef::NonNullableArray(string_array)
+ };
+ columns.push(column);
+ },
+ DataType::LargeUtf8 => {
+ let string_array = as_largestring_array(array);
+
+ data_size += string_array.values().len();
+ let column = if array.is_nullable() {
+ ColumnarValueRef::NullableLargeStringArray(string_array)
+ } else {
+ ColumnarValueRef::NonNullableLargeStringArray(string_array)
+ };
+ columns.push(column);
+ },
+ DataType::Utf8View => {
+ let string_array = as_string_view_array(array)?;
+
+ data_size += string_array.len();
Review Comment:
`data_size` is the estimated string array size after concatenation, I think here it should increment sum of inner buffers' size instead
(And everything else LGTM)
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #12309:
URL: https://github.com/apache/datafusion/pull/12309
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#discussion_r1746020502
##########
datafusion/functions/src/string/concat_ws.rs:
##########
@@ -46,9 +45,8 @@ impl Default for ConcatWsFunc {
impl ConcatWsFunc {
pub fn new() -> Self {
- use DataType::*;
Self {
- signature: Signature::variadic(vec![Utf8], Volatility::Immutable),
+ signature: Signature::variadic_any(Volatility::Immutable),
Review Comment:
> Looking through the type signatures I don't see an established way to do that (that I'm aware of). Any suggestions?
One way to do this is to explicitly list all the valid combinations using [`TypeSignature::OneOf`](https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.TypeSignature.html#variant.OneOf)
for example,
https://github.com/apache/datafusion/blob/e8ac93a0ffd490bd549872366bf7fd1b77ffd7f8/datafusion/functions/src/string/btrim.rs#L56-L62
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "devanbenz (via GitHub)" <gi...@apache.org>.
devanbenz commented on code in PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#discussion_r1750959141
##########
datafusion/functions/src/string/concat_ws.rs:
##########
@@ -155,21 +169,53 @@ impl ScalarUDFImpl for ConcatWsFunc {
let mut columns = Vec::with_capacity(args.len() - 1);
for arg in &args[1..] {
match arg {
- ColumnarValue::Scalar(ScalarValue::Utf8(maybe_value)) => {
+ ColumnarValue::Scalar(ScalarValue::Utf8(maybe_value))
+ | ColumnarValue::Scalar(ScalarValue::LargeUtf8(maybe_value))
+ | ColumnarValue::Scalar(ScalarValue::Utf8View(maybe_value)) => {
if let Some(s) = maybe_value {
data_size += s.len() * len;
columns.push(ColumnarValueRef::Scalar(s.as_bytes()));
}
}
ColumnarValue::Array(array) => {
- let string_array = as_string_array(array)?;
- data_size += string_array.values().len();
- let column = if array.is_nullable() {
- ColumnarValueRef::NullableArray(string_array)
- } else {
- ColumnarValueRef::NonNullableArray(string_array)
+ match array.data_type() {
+ DataType::Utf8 => {
+ let string_array = as_string_array(array)?;
+
+ data_size += string_array.values().len();
+ let column = if array.is_nullable() {
+ ColumnarValueRef::NullableArray(string_array)
+ } else {
+ ColumnarValueRef::NonNullableArray(string_array)
+ };
+ columns.push(column);
+ },
+ DataType::LargeUtf8 => {
+ let string_array = as_largestring_array(array);
+
+ data_size += string_array.values().len();
+ let column = if array.is_nullable() {
+ ColumnarValueRef::NullableLargeStringArray(string_array)
+ } else {
+ ColumnarValueRef::NonNullableLargeStringArray(string_array)
+ };
+ columns.push(column);
+ },
+ DataType::Utf8View => {
+ let string_array = as_string_view_array(array)?;
+
+ data_size += string_array.len();
Review Comment:
Using `data_size += string_array.data_buffers().len();` ?
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "devanbenz (via GitHub)" <gi...@apache.org>.
devanbenz commented on code in PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#discussion_r1750959141
##########
datafusion/functions/src/string/concat_ws.rs:
##########
@@ -155,21 +169,53 @@ impl ScalarUDFImpl for ConcatWsFunc {
let mut columns = Vec::with_capacity(args.len() - 1);
for arg in &args[1..] {
match arg {
- ColumnarValue::Scalar(ScalarValue::Utf8(maybe_value)) => {
+ ColumnarValue::Scalar(ScalarValue::Utf8(maybe_value))
+ | ColumnarValue::Scalar(ScalarValue::LargeUtf8(maybe_value))
+ | ColumnarValue::Scalar(ScalarValue::Utf8View(maybe_value)) => {
if let Some(s) = maybe_value {
data_size += s.len() * len;
columns.push(ColumnarValueRef::Scalar(s.as_bytes()));
}
}
ColumnarValue::Array(array) => {
- let string_array = as_string_array(array)?;
- data_size += string_array.values().len();
- let column = if array.is_nullable() {
- ColumnarValueRef::NullableArray(string_array)
- } else {
- ColumnarValueRef::NonNullableArray(string_array)
+ match array.data_type() {
+ DataType::Utf8 => {
+ let string_array = as_string_array(array)?;
+
+ data_size += string_array.values().len();
+ let column = if array.is_nullable() {
+ ColumnarValueRef::NullableArray(string_array)
+ } else {
+ ColumnarValueRef::NonNullableArray(string_array)
+ };
+ columns.push(column);
+ },
+ DataType::LargeUtf8 => {
+ let string_array = as_largestring_array(array);
+
+ data_size += string_array.values().len();
+ let column = if array.is_nullable() {
+ ColumnarValueRef::NullableLargeStringArray(string_array)
+ } else {
+ ColumnarValueRef::NonNullableLargeStringArray(string_array)
+ };
+ columns.push(column);
+ },
+ DataType::Utf8View => {
+ let string_array = as_string_view_array(array)?;
+
+ data_size += string_array.len();
Review Comment:
~~Using `data_size += string_array.data_buffers().len();` ? ~~
disregard I think I get what you mean I modified it to sum up the inner buffer vec on each iteration and use that as the size
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#issuecomment-2331888799
Marking as draft as it looks like we are still working out the CI checks
--
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
Re: [PR] Update concat_ws scalar function to support Utf8View [datafusion]
Posted by "devanbenz (via GitHub)" <gi...@apache.org>.
devanbenz commented on code in PR #12309:
URL: https://github.com/apache/datafusion/pull/12309#discussion_r1750959141
##########
datafusion/functions/src/string/concat_ws.rs:
##########
@@ -155,21 +169,53 @@ impl ScalarUDFImpl for ConcatWsFunc {
let mut columns = Vec::with_capacity(args.len() - 1);
for arg in &args[1..] {
match arg {
- ColumnarValue::Scalar(ScalarValue::Utf8(maybe_value)) => {
+ ColumnarValue::Scalar(ScalarValue::Utf8(maybe_value))
+ | ColumnarValue::Scalar(ScalarValue::LargeUtf8(maybe_value))
+ | ColumnarValue::Scalar(ScalarValue::Utf8View(maybe_value)) => {
if let Some(s) = maybe_value {
data_size += s.len() * len;
columns.push(ColumnarValueRef::Scalar(s.as_bytes()));
}
}
ColumnarValue::Array(array) => {
- let string_array = as_string_array(array)?;
- data_size += string_array.values().len();
- let column = if array.is_nullable() {
- ColumnarValueRef::NullableArray(string_array)
- } else {
- ColumnarValueRef::NonNullableArray(string_array)
+ match array.data_type() {
+ DataType::Utf8 => {
+ let string_array = as_string_array(array)?;
+
+ data_size += string_array.values().len();
+ let column = if array.is_nullable() {
+ ColumnarValueRef::NullableArray(string_array)
+ } else {
+ ColumnarValueRef::NonNullableArray(string_array)
+ };
+ columns.push(column);
+ },
+ DataType::LargeUtf8 => {
+ let string_array = as_largestring_array(array);
+
+ data_size += string_array.values().len();
+ let column = if array.is_nullable() {
+ ColumnarValueRef::NullableLargeStringArray(string_array)
+ } else {
+ ColumnarValueRef::NonNullableLargeStringArray(string_array)
+ };
+ columns.push(column);
+ },
+ DataType::Utf8View => {
+ let string_array = as_string_view_array(array)?;
+
+ data_size += string_array.len();
Review Comment:
~~Using `data_size += string_array.data_buffers().len();` ?~~
disregard I think I get what you mean I modified it to sum up the inner buffer vec on each iteration and use that as the size
--
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