You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "funcpp (via GitHub)" <gi...@apache.org> on 2026/02/04 03:09:02 UTC

Re: [PR] Databricks: Add support for OPTIMIZE, PARTITIONED BY, and STRUCT syntax [datafusion-sqlparser-rs]

funcpp commented on code in PR #2170:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2170#discussion_r2761955818


##########
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:
   Makes sense\! I've extracted the shared logic into `parse_column_def_inner(optional_data_type: bool)` so that `parse_column_def` delegates to it with `false` (type required) and the PARTITIONED BY path calls it with `true` (type optional via `maybe_parse`). This removes the duplicate function while reusing the full column def parsing logic including options.



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org