-
Notifications
You must be signed in to change notification settings - Fork 554
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
With Order Support for Memory Tables #1401
With Order Support for Memory Tables #1401
Conversation
…to feature/with-order-for-table
…to feature/with-order-for-table
parse with order in correct ordering
@@ -124,6 +124,7 @@ pub struct CreateTable { | |||
pub default_charset: Option<String>, | |||
pub collation: Option<String>, | |||
pub on_commit: Option<OnCommit>, | |||
pub with_order: Vec<Vec<OrderByExpr>>, |
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.
Could we include here a link to the docs where this syntax comes from? (e.g. similar to the on_cluster below)
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.
This was inspired by Datafusion's WITH ORDER
statement, so I've added the link and tests, thank you!
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.
FWIW I did some research and could not find any existing databases that use the WITH ORDER
syntax.
ClickHouse does seem to have a way to specify order as part of a CREATE TABLE
statement: https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/mergetree
@mertak-synnada rather than introducing special DataFusion only syntax support, what do you think about extending DataFusion to use the existing ClickHouse syntax?
CREATE TABLE ....
ORDER BY <...>
We might have to change the GenericDialect
or add some feature to the Dialect
trait to permit other dialects to parse such syntax, but it would be nice to align to some other existing syntax rather than creating something new
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 see two possible ways forward:
- We can change DF to support
ORDER BY
afterCREATE
and deprecateWITH ORDER
. This way we would have Clickhouse-like syntax for both memory and external tables, andWITH ORDER
syntax only for external tables. The latter asymmetry is a little weird but we can explain it away by deprecatingWITH ORDER
. - We can support both
ORDER BY
andWITH ORDER
for both memory and external tables in DF (they would be synonyms). We'd need to addWITH ORDER
for ordinaryCREATE
s here though.
I am OK with both, with a slight preference to 2 because DF has had WITH ORDER
for a while now. What do you think?
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 think in this case we should distinguish between DataFusion's needs and sqlparser-rs's needs
If we are going to introduce WITH ORDER
to sqlparser-rs I think it should follow the existing pattern of being connected to a specific dialect (in this case DatafusionDialect
).
Thus I would personally vote for option 1 (change DF) so we avoid creating a new SQL dialect (both in this crate and in general) as much as possible
- We can change DF to support ORDER BY after CREATE and deprecate WITH ORDER. This way we would have Clickhouse-like syntax for both memory and external tables, and WITH ORDER syntax only for external tables. The latter asymmetry is a little weird but we can explain it away by deprecating WITH ORDER.
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.
Makes sense - let's do it
@@ -124,6 +124,7 @@ pub struct CreateTable { | |||
pub default_charset: Option<String>, | |||
pub collation: Option<String>, | |||
pub on_commit: Option<OnCommit>, | |||
pub with_order: Vec<Vec<OrderByExpr>>, |
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 include test cases demonstrating the behavior introduced by the changes?
add unit test for WITH ORDER parsing in create table
# Conflicts: # src/ast/helpers/stmt_create_table.rs
src/parser/mod.rs
Outdated
if self.parse_keyword(Keyword::WITH) { | ||
if self.parse_keyword(Keyword::ORDER) { |
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 self.parse_keyword(Keyword::WITH) { | |
if self.parse_keyword(Keyword::ORDER) { | |
if self.parse_keywords(&[Keyword::WITH, Keyword::ORDER]) { |
Also I think we can keep the postgres path separate since this feature doesn't apply to that dialect? - so that this part remains the same
let with_options = self.parse_options(Keyword::WITH)?;
We can make the fuctionality conditional with e.g. if self.dialect.supports_with_order()
or similar method
src/parser/mod.rs
Outdated
loop { | ||
order_exprs.push(vec![self.parse_order_by_expr()?]); | ||
if !self.consume_token(&Token::Comma) { | ||
self.expect_token(&Token::RParen)?; | ||
break; | ||
} | ||
} |
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 the parse_comma_separated()
method be reused for this functionality?
src/parser/mod.rs
Outdated
@@ -12364,6 +12385,43 @@ mod tests { | |||
); | |||
} | |||
|
|||
#[test] |
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.
hmm I think this would probably not be the ideal place for the test to live - if the feature isn't bound to any dialect, or if it uses a dialect method to guard the feature, we can add the tests to common e.g. https://github.com/sqlparser-rs/sqlparser-rs/blob/main/tests/sqlparser_common.rs#L4405
remove parse_options_in_parentheses functionality
change tests to all_dialects_where clause
Pull Request Test Coverage Report for Build 10678509735Details
💛 - Coveralls |
Marking as draft as i think this is still under discussion and not in need of more review. Please mark it as review if I got that wrong or when it is ready |
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
Add support for WITH ORDER syntax for Memory Tables