feat: support INSERT INTO [TABLE] FUNCTION of Clickhouse#1633
feat: support INSERT INTO [TABLE] FUNCTION of Clickhouse#1633iffyio merged 12 commits intoapache:mainfrom
INSERT INTO [TABLE] FUNCTION of Clickhouse#1633Conversation
d4ac9e2 to
123d574
Compare
src/ast/dml.rs
Outdated
| /// TABLE | ||
| #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] | ||
| pub table_name: ObjectName, | ||
| pub table_object: TableObject, |
There was a problem hiding this comment.
| pub table_object: TableObject, | |
| pub table: TableObject, |
There was a problem hiding this comment.
There is already a field named table in this struct...
There was a problem hiding this comment.
Ah right, I didn't notice the existing table property. Looking at the description of that property it feels its naming isn't ideal, I'm thinking as a result we could take the opportunity to rename that one to e.g. has_table_keyword to free up the current one to be called table?
| #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||
| pub enum TableObject { |
There was a problem hiding this comment.
Could we include a doc comment mentionign this is the target of an insert table statement? And then for the variants that it can either be a tablename or function with example SQL? That would make it easy for folks to get an overview of the struct without having to dig into the code or test out manually
src/parser/mod.rs
Outdated
|
|
||
| pub fn parse_table_object( | ||
| &mut self, | ||
| in_table_clause: bool, |
There was a problem hiding this comment.
Is the in_table_clause flag needed? I imagine it'll always be false
src/parser/mod.rs
Outdated
| } | ||
| } | ||
|
|
||
| pub fn parse_table_object( |
There was a problem hiding this comment.
Can we add a doc comment for this given its a public method?
src/parser/mod.rs
Outdated
| &mut self, | ||
| in_table_clause: bool, | ||
| ) -> Result<TableObject, ParserError> { | ||
| if dialect_of!(self is ClickHouseDialect) && self.parse_keyword(Keyword::FUNCTION) { |
There was a problem hiding this comment.
Can we use a dialect method for this? e.g.
if self.dialect.supports_function_table_objects() && self.parse_keyword(keyword::FUNCTION)
src/parser/mod.rs
Outdated
| pub fn parse_table_function(&mut self) -> Result<Function, ParserError> { | ||
| let fn_name = self.parse_object_name(false)?; | ||
| self.parse_function_call(fn_name) | ||
| } |
There was a problem hiding this comment.
I'm wondering if its worth having this as a standalone method? It looks like it can be inlined given its only 2 LOC?
|
|
||
| #[test] | ||
| fn parse_insert_into_function() { | ||
| clickhouse().verified_stmt(r#"INSERT INTO TABLE FUNCTION remote('localhost', default.simple_table) VALUES (100, 'inserted via remote()')"#); |
There was a problem hiding this comment.
Can we add a similar test case without the TABLE keyword?
9e648e8 to
229d7db
Compare
|
@iffyio Thank you for your time. I have revised the PR according to your comments and hope you can review it. |
src/ast/dml.rs
Outdated
| /// TABLE | ||
| #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] | ||
| pub table_name: ObjectName, | ||
| pub table_object: TableObject, |
There was a problem hiding this comment.
Ah right, I didn't notice the existing table property. Looking at the description of that property it feels its naming isn't ideal, I'm thinking as a result we could take the opportunity to rename that one to e.g. has_table_keyword to free up the current one to be called table?
|
Hi @iffyio, I have revised the PR. Could you please review it again? |
iffyio
left a comment
There was a problem hiding this comment.
LGTM! Thanks @byte-sourcerer!
cc @alamb
|
@byte-sourcerer could you take a look when you get the chance to resolve the conflicts on the branch |
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
ed5f542 to
6137566
Compare
Resolved. |
Co-authored-by: Kermit <chenjiawei1@xiaohongshu.com> Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Support
INSERT INTO [TABLE] FUNCTIONof Clickhouse.