mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-03 22:08:16 +00:00
Add support for BigQuery table and view options (#1061)
This commit is contained in:
parent
c7d2903c6d
commit
3a6d3ecba2
8 changed files with 465 additions and 54 deletions
|
@ -2997,11 +2997,11 @@ fn parse_create_table_with_options() {
|
|||
vec![
|
||||
SqlOption {
|
||||
name: "foo".into(),
|
||||
value: Value::SingleQuotedString("bar".into()),
|
||||
value: Expr::Value(Value::SingleQuotedString("bar".into())),
|
||||
},
|
||||
SqlOption {
|
||||
name: "a".into(),
|
||||
value: number("123"),
|
||||
value: Expr::Value(number("123")),
|
||||
},
|
||||
],
|
||||
with_options
|
||||
|
@ -3260,11 +3260,11 @@ fn parse_alter_view_with_options() {
|
|||
vec![
|
||||
SqlOption {
|
||||
name: "foo".into(),
|
||||
value: Value::SingleQuotedString("bar".into()),
|
||||
value: Expr::Value(Value::SingleQuotedString("bar".into())),
|
||||
},
|
||||
SqlOption {
|
||||
name: "a".into(),
|
||||
value: number("123"),
|
||||
value: Expr::Value(number("123")),
|
||||
},
|
||||
],
|
||||
with_options
|
||||
|
@ -5589,18 +5589,18 @@ fn parse_create_view() {
|
|||
query,
|
||||
or_replace,
|
||||
materialized,
|
||||
with_options,
|
||||
options,
|
||||
cluster_by,
|
||||
with_no_schema_binding: late_binding,
|
||||
if_not_exists,
|
||||
temporary,
|
||||
} => {
|
||||
assert_eq!("myschema.myview", name.to_string());
|
||||
assert_eq!(Vec::<Ident>::new(), columns);
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
assert_eq!("SELECT foo FROM bar", query.to_string());
|
||||
assert!(!materialized);
|
||||
assert!(!or_replace);
|
||||
assert_eq!(with_options, vec![]);
|
||||
assert_eq!(options, CreateTableOptions::None);
|
||||
assert_eq!(cluster_by, vec![]);
|
||||
assert!(!late_binding);
|
||||
assert!(!if_not_exists);
|
||||
|
@ -5614,19 +5614,19 @@ fn parse_create_view() {
|
|||
fn parse_create_view_with_options() {
|
||||
let sql = "CREATE VIEW v WITH (foo = 'bar', a = 123) AS SELECT 1";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView { with_options, .. } => {
|
||||
Statement::CreateView { options, .. } => {
|
||||
assert_eq!(
|
||||
vec![
|
||||
CreateTableOptions::With(vec![
|
||||
SqlOption {
|
||||
name: "foo".into(),
|
||||
value: Value::SingleQuotedString("bar".into()),
|
||||
value: Expr::Value(Value::SingleQuotedString("bar".into())),
|
||||
},
|
||||
SqlOption {
|
||||
name: "a".into(),
|
||||
value: number("123"),
|
||||
value: Expr::Value(number("123")),
|
||||
},
|
||||
],
|
||||
with_options
|
||||
]),
|
||||
options
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
@ -5641,7 +5641,7 @@ fn parse_create_view_with_columns() {
|
|||
name,
|
||||
columns,
|
||||
or_replace,
|
||||
with_options,
|
||||
options,
|
||||
query,
|
||||
materialized,
|
||||
cluster_by,
|
||||
|
@ -5650,8 +5650,17 @@ fn parse_create_view_with_columns() {
|
|||
temporary,
|
||||
} => {
|
||||
assert_eq!("v", name.to_string());
|
||||
assert_eq!(columns, vec![Ident::new("has"), Ident::new("cols")]);
|
||||
assert_eq!(with_options, vec![]);
|
||||
assert_eq!(
|
||||
columns,
|
||||
vec![Ident::new("has"), Ident::new("cols"),]
|
||||
.into_iter()
|
||||
.map(|name| ViewColumnDef {
|
||||
name,
|
||||
options: None
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
assert_eq!(options, CreateTableOptions::None);
|
||||
assert_eq!("SELECT 1, 2", query.to_string());
|
||||
assert!(!materialized);
|
||||
assert!(!or_replace);
|
||||
|
@ -5674,18 +5683,18 @@ fn parse_create_view_temporary() {
|
|||
query,
|
||||
or_replace,
|
||||
materialized,
|
||||
with_options,
|
||||
options,
|
||||
cluster_by,
|
||||
with_no_schema_binding: late_binding,
|
||||
if_not_exists,
|
||||
temporary,
|
||||
} => {
|
||||
assert_eq!("myschema.myview", name.to_string());
|
||||
assert_eq!(Vec::<Ident>::new(), columns);
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
assert_eq!("SELECT foo FROM bar", query.to_string());
|
||||
assert!(!materialized);
|
||||
assert!(!or_replace);
|
||||
assert_eq!(with_options, vec![]);
|
||||
assert_eq!(options, CreateTableOptions::None);
|
||||
assert_eq!(cluster_by, vec![]);
|
||||
assert!(!late_binding);
|
||||
assert!(!if_not_exists);
|
||||
|
@ -5703,7 +5712,7 @@ fn parse_create_or_replace_view() {
|
|||
name,
|
||||
columns,
|
||||
or_replace,
|
||||
with_options,
|
||||
options,
|
||||
query,
|
||||
materialized,
|
||||
cluster_by,
|
||||
|
@ -5713,7 +5722,7 @@ fn parse_create_or_replace_view() {
|
|||
} => {
|
||||
assert_eq!("v", name.to_string());
|
||||
assert_eq!(columns, vec![]);
|
||||
assert_eq!(with_options, vec![]);
|
||||
assert_eq!(options, CreateTableOptions::None);
|
||||
assert_eq!("SELECT 1", query.to_string());
|
||||
assert!(!materialized);
|
||||
assert!(or_replace);
|
||||
|
@ -5738,7 +5747,7 @@ fn parse_create_or_replace_materialized_view() {
|
|||
name,
|
||||
columns,
|
||||
or_replace,
|
||||
with_options,
|
||||
options,
|
||||
query,
|
||||
materialized,
|
||||
cluster_by,
|
||||
|
@ -5748,7 +5757,7 @@ fn parse_create_or_replace_materialized_view() {
|
|||
} => {
|
||||
assert_eq!("v", name.to_string());
|
||||
assert_eq!(columns, vec![]);
|
||||
assert_eq!(with_options, vec![]);
|
||||
assert_eq!(options, CreateTableOptions::None);
|
||||
assert_eq!("SELECT 1", query.to_string());
|
||||
assert!(materialized);
|
||||
assert!(or_replace);
|
||||
|
@ -5771,17 +5780,17 @@ fn parse_create_materialized_view() {
|
|||
columns,
|
||||
query,
|
||||
materialized,
|
||||
with_options,
|
||||
options,
|
||||
cluster_by,
|
||||
with_no_schema_binding: late_binding,
|
||||
if_not_exists,
|
||||
temporary,
|
||||
} => {
|
||||
assert_eq!("myschema.myview", name.to_string());
|
||||
assert_eq!(Vec::<Ident>::new(), columns);
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
assert_eq!("SELECT foo FROM bar", query.to_string());
|
||||
assert!(materialized);
|
||||
assert_eq!(with_options, vec![]);
|
||||
assert_eq!(options, CreateTableOptions::None);
|
||||
assert!(!or_replace);
|
||||
assert_eq!(cluster_by, vec![]);
|
||||
assert!(!late_binding);
|
||||
|
@ -5802,17 +5811,17 @@ fn parse_create_materialized_view_with_cluster_by() {
|
|||
columns,
|
||||
query,
|
||||
materialized,
|
||||
with_options,
|
||||
options,
|
||||
cluster_by,
|
||||
with_no_schema_binding: late_binding,
|
||||
if_not_exists,
|
||||
temporary,
|
||||
} => {
|
||||
assert_eq!("myschema.myview", name.to_string());
|
||||
assert_eq!(Vec::<Ident>::new(), columns);
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
assert_eq!("SELECT foo FROM bar", query.to_string());
|
||||
assert!(materialized);
|
||||
assert_eq!(with_options, vec![]);
|
||||
assert_eq!(options, CreateTableOptions::None);
|
||||
assert!(!or_replace);
|
||||
assert_eq!(cluster_by, vec![Ident::new("foo")]);
|
||||
assert!(!late_binding);
|
||||
|
@ -7439,11 +7448,11 @@ fn parse_cache_table() {
|
|||
options: vec![
|
||||
SqlOption {
|
||||
name: Ident::with_quote('\'', "K1"),
|
||||
value: Value::SingleQuotedString("V1".into()),
|
||||
value: Expr::Value(Value::SingleQuotedString("V1".into())),
|
||||
},
|
||||
SqlOption {
|
||||
name: Ident::with_quote('\'', "K2"),
|
||||
value: number("0.88"),
|
||||
value: Expr::Value(number("0.88")),
|
||||
},
|
||||
],
|
||||
query: None,
|
||||
|
@ -7464,11 +7473,11 @@ fn parse_cache_table() {
|
|||
options: vec![
|
||||
SqlOption {
|
||||
name: Ident::with_quote('\'', "K1"),
|
||||
value: Value::SingleQuotedString("V1".into()),
|
||||
value: Expr::Value(Value::SingleQuotedString("V1".into())),
|
||||
},
|
||||
SqlOption {
|
||||
name: Ident::with_quote('\'', "K2"),
|
||||
value: number("0.88"),
|
||||
value: Expr::Value(number("0.88")),
|
||||
},
|
||||
],
|
||||
query: Some(query.clone()),
|
||||
|
@ -7489,11 +7498,11 @@ fn parse_cache_table() {
|
|||
options: vec![
|
||||
SqlOption {
|
||||
name: Ident::with_quote('\'', "K1"),
|
||||
value: Value::SingleQuotedString("V1".into()),
|
||||
value: Expr::Value(Value::SingleQuotedString("V1".into())),
|
||||
},
|
||||
SqlOption {
|
||||
name: Ident::with_quote('\'', "K2"),
|
||||
value: number("0.88"),
|
||||
value: Expr::Value(number("0.88")),
|
||||
},
|
||||
],
|
||||
query: Some(query.clone()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue