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

Add support for ORDER BY ALL #1724

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

PokIsemaine
Copy link

Comment on lines 9194 to 9200
let order_by = if self.parse_keyword(Keyword::ALL) {
if !self.dialect.supports_order_by_all() {
return parser_err!(
"ALL is not supported in ORDER BY",
self.peek_token().span.start
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let order_by = if self.parse_keyword(Keyword::ALL) {
if !self.dialect.supports_order_by_all() {
return parser_err!(
"ALL is not supported in ORDER BY",
self.peek_token().span.start
);
}
let order_by = if self.dialect.supports_order_by_all() && self.parse_keyword(Keyword::ALL) {

can we maybe add a test case for this? that other dialects can successfully parse ORDER BY all

Copy link
Author

Choose a reason for hiding this comment

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

If an unsupported dialect uses ORDER BY ALL, should we return parser_err or an OrderByKind::Expressions type OrderBy with its expr as ALL?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah the latter, if an unsupporting dialect sees the query ORDER BY ALL it implies that there's a column/variable in scope called ALL i.e all is an identifier so it'll indeed be correct to parse it as an expression

@@ -13405,6 +13419,19 @@ impl<'a> Parser<'a> {
})
}

pub fn parse_order_by_all(&mut self) -> Result<OrderByAll, ParserError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn parse_order_by_all(&mut self) -> Result<OrderByAll, ParserError> {
fn parse_order_by_all(&mut self) -> Result<OrderByAll, ParserError> {

@@ -13405,6 +13419,19 @@ impl<'a> Parser<'a> {
})
}

pub fn parse_order_by_all(&mut self) -> Result<OrderByAll, ParserError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we update parse_order_by_expr to use this helper? since it shares this code so that we avoid keeping both copies in sync

Copy link
Author

Choose a reason for hiding this comment

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

You are right, this change is better. I plan to first change pub fn parse_order_by_all to fn parse_order_by_options and then reuse it in parse_order_by_expr.

src/ast/query.rs Outdated
Comment on lines 2256 to 2263
if let Some(ref interpolate) = self.interpolate {
match &interpolate.exprs {
Some(exprs) => {
write!(f, " INTERPOLATE ({})", display_comma_separated(exprs))?
}
None => write!(f, " INTERPOLATE")?,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we can move this outside the match statement and write it unconditionally, representation wise its not tied to kind so it would be confusing to display interpolate conditionally on the kind.

@@ -89,4 +89,9 @@ impl Dialect for DuckDbDialect {
fn supports_from_first_select(&self) -> bool {
true
}

// See DuckDB <https://duckdb.org/docs/sql/query_syntax/orderby.html#order-by-all-examples>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// See DuckDB <https://duckdb.org/docs/sql/query_syntax/orderby.html#order-by-all-examples>
/// See DuckDB <https://duckdb.org/docs/sql/query_syntax/orderby.html#order-by-all-examples>

Copy link
Author

Choose a reason for hiding this comment

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

I am not very familiar with Rust yet, and I want to know if there are any tools that can automatically unify the comment format of a project, because I saw both // and /// in the same file, which is a bit confusing. Or does this project have any relevant specification documents?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, we don't run any lint for this in the project unfortunattely so there are discrepancies in the codebase. Ideally especially for public functions, in order for the comment to show up in the documentation /// is required, whereas // is a internal-only code comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants