You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/08/24 18:19:39 UTC
[GitHub] [arrow-datafusion] andygrove opened a new pull request, #3254: Early draft: Add type coercion for UDFs in logical plan
andygrove opened a new pull request, #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254
# 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 # TBD
This builds on other PRs that are still open.
# 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.
-->
We currently perform type coercion for UDFs in the physical planner/optimizer. I would like to have this logic in the logical plan so that other projects (such as Dask SQL) can benefit from this.
# 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.
-->
- Update the `TypeCoercion` rule to support Scalar UDFs
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
Yes, logical plans will be different in some cases.
<!--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1238205921
@alamb Here is another type coercion rule that we can now add
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove merged pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
andygrove merged PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#discussion_r963811265
##########
datafusion/optimizer/src/type_coercion.rs:
##########
@@ -116,18 +117,61 @@ impl ExprRewriter for TypeCoercionRewriter {
}
}
}
+ Expr::ScalarUDF { fun, args } => {
+ let new_expr = coerce_arguments_for_signature(
+ args.as_slice(),
+ &self.schema,
+ &fun.signature,
+ )?;
+ Ok(Expr::ScalarUDF {
+ fun: fun.clone(),
+ args: new_expr,
+ })
+ }
_ => Ok(expr),
}
}
}
+/// Returns `expressions` coerced to types compatible with
+/// `signature`, if possible.
+///
+/// See the module level documentation for more detail on coercion.
+pub fn coerce_arguments_for_signature(
Review Comment:
I feel like this code should already exist somewhere and it would be great to consolidate into a single implementation rather than have multiple implementations around
##########
datafusion/optimizer/src/type_coercion.rs:
##########
@@ -167,4 +211,64 @@ mod test {
\n EmptyRelation", &format!("{:?}", plan));
Ok(())
}
+
+ #[test]
+ fn scalar_udf() -> Result<()> {
+ let empty = empty();
+ let return_type: ReturnTypeFunction =
+ Arc::new(move |_| Ok(Arc::new(DataType::Utf8)));
+ let fun: ScalarFunctionImplementation = Arc::new(move |_| unimplemented!());
+ let udf = Expr::ScalarUDF {
+ fun: Arc::new(ScalarUDF::new(
+ "TestScalarUDF",
+ &Signature::uniform(1, vec![DataType::Float32], Volatility::Stable),
+ &return_type,
+ &fun,
+ )),
+ args: vec![lit(123_i32)],
+ };
+ let plan = LogicalPlan::Projection(Projection::try_new(vec![udf], empty, None)?);
+ let rule = TypeCoercion::new();
+ let mut config = OptimizerConfig::default();
+ let plan = rule.optimize(&plan, &mut config)?;
+ assert_eq!(
+ "Projection: TestScalarUDF(CAST(Int32(123) AS Float32))\n EmptyRelation",
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1239204430
> @andygrove @alamb Can we give a plan for the migration of type coercion?
@liukun4515 there is https://github.com/apache/arrow-datafusion/issues/2355 (which I will also add to the description of this PR). Is that what you had in mind?
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1239349379
> > > After the refactor of the type coercion, do we need to forbid to creation of physical expr directly?
> >
> >
> > I would personally prefer allow creating PhysicalExprs but not providing automatic coercion (leaving it up to the user to use the proper types)
>
> A+B will get the common data type `C` in the logical phase, but it will also affected in the physical phase. C+C will convert the D data type, but I can't find this changes after this #3222 merged. I want to find out why
I think I find a bug https://github.com/apache/arrow-datafusion/blob/c359018baa8bbb0a227e83df948c903cde4d701f/datafusion/expr/src/binary_rule.rs#L293 for the type coercion in arithmetic op.
@andygrove @alamb
If we move the type coercion to the logical phase, the type coercion will apply the binary op twice.
For the arithmetic operation, the decimal128(10,0) + decimal128(10,0) will get decimal128(11,0).
If the rule was applied to the op twice, the result type should be decimal(12,0);
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1238274143
I will review it tomorrow, it's too later for me today
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1238271777
@andygrove @alamb Can we give a plan for the migration of type 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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ursabot commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1239592679
Benchmark runs are scheduled for baseline = e6d13646c746c576b5eed8c9a21ac59d783f2910 and contender = 7c04964fee0210411f02bf3938aefe7773710e42. 7c04964fee0210411f02bf3938aefe7773710e42 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/2ea9b966c7014bfb82788d80a516f920...8079a23262854327ac98ee2664d0c4ea/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ddf49c567eaf495aa80d6332f5e4f8c3...2bfb2d60041a442d8079defab09fb2ff/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/d676bd4f36db4fc4b11abcc43e6b8eb6...2b2ecd2eebfb44599fae3cad69648a6e/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/1d48177793a04a089c2621c17ac0bef8...c3ff83d2382d43ba891b308da687a1ce/)
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#discussion_r964670550
##########
datafusion/optimizer/src/type_coercion.rs:
##########
@@ -116,18 +117,61 @@ impl ExprRewriter for TypeCoercionRewriter {
}
}
}
+ Expr::ScalarUDF { fun, args } => {
+ let new_expr = coerce_arguments_for_signature(
+ args.as_slice(),
+ &self.schema,
+ &fun.signature,
+ )?;
+ Ok(Expr::ScalarUDF {
+ fun: fun.clone(),
+ args: new_expr,
+ })
+ }
_ => Ok(expr),
}
}
}
+/// Returns `expressions` coerced to types compatible with
+/// `signature`, if possible.
+///
+/// See the module level documentation for more detail on coercion.
+pub fn coerce_arguments_for_signature(
Review Comment:
Do we need to public this method?
I think it's better to make it private.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1239437232
> > > > After the refactor of the type coercion, do we need to forbid to creation of physical expr directly?
> > >
> > >
> > > I would personally prefer allow creating PhysicalExprs but not providing automatic coercion (leaving it up to the user to use the proper types)
> >
> >
> > A+B will get the common data type `C` in the logical phase, but it will also affected in the physical phase. C+C will convert the D data type, but I can't find this changes after this #3222 merged. I want to find out why
>
> I think I find a bug
>
> https://github.com/apache/arrow-datafusion/blob/c359018baa8bbb0a227e83df948c903cde4d701f/datafusion/expr/src/binary_rule.rs#L293
> for the type coercion in arithmetic op.
>
> @andygrove @alamb
>
> If we move the type coercion to the logical phase, the type coercion will apply the binary op twice. For the arithmetic operation, the decimal128(10,0) + decimal128(10,0) will get decimal128(11,0). If the rule was applied to the op twice, the result type should be decimal(12,0);
Thanks @liukun4515. I have filed https://github.com/apache/arrow-datafusion/issues/3388 to track this. I will look at this next.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1238273453
> 👍 looks great @andygrove
>
> This will likely conflict with #3379
>
> For what it is worth, I would love to move _all_ type coercion rules out of physical planning and into this phase (aka consolidate all coercion)
we can do this after migrating the type coercion from the physical phase to logical phase.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1239241068
> > After the refactor of the type coercion, do we need to forbid to creation of physical expr directly?
>
> I would personally prefer allow creating PhysicalExprs but not providing automatic coercion (leaving it up to the user to use the proper types)
A+B will get the common data type `C` in the logical phase, but it will also affected in the physical phase.
C+C will convert the D data type, but I can't find this changes after this https://github.com/apache/arrow-datafusion/pull/3222 merged.
I want to find out why
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] codecov-commenter commented on pull request #3254: Early draft: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1226141556
# [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/3254?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#3254](https://codecov.io/gh/apache/arrow-datafusion/pull/3254?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (e6b4df3) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/bdc56ca3d9b3149267682cf4a95692251269efec?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (bdc56ca) will **increase** coverage by `0.08%`.
> The diff coverage is `97.45%`.
```diff
@@ Coverage Diff @@
## master #3254 +/- ##
==========================================
+ Coverage 85.84% 85.93% +0.08%
==========================================
Files 293 294 +1
Lines 53246 53419 +173
==========================================
+ Hits 45710 45905 +195
+ Misses 7536 7514 -22
```
| [Impacted Files](https://codecov.io/gh/apache/arrow-datafusion/pull/3254?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [datafusion/core/tests/parquet\_pruning.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3Rlc3RzL3BhcnF1ZXRfcHJ1bmluZy5ycw==) | `99.43% <ø> (ø)` | |
| [datafusion/core/tests/sql/aggregates.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3Rlc3RzL3NxbC9hZ2dyZWdhdGVzLnJz) | `99.37% <ø> (ø)` | |
| [datafusion/core/tests/sql/decimal.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3Rlc3RzL3NxbC9kZWNpbWFsLnJz) | `100.00% <ø> (ø)` | |
| [datafusion/core/tests/sql/expr.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3Rlc3RzL3NxbC9leHByLnJz) | `99.85% <ø> (+<0.01%)` | :arrow_up: |
| [datafusion/core/tests/sql/joins.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3Rlc3RzL3NxbC9qb2lucy5ycw==) | `99.33% <ø> (ø)` | |
| [datafusion/core/tests/sql/predicates.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3Rlc3RzL3NxbC9wcmVkaWNhdGVzLnJz) | `100.00% <ø> (ø)` | |
| [datafusion/core/tests/sql/subqueries.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3Rlc3RzL3NxbC9zdWJxdWVyaWVzLnJz) | `94.24% <ø> (-0.09%)` | :arrow_down: |
| [datafusion/core/tests/sql/timestamp.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3Rlc3RzL3NxbC90aW1lc3RhbXAucnM=) | `99.65% <ø> (ø)` | |
| [datafusion/core/src/datasource/view.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9kYXRhc291cmNlL3ZpZXcucnM=) | `86.54% <86.95%> (-0.03%)` | :arrow_down: |
| [datafusion/optimizer/src/type\_coercion.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL3R5cGVfY29lcmNpb24ucnM=) | `99.02% <99.02%> (ø)` | |
| ... and [23 more](https://codecov.io/gh/apache/arrow-datafusion/pull/3254/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1239213873
After the refactor of the type coercion, do we need to forbid to creation of physical expr directly
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#discussion_r963838566
##########
datafusion/optimizer/src/type_coercion.rs:
##########
@@ -116,18 +117,61 @@ impl ExprRewriter for TypeCoercionRewriter {
}
}
}
+ Expr::ScalarUDF { fun, args } => {
+ let new_expr = coerce_arguments_for_signature(
+ args.as_slice(),
+ &self.schema,
+ &fun.signature,
+ )?;
+ Ok(Expr::ScalarUDF {
+ fun: fun.clone(),
+ args: new_expr,
+ })
+ }
_ => Ok(expr),
}
}
}
+/// Returns `expressions` coerced to types compatible with
+/// `signature`, if possible.
+///
+/// See the module level documentation for more detail on coercion.
+pub fn coerce_arguments_for_signature(
Review Comment:
Yes, this is adapted from the `coerce` method in the `physical-expr` crate that operates on physical expressions rather than logical expressions.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1239217652
> After the refactor of the type coercion, do we need to forbid to creation of physical expr directly?
I would personally prefer allow creating PhysicalExprs but not providing automatic coercion (leaving it up to the user to use the proper types)
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #3254: Add type coercion for UDFs in logical plan
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #3254:
URL: https://github.com/apache/arrow-datafusion/pull/3254#issuecomment-1239345990
> > > After the refactor of the type coercion, do we need to forbid to creation of physical expr directly?
> >
> >
> > I would personally prefer allow creating PhysicalExprs but not providing automatic coercion (leaving it up to the user to use the proper types)
>
> A+B will get the common data type `C` in the logical phase, but it will also affected in the physical phase. C+C will convert the D data type, but I can't find this changes after this #3222 merged. I want to find out why
I think I find a bug https://github.com/apache/arrow-datafusion/blob/c359018baa8bbb0a227e83df948c903cde4d701f/datafusion/expr/src/binary_rule.rs#L293 for the type coercion in arithmetic op.
@andygrove @alamb
If we move the type coercion to the logical phase, the type coercion will apply the binary op twice.
For the arithmetic operation, the decimal128(10,0) + decimal128(10,0) will get decimal128(11,0).
If the rule was applied to the op twice, the result type should be decimal(12,0);
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org