Skip to content

Commit 4e5efd1

Browse files
committed
bigquery: SqlOption might contain expression
1 parent 38d49e0 commit 4e5efd1

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

src/ast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4290,7 +4290,7 @@ pub struct HiveFormat {
42904290
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
42914291
pub struct SqlOption {
42924292
pub name: WithSpan<Ident>,
4293-
pub value: Value,
4293+
pub value: Expr,
42944294
}
42954295

42964296
impl fmt::Display for SqlOption {

src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4693,7 +4693,7 @@ impl<'a> Parser<'a> {
46934693
pub fn parse_sql_option(&mut self) -> Result<SqlOption, ParserError> {
46944694
let name = self.parse_identifier()?;
46954695
self.expect_token(&Token::Eq)?;
4696-
let value = self.parse_value()?;
4696+
let value = self.parse_expr()?;
46974697
Ok(SqlOption { name, value })
46984698
}
46994699

tests/sqlparser_bigquery.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,3 +1378,10 @@ fn test_create_table_primary_key_not_enforced() {
13781378
"CREATE TABLE `myproject`.`mydataset`.`mytable` (id INT64, PRIMARY KEY (id) NOT ENFORCED)",
13791379
);
13801380
}
1381+
1382+
#[test]
1383+
fn test_options_expression() {
1384+
bigquery().verified_stmt(
1385+
"CREATE TABLE `myproject`.`mydataset`.`mytable` (id INT64) OPTIONS (max_staleness = INTERVAL '0-0 0 0:15:0' YEAR TO SECOND)",
1386+
);
1387+
}

tests/sqlparser_common.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,11 +2979,11 @@ fn parse_create_table_with_options() {
29792979
vec![
29802980
SqlOption {
29812981
name: Ident::new("foo").empty_span(),
2982-
value: Value::SingleQuotedString("bar".into()),
2982+
value: Expr::Value(Value::SingleQuotedString("bar".into())),
29832983
},
29842984
SqlOption {
29852985
name: Ident::new("a").empty_span(),
2986-
value: number("123"),
2986+
value: Expr::Value(number("123")),
29872987
},
29882988
],
29892989
with_options
@@ -3252,11 +3252,11 @@ fn parse_alter_view_with_options() {
32523252
vec![
32533253
SqlOption {
32543254
name: Ident::new("foo").empty_span(),
3255-
value: Value::SingleQuotedString("bar".into()),
3255+
value: Expr::Value(Value::SingleQuotedString("bar".into())),
32563256
},
32573257
SqlOption {
32583258
name: Ident::new("a").empty_span(),
3259-
value: number("123"),
3259+
value: Expr::Value(number("123")),
32603260
},
32613261
],
32623262
with_options
@@ -5741,11 +5741,11 @@ fn parse_create_view_with_options() {
57415741
vec![
57425742
SqlOption {
57435743
name: Ident::new("foo").empty_span(),
5744-
value: Value::SingleQuotedString("bar".into()),
5744+
value: Expr::Value(Value::SingleQuotedString("bar".into())),
57455745
},
57465746
SqlOption {
57475747
name: Ident::new("a").empty_span(),
5748-
value: number("123"),
5748+
value: Expr::Value(number("123")),
57495749
},
57505750
],
57515751
with_options
@@ -7561,11 +7561,11 @@ fn parse_cache_table() {
75617561
options: vec![
75627562
SqlOption {
75637563
name: Ident::with_quote('\'', "K1").empty_span(),
7564-
value: Value::SingleQuotedString("V1".into()),
7564+
value: Expr::Value(Value::SingleQuotedString("V1".into())),
75657565
},
75667566
SqlOption {
75677567
name: Ident::with_quote('\'', "K2").empty_span(),
7568-
value: number("0.88"),
7568+
value: Expr::Value(number("0.88")),
75697569
},
75707570
],
75717571
query: None,
@@ -7586,11 +7586,11 @@ fn parse_cache_table() {
75867586
options: vec![
75877587
SqlOption {
75887588
name: Ident::with_quote('\'', "K1").empty_span(),
7589-
value: Value::SingleQuotedString("V1".into()),
7589+
value: Expr::Value(Value::SingleQuotedString("V1".into())),
75907590
},
75917591
SqlOption {
75927592
name: Ident::with_quote('\'', "K2").empty_span(),
7593-
value: number("0.88"),
7593+
value: Expr::Value(number("0.88")),
75947594
},
75957595
],
75967596
query: Some(query.clone()),
@@ -7611,11 +7611,11 @@ fn parse_cache_table() {
76117611
options: vec![
76127612
SqlOption {
76137613
name: Ident::with_quote('\'', "K1").empty_span(),
7614-
value: Value::SingleQuotedString("V1".into()),
7614+
value: Expr::Value(Value::SingleQuotedString("V1".into())),
76157615
},
76167616
SqlOption {
76177617
name: Ident::with_quote('\'', "K2").empty_span(),
7618-
value: number("0.88"),
7618+
value: Expr::Value(number("0.88")),
76197619
},
76207620
],
76217621
query: Some(query.clone()),

tests/sqlparser_postgres.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ fn parse_create_table_with_defaults() {
479479
vec![
480480
SqlOption {
481481
name: Ident::new("fillfactor").empty_span(),
482-
value: number("20")
482+
value: Expr::Value(number("20")),
483483
},
484484
SqlOption {
485485
name: Ident::new("user_catalog_table").empty_span(),
486-
value: Value::Boolean(true)
486+
value: Expr::Value(Value::Boolean(true)),
487487
},
488488
SqlOption {
489489
name: Ident::new("autovacuum_vacuum_threshold").empty_span(),
490-
value: number("100")
490+
value: Expr::Value(number("100")),
491491
},
492492
]
493493
);

0 commit comments

Comments
 (0)