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

feat(planner): support order by in new planner #5253

Merged
merged 8 commits into from
May 9, 2022

Conversation

xudong963
Copy link
Member

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

Support order by in new planner

Changelog

  • New Feature

Related Issues

Fixes #5202

@vercel
Copy link

vercel bot commented May 9, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
databend ⬜️ Ignored (Inspect) May 9, 2022 at 2:52PM (UTC)

@mergify
Copy link
Contributor

mergify bot commented May 9, 2022

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@mergify mergify bot added the pr-feature this PR introduces a new feature to the codebase label May 9, 2022
@xudong963 xudong963 requested review from leiysky and sundy-li May 9, 2022 07:22
@BohuTANG BohuTANG requested review from zhang2014 and removed request for BohuTANG May 9, 2022 07:28
-- order by
SELECT number%3 as c1, number%2 as c2 FROM numbers_mt (10) order by c1 desc, c2 asc;
SELECT number, null from numbers(3) order by number desc;
SELECT number%3 as c1, number%2 as c2 FROM numbers_mt (10) order by c1, number desc;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe need test SELECT COUNT() FROM numbers_mt(10) GROUP BY number ORDER BY SUM(number);

Copy link
Member

Choose a reason for hiding this comment

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

SELECT SUM(number) AS s FROM numbers_mt(10) GROUP BY number ORDER BY s;

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe need test SELECT COUNT() FROM numbers_mt(10) GROUP BY number ORDER BY SUM(number);

Nice, the sort expression(s) can be any expression that would be valid in the query's select list, so I need to process its input schema and produce its output schema. Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't figured out how to support aggregate functions in order by, but now that other expressions than aggregate functions are supported, I'll note an issue.

let expr_name = expr.column_name().clone();
if !input_schema.has_field(expr_name.as_str()) {
let field = if expr.nullable(input_schema)? {
DataField::new_nullable(expr_name.as_str(), expr.to_data_type(input_schema)?)
Copy link
Member

Choose a reason for hiding this comment

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

Just use DataField::new(expr_name.as_str(), expr.to_data_type(input_schema)?)
expr.to_data_type already covered nullable case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually used new directly at the beginning, but I encountered a bug when I implemented group by the other day, so I still differentiate whether it's nullable here, and I'll sort out the bug tomorrow

@xudong963
Copy link
Member Author

Let's merge it first? Then I can do other tasks based on the ticket.

@xudong963 xudong963 merged commit ed635e9 into databendlabs:main May 9, 2022
@xudong963 xudong963 deleted the order_by branch May 9, 2022 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-review pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: order by for new planner
6 participants