Skip to content

Commit

Permalink
format option labels without leading space
Browse files Browse the repository at this point in the history
  • Loading branch information
iffyio committed Dec 4, 2023
1 parent b374f0e commit a345ec1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ impl fmt::Display for ViewColumnDef {
if let Some(options) = self.options.as_ref() {
write!(
f,
" OPTIONS ({})",
" OPTIONS({})",
display_comma_separated(options.as_slice())
)?;
}
Expand Down Expand Up @@ -628,7 +628,7 @@ pub enum ColumnOption {
/// BigQuery specific: Explicit column options in a view [1] or table [2]
/// Syntax
/// ```sql
/// OPTIONS (description="field desc")
/// OPTIONS(description="field desc")
/// ```
/// [1]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#view_column_option_list
/// [2]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#column_option_list
Expand Down Expand Up @@ -707,7 +707,7 @@ impl fmt::Display for ColumnOption {
}
}
SqlOptions(options) => {
write!(f, "OPTIONS ({})", display_comma_separated(options))
write!(f, "OPTIONS({})", display_comma_separated(options))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ pub enum CreateTableOptions {
/// <https://www.postgresql.org/docs/current/sql-createtable.html>
With(Vec<SqlOption>),
/// Options specified using the `OPTIONS` keyword.
/// e.g. `OPTIONS (description = "123")`
/// e.g. `OPTIONS(description = "123")`
///
/// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
Options(Vec<SqlOption>),
Expand All @@ -1389,7 +1389,7 @@ impl fmt::Display for CreateTableOptions {
write!(f, "WITH ({})", display_comma_separated(with_options))
}
CreateTableOptions::Options(options) => {
write!(f, "OPTIONS ({})", display_comma_separated(options))
write!(f, "OPTIONS({})", display_comma_separated(options))
}
CreateTableOptions::None => Ok(()),
}
Expand Down
18 changes: 8 additions & 10 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ fn parse_create_view_with_options() {
let sql = trim_sql(
r#"
CREATE VIEW myproject.mydataset.newview
(name, age OPTIONS (description = "field age"))
OPTIONS
(expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 48 HOUR),
(name, age OPTIONS(description = "field age"))
OPTIONS(expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 48 HOUR),
friendly_name = "newview",
description = "a view that expires in 2 days",
labels = [("org_unit", "development")])
Expand Down Expand Up @@ -148,7 +147,7 @@ fn parse_create_view_with_options() {
query.to_string()
);
assert_eq!(
r#"OPTIONS (expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 48 HOUR), friendly_name = "newview", description = "a view that expires in 2 days", labels = [("org_unit", "development")])"#,
r#"OPTIONS(expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 48 HOUR), friendly_name = "newview", description = "a view that expires in 2 days", labels = [("org_unit", "development")])"#,
options.to_string()
);
let CreateTableOptions::Options(options) = options else {
Expand All @@ -173,12 +172,11 @@ fn parse_create_table_with_options() {
let sql = trim_sql(
r#"
CREATE TABLE mydataset.newtable
(x INT64 NOT NULL OPTIONS (description = "field x"),
y BOOL OPTIONS (description = "field y"))
(x INT64 NOT NULL OPTIONS(description = "field x"),
y BOOL OPTIONS(description = "field y"))
PARTITION BY _PARTITIONDATE
CLUSTER BY userid, age
OPTIONS(partition_expiration_days = 1,
CLUSTER BY userid, age OPTIONS(partition_expiration_days = 1,
description = "table option description")
"#,
);
Expand Down Expand Up @@ -258,8 +256,8 @@ fn parse_create_table_with_options() {
let sql = trim_sql(
r#"
CREATE TABLE mydataset.newtable
(x INT64 NOT NULL OPTIONS (description = "field x"),
y BOOL OPTIONS (description = "field y"))
(x INT64 NOT NULL OPTIONS(description = "field x"),
y BOOL OPTIONS(description = "field y"))
CLUSTER BY userid
OPTIONS(partition_expiration_days = 1,
Expand Down

0 comments on commit a345ec1

Please sign in to comment.