-
Notifications
You must be signed in to change notification settings - Fork 583
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
base: main
Are you sure you want to change the base?
Conversation
src/parser/mod.rs
Outdated
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 | ||
); | ||
} |
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.
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
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.
If an unsupported dialect uses ORDER BY ALL
, should we return parser_err
or an OrderByKind::Expressions
type OrderBy
with its expr as ALL
?
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.
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
src/parser/mod.rs
Outdated
@@ -13405,6 +13419,19 @@ impl<'a> Parser<'a> { | |||
}) | |||
} | |||
|
|||
pub fn parse_order_by_all(&mut self) -> Result<OrderByAll, ParserError> { |
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.
pub fn parse_order_by_all(&mut self) -> Result<OrderByAll, ParserError> { | |
fn parse_order_by_all(&mut self) -> Result<OrderByAll, ParserError> { |
src/parser/mod.rs
Outdated
@@ -13405,6 +13419,19 @@ impl<'a> Parser<'a> { | |||
}) | |||
} | |||
|
|||
pub fn parse_order_by_all(&mut self) -> Result<OrderByAll, ParserError> { |
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.
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
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.
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
if let Some(ref interpolate) = self.interpolate { | ||
match &interpolate.exprs { | ||
Some(exprs) => { | ||
write!(f, " INTERPOLATE ({})", display_comma_separated(exprs))? | ||
} | ||
None => write!(f, " INTERPOLATE")?, | ||
} | ||
} |
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.
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.
src/dialect/duckdb.rs
Outdated
@@ -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> |
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.
// 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> |
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.
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?
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.
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
Add support for
ORDER BY ALL
https://duckdb.org/docs/sql/query_syntax/orderby.html#order-by-all-examples
https://clickhouse.com/docs/en/sql-reference/statements/select/order-by