Skip to content

Commit b00781c

Browse files
committed
Address review comments
- Update doc comments to use [Dialect](link) format - Remove dialect-specific inline comments - Rename parse_column_def_for_partition to parse_partitioned_by_column_def - Use maybe_parse instead of manual token checking - Use backticks for SQL keywords in doc comments
1 parent aa54943 commit b00781c

2 files changed

Lines changed: 20 additions & 25 deletions

File tree

src/ast/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,17 +4670,23 @@ pub enum Statement {
46704670
name: ObjectName,
46714671
/// Whether the `TABLE` keyword was present (ClickHouse uses `OPTIMIZE TABLE`, Databricks uses `OPTIMIZE`).
46724672
has_table_keyword: bool,
4673-
/// Optional cluster identifier (ClickHouse).
4673+
/// Optional cluster identifier.
4674+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/optimize)
46744675
on_cluster: Option<Ident>,
4675-
/// Optional partition spec (ClickHouse).
4676+
/// Optional partition spec.
4677+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/optimize)
46764678
partition: Option<Partition>,
4677-
/// Whether `FINAL` was specified (ClickHouse).
4679+
/// Whether `FINAL` was specified.
4680+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/optimize)
46784681
include_final: bool,
4679-
/// Optional deduplication settings (ClickHouse).
4682+
/// Optional deduplication settings.
4683+
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/optimize)
46804684
deduplicate: Option<Deduplicate>,
4681-
/// Optional WHERE predicate (Databricks).
4685+
/// Optional WHERE predicate.
4686+
/// [Databricks](https://docs.databricks.com/en/sql/language-manual/delta-optimize.html)
46824687
predicate: Option<Expr>,
4683-
/// Optional ZORDER BY columns (Databricks).
4688+
/// Optional ZORDER BY columns.
4689+
/// [Databricks](https://docs.databricks.com/en/sql/language-manual/delta-optimize.html)
46844690
zorder: Option<Vec<Expr>>,
46854691
},
46864692
/// ```sql

src/parser/mod.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,9 +3334,7 @@ impl<'a> Parser<'a> {
33343334
/// Syntax:
33353335
///
33363336
/// ```sql
3337-
/// -- BigQuery style
33383337
/// [field_name] field_type
3339-
/// -- Databricks/Hive style (colon separator)
33403338
/// field_name: field_type
33413339
/// ```
33423340
///
@@ -3348,17 +3346,13 @@ impl<'a> Parser<'a> {
33483346
) -> Result<(StructField, MatchedTrailingBracket), ParserError> {
33493347
// Look beyond the next item to infer whether both field name
33503348
// and type are specified.
3351-
// Supports both:
3352-
// - `field_name field_type` (BigQuery style)
3353-
// - `field_name: field_type` (Databricks/Hive style)
33543349
let is_named_field = matches!(
33553350
(self.peek_nth_token(0).token, self.peek_nth_token(1).token),
33563351
(Token::Word(_), Token::Word(_)) | (Token::Word(_), Token::Colon)
33573352
);
33583353

33593354
let field_name = if is_named_field {
33603355
let name = self.parse_identifier()?;
3361-
// Consume optional colon separator (Databricks/Hive style)
33623356
let _ = self.consume_token(&Token::Colon);
33633357
Some(name)
33643358
} else {
@@ -7890,33 +7884,29 @@ impl<'a> Parser<'a> {
78907884
pub fn parse_hive_distribution(&mut self) -> Result<HiveDistributionStyle, ParserError> {
78917885
if self.parse_keywords(&[Keyword::PARTITIONED, Keyword::BY]) {
78927886
self.expect_token(&Token::LParen)?;
7893-
let columns = self.parse_comma_separated(Parser::parse_column_def_for_partition)?;
7887+
let columns = self.parse_comma_separated(Parser::parse_partitioned_by_column_def)?;
78947888
self.expect_token(&Token::RParen)?;
78957889
Ok(HiveDistributionStyle::PARTITIONED { columns })
78967890
} else {
78977891
Ok(HiveDistributionStyle::NONE)
78987892
}
78997893
}
79007894

7901-
/// Parse column definition for PARTITIONED BY clause.
7895+
/// Parse column definition for `PARTITIONED BY` clause.
79027896
///
7903-
/// Databricks allows partition columns without types when referencing
7897+
/// Allows partition columns without types when referencing
79047898
/// columns already defined in the table specification:
79057899
/// ```sql
79067900
/// CREATE TABLE t (col1 STRING, col2 INT) PARTITIONED BY (col1)
79077901
/// CREATE TABLE t (col1 STRING) PARTITIONED BY (col2 INT)
79087902
/// ```
79097903
///
7910-
/// See [Databricks](https://docs.databricks.com/en/sql/language-manual/sql-ref-partition.html)
7911-
fn parse_column_def_for_partition(&mut self) -> Result<ColumnDef, ParserError> {
7904+
/// [Databricks](https://docs.databricks.com/en/sql/language-manual/sql-ref-partition.html)
7905+
fn parse_partitioned_by_column_def(&mut self) -> Result<ColumnDef, ParserError> {
79127906
let name = self.parse_identifier()?;
7913-
7914-
// Check if the next token indicates there's no type specified
7915-
// (comma or closing paren means end of this column definition)
7916-
let data_type = match self.peek_token().token {
7917-
Token::Comma | Token::RParen => DataType::Unspecified,
7918-
_ => self.parse_data_type()?,
7919-
};
7907+
let data_type = self
7908+
.maybe_parse(|parser| parser.parse_data_type())?
7909+
.unwrap_or(DataType::Unspecified);
79207910

79217911
Ok(ColumnDef {
79227912
name,
@@ -18256,7 +18246,6 @@ impl<'a> Parser<'a> {
1825618246
/// ```
1825718247
/// [Databricks](https://docs.databricks.com/en/sql/language-manual/delta-optimize.html)
1825818248
pub fn parse_optimize_table(&mut self) -> Result<Statement, ParserError> {
18259-
// Check for TABLE keyword (ClickHouse uses it, Databricks does not)
1826018249
let has_table_keyword = self.parse_keyword(Keyword::TABLE);
1826118250

1826218251
let name = self.parse_object_name(false)?;

0 commit comments

Comments
 (0)