You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "tlm365 (via GitHub)" <gi...@apache.org> on 2024/08/26 08:21:06 UTC
[PR] Implement native support StringView for `CONTAINS` function [datafusion]
tlm365 opened a new pull request, #12168:
URL: https://github.com/apache/datafusion/pull/12168
## 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 #11838.
## 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] Implement native support StringView for `CONTAINS` function [datafusion]
Posted by "tlm365 (via GitHub)" <gi...@apache.org>.
tlm365 commented on code in PR #12168:
URL: https://github.com/apache/datafusion/pull/12168#discussion_r1747839020
##########
datafusion/functions/src/regex/regexp_common.rs:
##########
@@ -0,0 +1,121 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Common utilities for implementing regex functions
+
+use crate::string::common::StringArrayType;
+
+use arrow::array::{Array, ArrayDataBuilder, BooleanArray};
+use arrow::datatypes::DataType;
+use arrow_buffer::{BooleanBufferBuilder, NullBuffer};
+use datafusion_common::DataFusionError;
+use regex::Regex;
+
+use std::collections::HashMap;
+
+#[cfg(doc)]
+use arrow::array::{LargeStringArray, StringArray, StringViewArray};
+/// Perform SQL `array ~ regex_array` operation on
+/// [`StringArray`] / [`LargeStringArray`] / [`StringViewArray`].
+///
+/// If `regex_array` element has an empty value, the corresponding result value is always true.
+///
+/// `flags_array` are optional [`StringArray`] / [`LargeStringArray`] / [`StringViewArray`] flag,
+/// which allow special search modes, such as case-insensitive and multi-line mode.
+/// See the documentation [here](https://docs.rs/regex/1.5.4/regex/#grouping-and-flags)
+/// for more information.
+///
+/// It is inspired / copied from `regexp_is_match_utf8` [arrow-rs].
Review Comment:
> Is it because the arrow kernel doesn't support StringView yet?
Yes, you're right. I intend to update this one in upstream [arrow-rs]. After that, we can eliminate it from this location.
--
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] Implement native support StringView for `CONTAINS` function [datafusion]
Posted by "tlm365 (via GitHub)" <gi...@apache.org>.
tlm365 commented on PR #12168:
URL: https://github.com/apache/datafusion/pull/12168#issuecomment-2329317580
> I am wondering since the `contains` udf relies on regex (which isn't documented at all btw) whether it should be a wrapper for `regexp_like` and moved to the regex module? The order of the arguments is reversed and there is no flags for `contains` but functionally I think the two are equivalent.
yeah, I also mentioned the similar of `contains` and `regex_like` that you mentioned above in #12180. But somehow I chose to implement it in `string` module. Let me try to implement it in `regex` module as your point - I also think it makes more sense.
--
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] Implement native support StringView for `CONTAINS` function [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12168:
URL: https://github.com/apache/datafusion/pull/12168#discussion_r1750195776
##########
datafusion/functions/src/regexp_common.rs:
##########
@@ -0,0 +1,121 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Common utilities for implementing regex functions
+
+use crate::string::common::StringArrayType;
+
+use arrow::array::{Array, ArrayDataBuilder, BooleanArray};
+use arrow::datatypes::DataType;
+use arrow_buffer::{BooleanBufferBuilder, NullBuffer};
+use datafusion_common::DataFusionError;
+use regex::Regex;
+
+use std::collections::HashMap;
+
+#[cfg(doc)]
+use arrow::array::{LargeStringArray, StringArray, StringViewArray};
+/// Perform SQL `array ~ regex_array` operation on
+/// [`StringArray`] / [`LargeStringArray`] / [`StringViewArray`].
+///
+/// If `regex_array` element has an empty value, the corresponding result value is always true.
+///
+/// `flags_array` are optional [`StringArray`] / [`LargeStringArray`] / [`StringViewArray`] flag,
+/// which allow special search modes, such as case-insensitive and multi-line mode.
+/// See the documentation [here](https://docs.rs/regex/1.5.4/regex/#grouping-and-flags)
+/// for more information.
+///
+/// It is inspired / copied from `regexp_is_match_utf8` [arrow-rs].
Review Comment:
I filed a ticket to track moving this upstream in https://github.com/apache/arrow-rs/issues/6370
```suggestion
/// It is inspired / copied from `regexp_is_match_utf8` [arrow-rs].
///
/// Can remove when <https://github.com/apache/arrow-rs/issues/6370> is implemented upstream
```
--
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] Implement native support StringView for `CONTAINS` function [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12168:
URL: https://github.com/apache/datafusion/pull/12168#discussion_r1747741481
##########
datafusion/functions/Cargo.toml:
##########
@@ -52,9 +52,9 @@ encoding_expressions = ["base64", "hex"]
# enable math functions
math_expressions = []
# enable regular expressions
-regex_expressions = ["regex"]
+regex_expressions = ["regex", "string_expressions"]
Review Comment:
I don't understand the need for this change (which seems to basically make `regex_expressions` and `string_expressions` the same feature flag)
I see you added `datafusion/functions/src/regex/regexp_common.rs`, but that seems only to be used by string functions. Perhaps it would be beter placed somewhere in functions/src/ 🤔
##########
datafusion/functions/src/regex/regexp_common.rs:
##########
@@ -0,0 +1,121 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Common utilities for implementing regex functions
+
+use crate::string::common::StringArrayType;
+
+use arrow::array::{Array, ArrayDataBuilder, BooleanArray};
+use arrow::datatypes::DataType;
+use arrow_buffer::{BooleanBufferBuilder, NullBuffer};
+use datafusion_common::DataFusionError;
+use regex::Regex;
+
+use std::collections::HashMap;
+
+#[cfg(doc)]
+use arrow::array::{LargeStringArray, StringArray, StringViewArray};
+/// Perform SQL `array ~ regex_array` operation on
+/// [`StringArray`] / [`LargeStringArray`] / [`StringViewArray`].
+///
+/// If `regex_array` element has an empty value, the corresponding result value is always true.
+///
+/// `flags_array` are optional [`StringArray`] / [`LargeStringArray`] / [`StringViewArray`] flag,
+/// which allow special search modes, such as case-insensitive and multi-line mode.
+/// See the documentation [here](https://docs.rs/regex/1.5.4/regex/#grouping-and-flags)
+/// for more information.
+///
+/// It is inspired / copied from `regexp_is_match_utf8` [arrow-rs].
Review Comment:
I wonder why we need to haev our own copy here? Is it because the arrow kernel doesn't support StringView yet?
--
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] Implement native support StringView for `CONTAINS` function [datafusion]
Posted by "tlm365 (via GitHub)" <gi...@apache.org>.
tlm365 commented on code in PR #12168:
URL: https://github.com/apache/datafusion/pull/12168#discussion_r1747837674
##########
datafusion/functions/Cargo.toml:
##########
@@ -52,9 +52,9 @@ encoding_expressions = ["base64", "hex"]
# enable math functions
math_expressions = []
# enable regular expressions
-regex_expressions = ["regex"]
+regex_expressions = ["regex", "string_expressions"]
Review Comment:
@alamb thanks for reviewing 🙏
> Perhaps it would be beter placed somewhere in functions/src/
oh, I agree, will update it soon
--
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] Implement native support StringView for `CONTAINS` function [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #12168:
URL: https://github.com/apache/datafusion/pull/12168
--
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] Implement native support StringView for `CONTAINS` function [datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on PR #12168:
URL: https://github.com/apache/datafusion/pull/12168#issuecomment-2325344149
I am wondering since the `contains` udf relies on regex (which isn't documented at all btw) whether it should be a wrapper for `regexp_like` and moved to the regex module? The order of the arguments is reversed and there is no flags for `contains` but functionally I think the two are equivalent.
--
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] Implement native support StringView for `CONTAINS` function [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12168:
URL: https://github.com/apache/datafusion/pull/12168#issuecomment-2340339196
Thanks again @tlm365
--
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