Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/polyglot-sql/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,8 @@ impl SelectBuilder {
copy_grants: false,
using_template: None,
rollup: None,
with_partition_columns: vec![],
with_connection: None,
}))
}

Expand Down
2 changes: 2 additions & 0 deletions crates/polyglot-sql/src/dialects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26107,6 +26107,8 @@ impl Dialect {
copy_grants: false,
using_template: None,
rollup: None,
with_partition_columns: Vec::new(),
with_connection: None,
};
return Expression::CreateTable(Box::new(ct));
}
Expand Down
11 changes: 11 additions & 0 deletions crates/polyglot-sql/src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5841,6 +5841,15 @@ pub struct CreateTable {
/// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rollup: Option<RollupProperty>,
/// WITH PARTITION COLUMNS (col_name col_type, ...) — currently used by BigQuery
/// for hive-partitioned external tables. Not dialect-prefixed since the syntax
/// could appear in other engines.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub with_partition_columns: Vec<ColumnDef>,
/// WITH CONNECTION `project.region.connection` — currently used by BigQuery
/// for external tables that reference a Cloud Resource connection.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub with_connection: Option<TableRef>,
}

/// Teradata index specification for CREATE TABLE
Expand Down Expand Up @@ -5907,6 +5916,8 @@ impl CreateTable {
copy_grants: false,
using_template: None,
rollup: None,
with_partition_columns: Vec::new(),
with_connection: None,
}
}
}
Expand Down
45 changes: 45 additions & 0 deletions crates/polyglot-sql/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7493,6 +7493,51 @@ impl Generator {
self.generate_expression(&on_prop.this)?;
}

// BigQuery: WITH PARTITION COLUMNS (col_name col_type, ...)
if !ct.with_partition_columns.is_empty() {
if self.config.pretty {
self.write_newline();
} else {
self.write_space();
}
self.write_keyword("WITH PARTITION COLUMNS");
self.write(" (");
if self.config.pretty {
self.write_newline();
self.indent_level += 1;
for (i, col) in ct.with_partition_columns.iter().enumerate() {
if i > 0 {
self.write(",");
self.write_newline();
}
self.write_indent();
self.generate_column_def(col)?;
}
self.indent_level -= 1;
self.write_newline();
} else {
for (i, col) in ct.with_partition_columns.iter().enumerate() {
if i > 0 {
self.write(", ");
}
self.generate_column_def(col)?;
}
}
self.write(")");
}

// BigQuery: WITH CONNECTION `project.region.connection`
if let Some(ref conn) = ct.with_connection {
if self.config.pretty {
self.write_newline();
} else {
self.write_space();
}
self.write_keyword("WITH CONNECTION");
self.write_space();
self.generate_table(conn)?;
}

// Output SchemaCommentProperty BEFORE WITH properties (Presto/Hive/Spark style)
// For ClickHouse, SchemaCommentProperty goes after AS SELECT, handled later
if !is_clickhouse {
Expand Down
Loading