You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "zjregee (via GitHub)" <gi...@apache.org> on 2025/02/21 12:42:21 UTC
[PR] [wip] replace TypeSignature::String with TypeSignature::Coercible [datafusion]
zjregee opened a new pull request, #14812:
URL: https://github.com/apache/datafusion/pull/14812
## Which issue does this PR close?
- Closes #14759.
## Rationale for this change
## What changes are included in this PR?
## Are these changes tested?
## Are there any user-facing changes?
--
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] replace TypeSignature::String with TypeSignature::Coercible for starts_with [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 merged PR #14812:
URL: https://github.com/apache/datafusion/pull/14812
--
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] replace TypeSignature::String with TypeSignature::Coercible for starts_with [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2686817387
Thanks @zjregee
--
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] [wip] replace TypeSignature::String with TypeSignature::Coercible [datafusion]
Posted by "zjregee (via GitHub)" <gi...@apache.org>.
zjregee commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2678272429
@jayzhan211. Got this, thank you very much for your help.
In addition, some functions will also have similar problems that need to be solved during the replacement process. Maybe we can split it into several PRs. I will try to complete all of this in the next few days.
--
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] replace TypeSignature::String with TypeSignature::Coercible for starts_with [datafusion]
Posted by "zjregee (via GitHub)" <gi...@apache.org>.
zjregee commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2680962268
I think this PR is ready for review now. cc: @jayzhan211
--
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] [wip] replace TypeSignature::String with TypeSignature::Coercible [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2674648296
https://github.com/apache/datafusion/blob/9ca09cf8f769a3f0a64dbc87ec84eb6fe08b36f6/datafusion/functions/src/string/starts_with.rs#L98-L138
The problem seems like you need to cast `args[0]` to the same as `args[1]` for `like` kernel function.
--
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] [wip] replace TypeSignature::String with TypeSignature::Coercible [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2678065061
@zjregee How about wrapping with Expr::Cast?
The logic should be something similar to this
```rust
let data_type_a = complex_expr.get_data_type();
let data_type_b = complex_expr.get_data_type();
if data_type_a != data_type_a {
target type = determine_common_type()
Expr::Cast(complex_expr, target type)
}
```
--
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] [wip] replace TypeSignature::String with TypeSignature::Coercible [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2678275102
> can split it into several PRs.
sure
--
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] replace TypeSignature::String with TypeSignature::Coercible for starts_with [datafusion]
Posted by "zjregee (via GitHub)" <gi...@apache.org>.
zjregee commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2681745896
Hi, @jayzhan211. I resubmitted the PR, and now we not only don't have redundant CAST, but also reduce the use of redundant CAST in some cases. I think the current treatment is appropriate, thank you very much for your help!
--
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] [wip] replace TypeSignature::String with TypeSignature::Coercible [datafusion]
Posted by "zjregee (via GitHub)" <gi...@apache.org>.
zjregee commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2677958302
Hi, @jayzhan211. I'm sorry to bother you again. Before I start replacing other functions, I'd like to get some confirmation from you that my current implementation and handling are as expected. Thanks a lot!
https://github.com/apache/datafusion/blob/9ca09cf8f769a3f0a64dbc87ec84eb6fe08b36f6/datafusion/functions/src/string/starts_with.rs#L98-L138
After some experimentation, I ended up not handling the type conversion in `simplify` of `starts_with` for the following reasons: this doesn't seem to cover all failure cases; If args[0] is of type `Expr::Column`, it seems that cannot do a direct type conversion here, because the type of args[0] is not deduced here.
The above is my superficial understanding. If there is anything that does not meet expectations, I hope to be corrected.
--
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] [wip] replace TypeSignature::String with TypeSignature::Coercible [datafusion]
Posted by "zjregee (via GitHub)" <gi...@apache.org>.
zjregee commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2674530942
Hi, @jayzhan211. I encountered some problems when trying to discard `TypeSignature::String`.
After a simple direct replacement, the original test failed. The specific test failure items are shown in this https://github.com/apache/datafusion/actions/runs/13457031878/job/37603204917?pr=14812.
I think the problem may be caused by the need to modify the logic of this part of the code in this function https://github.com/zjregee/datafusion/blob/replace-type-signature/datafusion/expr/src/type_coercion/functions.rs#L603-L636, but I am not sure, and hope to get some help and 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] replace TypeSignature::String with TypeSignature::Coercible for starts_with [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#discussion_r1969207266
##########
datafusion/sqllogictest/test_files/parquet.slt:
##########
@@ -619,13 +619,13 @@ query TT
explain select * from foo where starts_with(column1, 'f');
----
logical_plan
-01)Filter: foo.column1 LIKE Utf8View("f%")
-02)--TableScan: foo projection=[column1], partial_filters=[foo.column1 LIKE Utf8View("f%")]
+01)Filter: CAST(foo.column1 AS Utf8) LIKE Utf8("f%")
Review Comment:
In this case, casting array is less efficient, since you only has 2 characters "f%" on right hand side.
Even more, instead of calling `make_scalar_function`, we can wrap scalar case to arrow::Scalar and call `arrow::compute::kernels::comparison::starts_with` directly.
It accepts Datum
```rust
pub fn starts_with(left: &dyn Datum, right: &dyn Datum) -> Result<BooleanArray, ArrowError> {
like_op(Op::StartsWith, left, right)
}
```
--
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] [wip] replace TypeSignature::String with TypeSignature::Coercible [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#issuecomment-2678247545
https://github.com/apache/datafusion/blob/6c5f214643fe81affcad5f3aa9031f02c4390bf0/datafusion/optimizer/src/analyzer/type_coercion.rs#L391-L415
This is how types coerced in like expression, I guess we might need a similar coerce logic
--
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] replace TypeSignature::String with TypeSignature::Coercible for starts_with [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #14812:
URL: https://github.com/apache/datafusion/pull/14812#discussion_r1969204488
##########
datafusion/functions/src/string/starts_with.rs:
##########
@@ -23,15 +23,19 @@ use arrow::datatypes::DataType;
use datafusion_expr::simplify::{ExprSimplifyResult, SimplifyInfo};
use crate::utils::make_scalar_function;
+use datafusion_common::types::logical_string;
use datafusion_common::{internal_err, Result, ScalarValue};
-use datafusion_expr::{ColumnarValue, Documentation, Expr, Like};
-use datafusion_expr::{ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility};
+use datafusion_expr::{
+ cast, Coercion, ColumnarValue, Documentation, Expr, Like, ScalarFunctionArgs,
+ ScalarUDFImpl, Signature, TypeSignatureClass, Volatility,
+};
use datafusion_macros::user_doc;
/// Returns true if string starts with prefix.
/// starts_with('alphabet', 'alph') = 't'
pub fn starts_with(args: &[ArrayRef]) -> Result<ArrayRef> {
- let result = arrow::compute::kernels::comparison::starts_with(&args[0], &args[1])?;
+ let arg0 = arrow::compute::kernels::cast::cast(&args[0], args[1].data_type())?;
Review Comment:
I think better to use `string_coercion` and `binary_to_string_coercion`
##########
datafusion/functions/src/string/starts_with.rs:
##########
@@ -127,7 +137,7 @@ impl ScalarUDFImpl for StartsWithFunc {
return Ok(ExprSimplifyResult::Simplified(Expr::Like(Like {
negated: false,
- expr: Box::new(args[0].clone()),
+ expr: Box::new(cast(args[0].clone(), scalar_value.data_type())),
Review Comment:
I think better to use string_coercion and binary_to_string_coercion
--
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