You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "0lai0 (via GitHub)" <gi...@apache.org> on 2026/03/08 10:14:29 UTC
[PR] fix: Support on all-literal RLIKE expression [datafusion-comet]
0lai0 opened a new pull request, #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647
## 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 #3343
## 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.
-->
When `ConstantFolding` is disabled, all-literal RLIKE expressions crash the native engine with a misleading error. The engine should handle scalar literals gracefully.
## 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.
-->
- Fixed all-literal RLIKE expression handling in native engine
- Added proper scalar evaluation for RLIKE with literal inputs
- Improved error handling and fallback logic
## How 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)?
-->
- Added tests for all-literal RLIKE with `ConstantFolding` disabled
- Verified `rlike_enabled.sql` test now passes
- All existing RLIKE tests continue to pass
- `./mvnw test -Dsuites="org.apache.comet.CometSqlFileTestSuite rlike_enabled" -Dtest=none`
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#issuecomment-4045949769
Thank you, @0lai0 !
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#discussion_r2912621961
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -21,7 +21,9 @@ use arrow::array::types::Int32Type;
use arrow::array::{Array, BooleanArray, DictionaryArray, RecordBatch, StringArray};
use arrow::compute::take;
use arrow::datatypes::{DataType, Schema};
-use datafusion::common::{internal_err, Result};
+use datafusion::common::{internal_err, Result, ScalarValue};
+#[cfg(test)]
+use datafusion::physical_expr::expressions::Literal;
Review Comment:
The import should just be moved inside `mod test` which is already behind the `#[cfg(test)]` guard
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on code in PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#discussion_r2916945340
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -165,3 +181,26 @@ impl PhysicalExpr for RLike {
Display::fmt(self, f)
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use datafusion::physical_expr::expressions::Literal;
+
+ #[test]
+ fn test_rlike_scalar_utf8_literal() {
+ let expr = RLike::try_new(
+ Arc::new(Literal::new(ScalarValue::Utf8(Some("Rose".to_string())))),
Review Comment:
This tests the happy path (`Utf8(Some)`).
It would be good to also add a test case for `Utf8(None)`.
You could also extend it to cover the LargeUtf8 and Utf8View paths too:
```rust
for scalar in &[ScalarValue::Utf8(Some("Utf8".to_string())), ScalarValue::LargeUtf8(Some("LargeUtf8".to_string())), ScalarValue::Utf8View(Some("Utf8View".to_string()))] { ... }
```
and some non-Utf8 type, e.g. ScalarValue::Boolean to trigger the error.
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -140,8 +140,24 @@ impl PhysicalExpr for RLike {
let array = self.is_match(inputs);
Ok(ColumnarValue::Array(Arc::new(array)))
}
- ColumnarValue::Scalar(_) => {
- internal_err!("non scalar regexp patterns are not supported")
+ ColumnarValue::Scalar(scalar) => {
+ if scalar.is_null() {
+ return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
+ }
+
+ let is_match = match scalar {
+ ScalarValue::Utf8(Some(s))
+ | ScalarValue::LargeUtf8(Some(s))
+ | ScalarValue::Utf8View(Some(s)) => self.pattern.is_match(s.as_str()),
Review Comment:
```suggestion
| ScalarValue::Utf8View(Some(s)) => self.pattern.is_match(&s),
```
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "coderfender (via GitHub)" <gi...@apache.org>.
coderfender commented on code in PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#discussion_r2902409152
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -140,8 +140,30 @@ impl PhysicalExpr for RLike {
let array = self.is_match(inputs);
Ok(ColumnarValue::Array(Arc::new(array)))
}
- ColumnarValue::Scalar(_) => {
- internal_err!("non scalar regexp patterns are not supported")
+ ColumnarValue::Scalar(scalar) => {
+ // Handle scalar input (all-literal RLIKE expressions)
+ // This case occurs when ConstantFolding is disabled and both
+ // the input string and pattern are literals
+ if scalar.is_null() {
+ // NULL RLIKE pattern -> NULL result
+ return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
+ }
+
+ // Extract string value from scalar and match pattern
+ // We handle each type separately to avoid lifetime issues with Utf8View
+ let is_match = match scalar {
+ ScalarValue::Utf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::LargeUtf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::Utf8View(Some(s)) => self.pattern.is_match(s.as_str()),
Review Comment:
@0lai0 would we ever get a UTF-8 input from the spark side?
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -140,8 +140,30 @@ impl PhysicalExpr for RLike {
let array = self.is_match(inputs);
Ok(ColumnarValue::Array(Arc::new(array)))
}
- ColumnarValue::Scalar(_) => {
- internal_err!("non scalar regexp patterns are not supported")
+ ColumnarValue::Scalar(scalar) => {
+ // Handle scalar input (all-literal RLIKE expressions)
+ // This case occurs when ConstantFolding is disabled and both
+ // the input string and pattern are literals
+ if scalar.is_null() {
+ // NULL RLIKE pattern -> NULL result
+ return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
+ }
+
+ // Extract string value from scalar and match pattern
+ // We handle each type separately to avoid lifetime issues with Utf8View
+ let is_match = match scalar {
+ ScalarValue::Utf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::LargeUtf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::Utf8View(Some(s)) => self.pattern.is_match(s.as_str()),
+ _ => {
+ return internal_err!(
Review Comment:
@0lai0 could we also add test on rust side ?
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "coderfender (via GitHub)" <gi...@apache.org>.
coderfender commented on code in PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#discussion_r2902409152
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -140,8 +140,30 @@ impl PhysicalExpr for RLike {
let array = self.is_match(inputs);
Ok(ColumnarValue::Array(Arc::new(array)))
}
- ColumnarValue::Scalar(_) => {
- internal_err!("non scalar regexp patterns are not supported")
+ ColumnarValue::Scalar(scalar) => {
+ // Handle scalar input (all-literal RLIKE expressions)
+ // This case occurs when ConstantFolding is disabled and both
+ // the input string and pattern are literals
+ if scalar.is_null() {
+ // NULL RLIKE pattern -> NULL result
+ return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
+ }
+
+ // Extract string value from scalar and match pattern
+ // We handle each type separately to avoid lifetime issues with Utf8View
+ let is_match = match scalar {
+ ScalarValue::Utf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::LargeUtf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::Utf8View(Some(s)) => self.pattern.is_match(s.as_str()),
Review Comment:
@0lai0 would we ever get a `UTF8View` input from the spark side?
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on code in PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#discussion_r2902978794
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -140,8 +140,30 @@ impl PhysicalExpr for RLike {
let array = self.is_match(inputs);
Ok(ColumnarValue::Array(Arc::new(array)))
}
- ColumnarValue::Scalar(_) => {
- internal_err!("non scalar regexp patterns are not supported")
+ ColumnarValue::Scalar(scalar) => {
+ // Handle scalar input (all-literal RLIKE expressions)
+ // This case occurs when ConstantFolding is disabled and both
+ // the input string and pattern are literals
+ if scalar.is_null() {
+ // NULL RLIKE pattern -> NULL result
+ return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
+ }
+
+ // Extract string value from scalar and match pattern
+ // We handle each type separately to avoid lifetime issues with Utf8View
+ let is_match = match scalar {
+ ScalarValue::Utf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::LargeUtf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::Utf8View(Some(s)) => self.pattern.is_match(s.as_str()),
Review Comment:
Yes, On the current Spark -> Comet proto -> native planner path, string literals are deserialized as ScalarValue::Utf8. So I think keeping Utf8 handling here is necessary.
Let me know if I missed anything.
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#issuecomment-4036086066
Thanks @andygrove for the review. PR updated.
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on code in PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#discussion_r2902980706
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -140,8 +140,30 @@ impl PhysicalExpr for RLike {
let array = self.is_match(inputs);
Ok(ColumnarValue::Array(Arc::new(array)))
}
- ColumnarValue::Scalar(_) => {
- internal_err!("non scalar regexp patterns are not supported")
+ ColumnarValue::Scalar(scalar) => {
+ // Handle scalar input (all-literal RLIKE expressions)
+ // This case occurs when ConstantFolding is disabled and both
+ // the input string and pattern are literals
+ if scalar.is_null() {
+ // NULL RLIKE pattern -> NULL result
+ return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
+ }
+
+ // Extract string value from scalar and match pattern
+ // We handle each type separately to avoid lifetime issues with Utf8View
+ let is_match = match scalar {
+ ScalarValue::Utf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::LargeUtf8(Some(s)) => self.pattern.is_match(s.as_str()),
+ ScalarValue::Utf8View(Some(s)) => self.pattern.is_match(s.as_str()),
+ _ => {
+ return internal_err!(
Review Comment:
Sure, thanks @coderfender.
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g merged PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on code in PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#discussion_r2918670327
##########
native/spark-expr/src/predicate_funcs/rlike.rs:
##########
@@ -165,3 +181,26 @@ impl PhysicalExpr for RLike {
Display::fmt(self, f)
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use datafusion::physical_expr::expressions::Literal;
+
+ #[test]
+ fn test_rlike_scalar_utf8_literal() {
+ let expr = RLike::try_new(
+ Arc::new(Literal::new(ScalarValue::Utf8(Some("Rose".to_string())))),
Review Comment:
Thanks @martin-g PR updated.
--
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] fix: Support on all-literal RLIKE expression [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on PR #3647:
URL: https://github.com/apache/datafusion-comet/pull/3647#issuecomment-4046472366
Thanks @coderfender , @andygrove and @martin-g
--
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