You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "xudong963 (via GitHub)" <gi...@apache.org> on 2025/01/15 01:23:45 UTC
[PR] Return err if wildcard is not expanded before type coercion [datafusion]
xudong963 opened a new pull request, #14130:
URL: https://github.com/apache/datafusion/pull/14130
## 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.
-->
If users use the whole analyzer, they won't encounter the issue. But if only use the [TypeCoercionRewriter](https://docs.rs/datafusion/latest/datafusion/optimizer/analyzer/type_coercion/struct.TypeCoercionRewriter.html)(Yes, it's me), such as
```rust
if let LogicalPlan::Union(union) = logical_plan {
logical_plan = TypeCoercionRewriter::coerce_union(union)?;
}
```
and if there is the wildcard in the union, such as the test in the PR, I'll get the error `https://github.com/apache/datafusion/blob/main/datafusion/expr/src/logical_plan/plan.rs#L2138`.
## 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.
-->
Make the error report early and clear, the current change will directly tell the user what they are missing.
## 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)?
-->
Yes
## 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.
-->
No
--
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] Return err if wildcard is not expanded before type coercion [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on PR #14130:
URL: https://github.com/apache/datafusion/pull/14130#issuecomment-2594170021
thanks @alamb @jonahgao —ill merge it
--
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] Return err if wildcard is not expanded before type coercion [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14130:
URL: https://github.com/apache/datafusion/pull/14130#issuecomment-2592492306
I thin you can fix the CI test by using `assert_contains!` rather than checking the exact error message
--
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] Return err if wildcard is not expanded before type coercion [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 merged PR #14130:
URL: https://github.com/apache/datafusion/pull/14130
--
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] Return err if wildcard is not expanded before type coercion [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14130:
URL: https://github.com/apache/datafusion/pull/14130#issuecomment-2593495598
I merged this PR up from main and merged a clippy fix
--
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] Return err if wildcard is not expanded before type coercion [datafusion]
Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao commented on code in PR #14130:
URL: https://github.com/apache/datafusion/pull/14130#discussion_r1916749598
##########
datafusion/optimizer/tests/optimizer_integration.rs:
##########
@@ -387,6 +389,30 @@ fn select_correlated_predicate_subquery_with_uppercase_ident() {
assert_eq!(expected, format!("{plan}"));
}
+// The test should return an error
+// because the wildcard didn't be expanded before type coercion
+#[test]
+fn test_union_coercion_with_wildcard() -> Result<()> {
+ let dialect = PostgreSqlDialect {};
+ let context_provider = MyContextProvider::default();
+ let sql = "select * from (SELECT col_int32, col_uint32 FROM test) union all select * from(SELECT col_uint32, col_int32 FROM test)";
+ let statements = Parser::parse_sql(&dialect, sql)?;
+ let sql_to_rel = SqlToRel::new(&context_provider);
+ let logical_plan = sql_to_rel.sql_statement_to_plan(statements[0].clone())?;
+
+ if let LogicalPlan::Union(union) = logical_plan {
Review Comment:
We need to ensure that logical_plan is definitely a union. This could happen if `sql_statement_to_plan` changes in the future, and then this test would become invalid. We can do it like this:
```rust
let LogicalPlan::Union(union) = logical_plan else {
panic!("Expected Union plan");
};
let err = TypeCoercionRewriter::coerce_union(union)
.err()
.unwrap()
.to_string();
assert_contains!(
err,
"Error during planning: Wildcard should be expanded before 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@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