iffyio commented on code in PR #2170:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2170#discussion_r2741645683
##########
src/parser/mod.rs:
##########
@@ -7907,14 +7890,41 @@ impl<'a> Parser<'a> {
pub fn parse_hive_distribution(&mut self) -> Result<HiveDistributionStyle,
ParserError> {
if self.parse_keywords(&[Keyword::PARTITIONED, Keyword::BY]) {
self.expect_token(&Token::LParen)?;
- let columns =
self.parse_comma_separated(Parser::parse_column_def)?;
+ let columns =
self.parse_comma_separated(Parser::parse_column_def_for_partition)?;
self.expect_token(&Token::RParen)?;
Ok(HiveDistributionStyle::PARTITIONED { columns })
} else {
Ok(HiveDistributionStyle::NONE)
}
}
+ /// Parse column definition for PARTITIONED BY clause.
+ ///
+ /// Databricks allows partition columns without types when referencing
+ /// columns already defined in the table specification:
+ /// ```sql
+ /// CREATE TABLE t (col1 STRING, col2 INT) PARTITIONED BY (col1)
+ /// CREATE TABLE t (col1 STRING) PARTITIONED BY (col2 INT)
+ /// ```
+ ///
+ /// See
[Databricks](https://docs.databricks.com/en/sql/language-manual/sql-ref-partition.html)
+ fn parse_column_def_for_partition(&mut self) -> Result<ColumnDef,
ParserError> {
Review Comment:
Oh I see they're indeed the same cases. It would seem that `ColumnDef`
should have an `Option`al datatype instead of us introducing a special datatype
but that issue is unrelated to this PR.
For this PR though this new function seems to duplicate `parse_column_def`
(minus the aforementioned optional datatype case) so that it would be good to
reuse it instead. I can imagine something like?
```rust
pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError> {
parse_column_def_inner(true)
}
fn parse_column_def_inner(&mut self) -> Result<ColumnDef, ParserError> {
// ...
let data_type = if self.is_column_type_sqlite_unspecified() {
DataType::Unspecified
} else {
self
.maybe_parse(|parser| parser.parse_data_type())?
.unwrap_or(DataType::Unspecified)
};
// ...
}
```
--
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]