Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement EXCEPT & EXCEPT DISTINCT #1259

Merged
merged 1 commit into from
Nov 8, 2021
Merged

Conversation

xudong963
Copy link
Member

Which issue does this PR close?

Closes #1082

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added datafusion Changes in the datafusion crate sql SQL Planner labels Nov 6, 2021
@xudong963
Copy link
Member Author

PTAL, thanks❤️ @alamb @houqp @Dandandan

@@ -195,26 +195,42 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
} => {
let left_plan = self.set_expr_to_plan(left.as_ref(), None, ctes)?;
let right_plan = self.set_expr_to_plan(right.as_ref(), None, ctes)?;
let join_keys = left_plan
Copy link
Member

Choose a reason for hiding this comment

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

i am a bit concerned about the extra overhead here for the union branches. perhaps also relevant to https://github.com/apache/arrow-datafusion/pull/1258/files#r744178212

@xudong963 xudong963 force-pushed the impl_except branch 3 times, most recently from 392a134 to 7cedf95 Compare November 7, 2021 14:18
@xudong963
Copy link
Member Author

I extracted some duplicate code, you can review this ticket firstly. After the ticket is merged, I'll update #1258 and #1261 @houqp @alamb @Dandandan

let sql = "SELECT * FROM (SELECT null AS id1, 1 AS id2) t1
EXCEPT SELECT * FROM (SELECT null AS id1, 2 AS id2) t2";

let expected: Vec<Vec<String>> = vec![vec!["NULL".to_string(), "1".to_string()]];
Copy link
Contributor

Choose a reason for hiding this comment

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

Using &str is possible here too I think, maybe easier to remove the explicit type.

Comment on lines 245 to 250
LogicalPlanBuilder::intersect_or_except(
left_plan,
right_plan,
JoinType::Semi,
false,
)
Copy link
Member

Choose a reason for hiding this comment

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

i think it would be cleaner to turn this and except into a simple public wrapper method in logical plan builder so users won't need to worry about which join type to pass in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice suggestion!

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.

I think this looks great -- nice work @xudong963

}

/// Process intersect or except
fn intersect_or_except(
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nice

"Only UNION ALL and UNION [DISTINCT] and INTERSECT and INTERSECT [DISTINCT] are supported, found {}",
op
))),
(SetOperator::Union, true) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

that certainly looks nicer

@alamb alamb merged commit 6f1212d into apache:master Nov 8, 2021
@xudong963 xudong963 deleted the impl_except branch November 9, 2021 06:20
@houqp houqp added the enhancement New feature or request label Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate enhancement New feature or request sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the rest of Set Operators: INTERSECT, EXCEPT, etc
4 participants