-
Notifications
You must be signed in to change notification settings - Fork 562
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
support clickhouse parameterized views #1181
Conversation
Pull Request Test Coverage Report for Build 8669253871Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
src/ast/mod.rs
Outdated
@@ -733,6 +733,10 @@ pub enum Expr { | |||
/// | |||
/// See <https://docs.snowflake.com/en/sql-reference/constructs/where#joins-in-the-where-clause>. | |||
OuterJoin(Box<Expr>), | |||
ColumnWithDataType { |
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 a description for this new variant (ideally including a link to the docs)?
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.
Sure!
src/ast/mod.rs
Outdated
ColumnWithDataType { | ||
columns: Box<Expr>, | ||
data_type: DataType, | ||
}, |
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'm wondering if naming wise, 'ColumnWithDataType' sounds a bit too generic since it applies to a lot of unrelated scenarios. From the docs, it sounds incorrect as well to have the columns: Box<Expr>
?
- The actual column in
WHERE a = {b:INT}
isa
, whileb
would be more of a function parameter b
given its a function parameter likely needs to be anIdent
instead of anExpr
thinking roughly something along this line could be more descriptive
ParameterizedViewArg{
name: Ident,
data_type: DataType,
}
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.
Sure, I'll change it
src/parser/mod.rs
Outdated
if dialect_of!(self is ClickHouseDialect) && self.peek_token().token == Token::LBrace { | ||
return self.parse_column_with_data_type(); | ||
} |
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.
Currently the parse logic for this feature is spread across this and the parse_infix function where one triggers the other indirectly, slightly harder to follow as a result - one suggestion to simplify this would be:
- The current function already includes a match onthe token type, so we can introduce a clause
Token::LBRACE if dialect_of!(self is Clickhouse) => { self.prev_token(); self.parse_column_with_data_type() }
- The current
parse_column_with_data_type
can parse the components directly - especially given that it does not seem correct for it to parse an inner expression. It becomes// consume LBRACE let name = self.parse_identifier()?; self.expect(Token::Colon)?; let data_type = self.parse_data_type()?; // consume RBRACE
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 to me.
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.
Thank you @Lordworms -- this is a really nice contribution . I think it just needs a little polish and would be ready to go
fyi @flipchart
src/parser/mod.rs
Outdated
|
||
// ClickHouse support using {column:Datatype} format in its creation of parametrised views | ||
match self.peek_token().token { | ||
Token::LBrace if dialect_of!(self is ClickHouseDialect) => { |
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 you please also support this syntax in GenericDialect
as well as explained in https://github.com/sqlparser-rs/sqlparser-rs?tab=readme-ov-file#new-syntax ?
(also add test for it 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.
sure
|
||
#[test] | ||
fn parse_create_parametrised_views() { | ||
clickhouse().verified_stmt("CREATE VIEW view AS SELECT * FROM A WHERE Column1 = {column1:datatype1} AND Column2 = {column2:datatype2}"); |
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 you also please test:
- In generic dialect
- A single column definition
- Error case (like
where Column1 = {column1}
) - Error case (like
where
) (no column definition)
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.
Sure, I'll add these tommorrow
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.
Thank you @Lordworms
I took the liberty of fixing the compile error and pushing a commit to fix it |
Hi @Lordworms -- it seems like there is a real test failure on this PR. Can you investigate? |
Marking as draft as the PR checks are failing |
It seems to have some conflict with the DuckDB literal. I'll fix this. |
@alamb I have resolved it and would you please take a look at it when you are available? Thanks! Sorry for the failure since this PR has lasted for 3 weeks and I forgot to rebase this branch. |
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.
Thanks @Lordworms . I have a few more comments -- sorry it takes me so long to review these
} | ||
} | ||
#[test] | ||
fn parse_create_parametrised_views() { |
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 may be mistaken, but thinking about this PR some more and I am not sure about the change to parse_prefix
Specifically, by changing that I think it now allows {column:data_type}
to appear in any expression (not just a parameterized view).
For example, wouldn't these queries now parse SELECT * FROM foo WHERE x = {column:int}
or SELECT x={column:int} FROM foo
?
Can you add test coverage for those cases?
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.
Sure
Co-authored-by: Andrew Lamb <[email protected]>
I am not sure what the current status of this PR is -- it has a bunch of conflicts and I am not quite sure if it is ready for another review. Sorry for the delay. Marking it as a draft until we sort that out so it isn't on my review queue |
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. |
Closes #1167