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 2023/01/07 08:53:26 UTC
[GitHub] [arrow-datafusion] Jefffrey opened a new pull request, #4840: Support wildcard select on multiple column using joins
Jefffrey opened a new pull request, #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840
# 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 #4674
# 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.
-->
Support proper wildcard expansion on multiple column USING joins.
# 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)?
-->
New unit 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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] Jefffrey commented on a diff in pull request #4840: Support wildcard select on multiple column using joins
Posted by GitBox <gi...@apache.org>.
Jefffrey commented on code in PR #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840#discussion_r1063978094
##########
datafusion/expr/src/utils.rs:
##########
@@ -150,13 +150,23 @@ pub fn expand_wildcard(schema: &DFSchema, plan: &LogicalPlan) -> Result<Vec<Expr
let using_columns = plan.using_columns()?;
let columns_to_skip = using_columns
.into_iter()
- // For each USING JOIN condition, only expand to one column in projection
+ // For each USING JOIN condition, only expand to one of each join column in projection
.flat_map(|cols| {
let mut cols = cols.into_iter().collect::<Vec<_>>();
// sort join columns to make sure we consistently keep the same
// qualified column
cols.sort();
- cols.into_iter().skip(1)
+ let mut out_column_names: HashSet<String> = HashSet::new();
+ cols.into_iter()
+ .filter_map(|c| {
+ if out_column_names.contains(&c.name) {
+ Some(c)
+ } else {
+ out_column_names.insert(c.name);
+ None
+ }
+ })
+ .collect::<Vec<_>>()
Review Comment:
main fix is here, since instead of only skipping the first column (which is based on assumption of using join with only one column), actually keep track of which columns to skip, allowing only one set of the join columns to be output
--
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] Jefffrey commented on a diff in pull request #4840: Support wildcard select on multiple column using joins
Posted by GitBox <gi...@apache.org>.
Jefffrey commented on code in PR #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840#discussion_r1064052544
##########
datafusion/sql/src/planner.rs:
##########
@@ -2390,6 +2390,63 @@ mod tests {
quick_test(sql, expected);
}
+ #[test]
+ fn using_join_multiple_keys() {
+ let sql = "SELECT * FROM person a join person b using (id, age)";
+ let expected = "Projection: a.id, a.first_name, a.last_name, a.age, a.state, a.salary, a.birth_date, a.😀, \
+ b.first_name, b.last_name, b.state, b.salary, b.birth_date, b.😀\
+ \n Inner Join: Using a.id = b.id, a.age = b.age\
+ \n SubqueryAlias: a\
+ \n TableScan: person\
+ \n SubqueryAlias: b\
+ \n TableScan: person";
+ quick_test(sql, expected);
+ }
+
+ #[test]
+ fn using_join_multiple_keys_subquery() {
+ let sql = "SELECT age FROM (SELECT * FROM person a join person b using (id, age, state))";
+ let expected = "Projection: a.age\
+ \n Projection: a.id, a.first_name, a.last_name, a.age, a.state, a.salary, a.birth_date, a.😀, \
+ b.first_name, b.last_name, b.salary, b.birth_date, b.😀\
+ \n Inner Join: Using a.id = b.id, a.age = b.age, a.state = b.state\
+ \n SubqueryAlias: a\
+ \n TableScan: person\
+ \n SubqueryAlias: b\
+ \n TableScan: person";
+ quick_test(sql, expected);
+ }
+
+ #[test]
+ fn using_join_multiple_keys_select_all_columns() {
+ let sql = "SELECT a.*, b.* FROM person a join person b using (id, age)";
Review Comment:
Added test
--
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] Jefffrey commented on a diff in pull request #4840: Support wildcard select on multiple column using joins
Posted by GitBox <gi...@apache.org>.
Jefffrey commented on code in PR #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840#discussion_r1063978289
##########
datafusion/expr/src/utils.rs:
##########
@@ -198,9 +207,14 @@ pub fn expand_qualified_wildcard(
"Invalid qualifier {qualifier}"
)));
}
- let qualifier_schema =
+ let qualified_schema =
DFSchema::new_with_metadata(qualified_fields, schema.metadata().clone())?;
- expand_wildcard(&qualifier_schema, plan)
+ // if qualified, allow all columns in output (i.e. ignore using column check)
+ Ok(qualified_schema
+ .fields()
+ .iter()
+ .map(|f| Expr::Column(f.qualified_column()))
+ .collect::<Vec<Expr>>())
Review Comment:
this is an extra fix, as i observed in postgresql if you have the following query:
```sql
select a.*, b.*, c.*
from categories a
join categories b using (category_id)
join categories c using (category_id)
;
```
then `a.category_id`, `b.category_id` and `c.category_id` are all included in the output instead of being omitted due to being part of the using join, because they have been specifically qualified in their wildcard, hence shouldn't try to deduplicate those as in the non-qualified wildcard case
--
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 merged pull request #4840: Support wildcard select on multiple column using joins
Posted by GitBox <gi...@apache.org>.
alamb merged PR #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840
--
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 #4840: Support wildcard select on multiple column using joins
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840#issuecomment-1374509684
> Could you please wait for https://github.com/apache/arrow-datafusion/pull/4829 merge?😂. I have split the planner.
I just merged https://github.com/apache/arrow-datafusion/pull/4829 -- sorry for the conflict @Jefffrey -- can you resolve the conflicts?
--
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 #4840: Support wildcard select on multiple column using joins
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840#discussion_r1064013888
##########
datafusion/sql/src/planner.rs:
##########
@@ -2390,6 +2390,63 @@ mod tests {
quick_test(sql, expected);
}
+ #[test]
+ fn using_join_multiple_keys() {
+ let sql = "SELECT * FROM person a join person b using (id, age)";
+ let expected = "Projection: a.id, a.first_name, a.last_name, a.age, a.state, a.salary, a.birth_date, a.😀, \
+ b.first_name, b.last_name, b.state, b.salary, b.birth_date, b.😀\
+ \n Inner Join: Using a.id = b.id, a.age = b.age\
+ \n SubqueryAlias: a\
+ \n TableScan: person\
+ \n SubqueryAlias: b\
+ \n TableScan: person";
+ quick_test(sql, expected);
+ }
+
+ #[test]
+ fn using_join_multiple_keys_subquery() {
+ let sql = "SELECT age FROM (SELECT * FROM person a join person b using (id, age, state))";
+ let expected = "Projection: a.age\
+ \n Projection: a.id, a.first_name, a.last_name, a.age, a.state, a.salary, a.birth_date, a.😀, \
+ b.first_name, b.last_name, b.salary, b.birth_date, b.😀\
+ \n Inner Join: Using a.id = b.id, a.age = b.age, a.state = b.state\
+ \n SubqueryAlias: a\
+ \n TableScan: person\
+ \n SubqueryAlias: b\
+ \n TableScan: person";
+ quick_test(sql, expected);
+ }
+
+ #[test]
+ fn using_join_multiple_keys_select_all_columns() {
+ let sql = "SELECT a.*, b.* FROM person a join person b using (id, age)";
Review Comment:
👍
##########
datafusion/sql/src/planner.rs:
##########
@@ -2390,6 +2390,63 @@ mod tests {
quick_test(sql, expected);
}
+ #[test]
+ fn using_join_multiple_keys() {
+ let sql = "SELECT * FROM person a join person b using (id, age)";
+ let expected = "Projection: a.id, a.first_name, a.last_name, a.age, a.state, a.salary, a.birth_date, a.😀, \
+ b.first_name, b.last_name, b.state, b.salary, b.birth_date, b.😀\
+ \n Inner Join: Using a.id = b.id, a.age = b.age\
+ \n SubqueryAlias: a\
+ \n TableScan: person\
+ \n SubqueryAlias: b\
+ \n TableScan: person";
+ quick_test(sql, expected);
+ }
+
+ #[test]
+ fn using_join_multiple_keys_subquery() {
+ let sql = "SELECT age FROM (SELECT * FROM person a join person b using (id, age, state))";
+ let expected = "Projection: a.age\
+ \n Projection: a.id, a.first_name, a.last_name, a.age, a.state, a.salary, a.birth_date, a.😀, \
+ b.first_name, b.last_name, b.salary, b.birth_date, b.😀\
+ \n Inner Join: Using a.id = b.id, a.age = b.age, a.state = b.state\
+ \n SubqueryAlias: a\
+ \n TableScan: person\
+ \n SubqueryAlias: b\
+ \n TableScan: person";
+ quick_test(sql, expected);
+ }
+
+ #[test]
+ fn using_join_multiple_keys_select_all_columns() {
+ let sql = "SELECT a.*, b.* FROM person a join person b using (id, age)";
Review Comment:
I wonder is it worth one more test of just one of `a` or `b` ?
```rust
let sql = "SELECT a.*, FROM person a join person b using (id, age)";
```
?
--
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] jackwener commented on pull request #4840: Support wildcard select on multiple column using joins
Posted by GitBox <gi...@apache.org>.
jackwener commented on PR #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840#issuecomment-1374502403
Could you please wait for #4829 merge?😂. I have split the planner.
It will cause conflict.
--
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 #4840: Support wildcard select on multiple column using joins
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4840:
URL: https://github.com/apache/arrow-datafusion/pull/4840#issuecomment-1374947195
Benchmark runs are scheduled for baseline = f9b72f4230687b884a92f79d21762578d3d56281 and contender = 63ae2b9ebbe853648492576cda457a3049bbd2dc. 63ae2b9ebbe853648492576cda457a3049bbd2dc 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/6f4bc1aaf5114161b61ce5763815fe17...2716f96046f148f1abea85fc7d0b842a/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/68f4a2f3eefd42849099e83f4e64c51e...77a77cec038c467aab9a59ce43299dc0/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/5e43be0720974add9fc9ae13db6528fd...39a2b37c2426429ab4186cf100ab044c/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/e601e92265ba4bd7bc3cd00d01874f9a...c8eef88d18084afa9a9158869dfa7e66/)
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