Skip to content

Conversation

@jackwener
Copy link
Member

Which issue does this PR close?

Closes #.

Rationale for this change

original code will remove distinct when they are children of union.

But we should't remove them, because

  1. distinct can decrease cardinaty/rowcount of union input
  2. sometime distinct can pushdown, such as distinct can pushdown through join.
  3. even if we want to remove distinct, we should create rule instead of eliminate distinct in plan builder

What changes are included in this PR?

union_distinct shouldn't remove child distinct

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Aug 21, 2023
@jackwener jackwener marked this pull request as draft August 21, 2023 07:59
@jackwener jackwener marked this pull request as ready for review August 21, 2023 10:40
@jackwener
Copy link
Member Author

jackwener commented Aug 21, 2023

I will add other rule after this PR, such as MergeUnionRule to combine multiple union

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me -- it is somewhat interesting that there are no end to end plan explain changes. Thanks @jackwener

I looked into it and it seems like this function is not called via the SQL planner, only via the DataFrame API

https://github.com/search?q=repo%3Aapache%2Farrow-datafusion%20%20union_distinct&type=code


/// Apply a union, removing duplicate rows
pub fn union_distinct(self, plan: LogicalPlan) -> Result<Self> {
// unwrap top-level Distincts, to avoid duplication
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key point of this PR is that reshuffling around of DISTINCT should be done as an optimization pass, rather than as part of the builder, if I understand it. This makes sense to me

@alamb alamb merged commit 304cb02 into apache:main Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants