iffyio commented on code in PR #1628:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/1628#discussion_r1910640466
##########
src/parser/mod.rs:
##########
@@ -12012,10 +12033,26 @@ impl<'a> Parser<'a> {
replace_into,
priority,
insert_alias,
+ settings,
+ format_clause,
}))
}
}
+ // Parses format clause used for [ClickHouse]. Formats are different when
using `SELECT` and
+ // `INSERT` and also when using the CLI for pipes. For `INSERT` it can
take an optional values
+ // list which we try to parse here.
Review Comment:
Probably no need to mention the SELECT since that's now unrelated to this
one? Regarding insert and optional values, that detail I imagine is clear from
the doc/type
##########
src/parser/mod.rs:
##########
@@ -12012,10 +12033,26 @@ impl<'a> Parser<'a> {
replace_into,
priority,
insert_alias,
+ settings,
+ format_clause,
}))
}
}
+ // Parses format clause used for [ClickHouse]. Formats are different when
using `SELECT` and
+ // `INSERT` and also when using the CLI for pipes. For `INSERT` it can
take an optional values
+ // list which we try to parse here.
+ //
+ // <https://clickhouse.com/docs/en/interfaces/formats>
+ pub fn parse_input_format_clause(&mut self) -> Result<InputFormatClause,
ParserError> {
+ let ident = self.parse_identifier()?;
+ let values = self
+ .try_parse(|p| p.parse_comma_separated(|p| p.parse_expr()))
Review Comment:
I think this can use maybe_parse instead? to properly account for unexpected
error
##########
src/parser/mod.rs:
##########
@@ -11899,35 +11899,56 @@ impl<'a> Parser<'a> {
let is_mysql = dialect_of!(self is MySqlDialect);
- let (columns, partitioned, after_columns, source, assignments) =
- if self.parse_keywords(&[Keyword::DEFAULT, Keyword::VALUES]) {
- (vec![], None, vec![], None, vec![])
- } else {
- let (columns, partitioned, after_columns) = if
!self.peek_subquery_start() {
- let columns =
self.parse_parenthesized_column_list(Optional, is_mysql)?;
+ let (columns, partitioned, after_columns, source, assignments) =
if self
+ .parse_keywords(&[Keyword::DEFAULT, Keyword::VALUES])
+ {
+ (vec![], None, vec![], None, vec![])
+ } else {
+ let (columns, partitioned, after_columns) = if
!self.peek_subquery_start() {
+ let columns =
self.parse_parenthesized_column_list(Optional, is_mysql)?;
- let partitioned = self.parse_insert_partition()?;
- // Hive allows you to specify columns after partitions
as well if you want.
- let after_columns = if dialect_of!(self is
HiveDialect) {
- self.parse_parenthesized_column_list(Optional,
false)?
- } else {
- vec![]
- };
- (columns, partitioned, after_columns)
+ let partitioned = self.parse_insert_partition()?;
+ // Hive allows you to specify columns after partitions as
well if you want.
+ let after_columns = if dialect_of!(self is HiveDialect) {
+ self.parse_parenthesized_column_list(Optional, false)?
} else {
- Default::default()
+ vec![]
};
+ (columns, partitioned, after_columns)
+ } else {
+ Default::default()
+ };
- let (source, assignments) =
- if self.dialect.supports_insert_set() &&
self.parse_keyword(Keyword::SET) {
- (None,
self.parse_comma_separated(Parser::parse_assignment)?)
- } else {
- (Some(self.parse_query()?), vec![])
- };
+ let (source, assignments) = if
self.peek_keyword(Keyword::FORMAT)
+ || self.peek_keyword(Keyword::SETTINGS)
+ {
+ (None, vec![])
+ } else if self.dialect.supports_insert_set() &&
self.parse_keyword(Keyword::SET) {
+ (None,
self.parse_comma_separated(Parser::parse_assignment)?)
+ } else {
+ (Some(self.parse_query()?), vec![])
+ };
+
+ (columns, partitioned, after_columns, source, assignments)
+ };
- (columns, partitioned, after_columns, source, assignments)
+ let (format_clause, settings) = if dialect_of!(self is
ClickHouseDialect | GenericDialect)
Review Comment:
Can we use a dialect method for the feature gating? thinking we can do
something like
```rust
let (format_clause, settings) = if self.dialect.supports_insert_format() {
//...
} else {
Default::default()
}
```
Then we can probably only enable it for clickhouse if there's a risk that
the syntax could conflict with what generic dialect currently supports
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]