-
Notifications
You must be signed in to change notification settings - Fork 752
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
Feature: Support DISTINCT in new planner #5410
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ffa7e7f
feat: support ditinct in new planner
ygf11 bb422b6
feat: support distinct with group by
ygf11 01de32e
fix: fix distinct stateless test
ygf11 3fcd1eb
fix: avoid unnecessary column expr transform
ygf11 e7cdf9c
Merge branch 'main' into dev
mergify[bot] db20ed0
fix: run ci again
ygf11 ab2b2a4
Merge branch main into dev
ygf11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2022 Datafuse Labs. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use common_exception::Result; | ||
|
||
use crate::sql::binder::Binder; | ||
use crate::sql::optimizer::SExpr; | ||
use crate::sql::plans::AggregatePlan; | ||
use crate::sql::plans::BoundColumnRef; | ||
use crate::sql::plans::Scalar; | ||
use crate::sql::BindContext; | ||
|
||
impl<'a> Binder { | ||
pub(super) fn bind_distinct(&self, bind_context: &BindContext, child: SExpr) -> Result<SExpr> { | ||
// Like aggregate, we just use scalar directly. | ||
let group_items: Vec<Scalar> = bind_context | ||
.all_column_bindings() | ||
.iter() | ||
.map(|v| { | ||
v.scalar | ||
.clone() | ||
.map(|scalar| *scalar) | ||
.unwrap_or_else(|| Scalar::BoundColumnRef(BoundColumnRef { column: v.clone() })) | ||
}) | ||
.collect(); | ||
|
||
let distinct_plan = AggregatePlan { | ||
group_items, | ||
aggregate_functions: vec![], | ||
from_distinct: true, | ||
}; | ||
|
||
Ok(SExpr::create_unary(distinct_plan.into(), child)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,3 +243,13 @@ new_planner | |
0 8 5 | ||
====Context Function==== | ||
default | ||
==== Distinct ===== | ||
0 | ||
1 | ||
2 | ||
1 | ||
0 | ||
1 | ||
2 | ||
3 | ||
4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The group expression may have been a column, so there may be duplicate conversions here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if a group expression is a column, it is unnecessary here.
The desitnation of adding this code is to make distinct with group-by work.
Two ways to make it better: