Add support for TABLESAMPLE (#1580)

This commit is contained in:
Yoav Cohen 2024-12-15 10:40:25 +01:00 committed by GitHub
parent 7bc6ddb8fb
commit 316bb14135
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 546 additions and 458 deletions

View file

@ -222,16 +222,7 @@ fn parse_delete_statement() {
..
}) => {
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::with_quote('"', "table")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![Ident::with_quote('"', "table")])),
from[0].relation
);
}
@ -1379,16 +1370,7 @@ fn parse_table_identifiers() {
assert_eq!(
select.from,
vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(expected),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(expected)),
joins: vec![]
},]
);
@ -1562,6 +1544,7 @@ fn parse_table_time_travel() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
joins: vec![]
},]
@ -1661,6 +1644,7 @@ fn parse_merge() {
partitions: Default::default(),
with_ordinality: false,
json_path: None,
sample: None,
},
table
);
@ -1677,6 +1661,7 @@ fn parse_merge() {
partitions: Default::default(),
with_ordinality: false,
json_path: None,
sample: None,
},
source
);

View file

@ -63,16 +63,7 @@ fn parse_map_access_expr() {
})],
into: None,
from: vec![TableWithJoins {
relation: Table {
name: ObjectName(vec![Ident::new("foos")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::new("foos")])),
joins: vec![],
}],
lateral_views: vec![],
@ -175,9 +166,7 @@ fn parse_delimited_identifiers() {
args,
with_hints,
version,
with_ordinality: _,
partitions: _,
json_path: _,
..
} => {
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
@ -1625,6 +1614,14 @@ fn parse_explain_table() {
}
}
#[test]
fn parse_table_sample() {
clickhouse().verified_stmt("SELECT * FROM tbl SAMPLE 0.1");
clickhouse().verified_stmt("SELECT * FROM tbl SAMPLE 1000");
clickhouse().verified_stmt("SELECT * FROM tbl SAMPLE 1 / 10");
clickhouse().verified_stmt("SELECT * FROM tbl SAMPLE 1 / 10 OFFSET 1 / 2");
}
fn clickhouse() -> TestedDialects {
TestedDialects::new(vec![Box::new(ClickHouseDialect {})])
}

View file

@ -41,7 +41,7 @@ use sqlparser::tokenizer::Span;
use sqlparser::tokenizer::Tokenizer;
use test_utils::{
all_dialects, all_dialects_where, alter_table_op, assert_eq_vec, call, expr_from_projection,
join, number, only, table, table_alias, TestedDialects,
join, number, only, table, table_alias, table_from_name, TestedDialects,
};
#[macro_use]
@ -359,16 +359,7 @@ fn parse_update_set_from() {
stmt,
Statement::Update {
table: TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::new("t1")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::new("t1")])),
joins: vec![],
},
assignments: vec![Assignment {
@ -391,16 +382,7 @@ fn parse_update_set_from() {
],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::new("t1")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::new("t1")])),
joins: vec![],
}],
lateral_views: vec![],
@ -480,6 +462,7 @@ fn parse_update_with_table_alias() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
joins: vec![],
},
@ -572,6 +555,7 @@ fn parse_select_with_table_alias() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
joins: vec![],
}]
@ -601,16 +585,7 @@ fn parse_delete_statement() {
..
}) => {
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::with_quote('"', "table")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![Ident::with_quote('"', "table")])),
from[0].relation
);
}
@ -649,29 +624,17 @@ fn parse_delete_statement_for_multi_tables() {
tables[1]
);
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::new("schema1"), Ident::new("table1")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![
Ident::new("schema1"),
Ident::new("table1")
])),
from[0].relation
);
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::new("schema2"), Ident::new("table2")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![
Ident::new("schema2"),
Ident::new("table2")
])),
from[0].joins[0].relation
);
}
@ -689,55 +652,31 @@ fn parse_delete_statement_for_multi_tables_with_using() {
..
}) => {
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::new("schema1"), Ident::new("table1")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![
Ident::new("schema1"),
Ident::new("table1")
])),
from[0].relation
);
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::new("schema2"), Ident::new("table2")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![
Ident::new("schema2"),
Ident::new("table2")
])),
from[1].relation
);
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::new("schema1"), Ident::new("table1")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![
Ident::new("schema1"),
Ident::new("table1")
])),
using[0].relation
);
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::new("schema2"), Ident::new("table2")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![
Ident::new("schema2"),
Ident::new("table2")
])),
using[0].joins[0].relation
);
}
@ -760,16 +699,7 @@ fn parse_where_delete_statement() {
..
}) => {
assert_eq!(
TableFactor::Table {
name: ObjectName(vec![Ident::new("foo")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
table_from_name(ObjectName(vec![Ident::new("foo")])),
from[0].relation,
);
@ -815,6 +745,7 @@ fn parse_where_delete_with_alias_statement() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
from[0].relation,
);
@ -832,6 +763,7 @@ fn parse_where_delete_with_alias_statement() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
joins: vec![],
}]),
@ -4920,20 +4852,11 @@ fn test_parse_named_window() {
],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident {
value: "aggregate_test_100".to_string(),
quote_style: None,
span: Span::empty(),
}]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident {
value: "aggregate_test_100".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![],
}],
lateral_views: vec![],
@ -5511,20 +5434,11 @@ fn parse_interval_and_or_xor() {
}))],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident {
value: "test".to_string(),
quote_style: None,
span: Span::empty(),
}]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident {
value: "test".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![],
}],
lateral_views: vec![],
@ -6132,29 +6046,11 @@ fn parse_implicit_join() {
assert_eq!(
vec![
TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec!["t1".into()]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec!["t1".into()])),
joins: vec![],
},
TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec!["t2".into()]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec!["t2".into()])),
joins: vec![],
},
],
@ -6166,53 +6062,17 @@ fn parse_implicit_join() {
assert_eq!(
vec![
TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec!["t1a".into()]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec!["t1a".into()])),
joins: vec![Join {
relation: TableFactor::Table {
name: ObjectName(vec!["t1b".into()]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec!["t1b".into()])),
global: false,
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
}],
},
TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec!["t2a".into()]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec!["t2a".into()])),
joins: vec![Join {
relation: TableFactor::Table {
name: ObjectName(vec!["t2b".into()]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec!["t2b".into()])),
global: false,
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
}],
@ -6228,16 +6088,7 @@ fn parse_cross_join() {
let select = verified_only_select(sql);
assert_eq!(
Join {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::new("t2")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::new("t2")])),
global: false,
join_operator: JoinOperator::CrossJoin,
},
@ -6263,6 +6114,7 @@ fn parse_joins_on() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
global,
join_operator: f(JoinConstraint::On(Expr::BinaryOp {
@ -6391,6 +6243,7 @@ fn parse_joins_using() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
global: false,
join_operator: f(JoinConstraint::Using(vec!["c1".into()])),
@ -6465,6 +6318,7 @@ fn parse_natural_join() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
global: false,
join_operator: f(JoinConstraint::Natural),
@ -6728,16 +6582,7 @@ fn parse_derived_tables() {
}),
},
joins: vec![Join {
relation: TableFactor::Table {
name: ObjectName(vec!["t2".into()]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec!["t2".into()])),
global: false,
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
}],
@ -7668,20 +7513,11 @@ fn lateral_function() {
top_before_distinct: false,
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident {
value: "customer".to_string(),
quote_style: None,
span: Span::empty(),
}]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident {
value: "customer".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![Join {
relation: TableFactor::Function {
lateral: true,
@ -8499,6 +8335,7 @@ fn parse_merge() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
}
);
assert_eq!(table, table_no_into);
@ -8519,16 +8356,10 @@ fn parse_merge() {
)],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::new("s"), Ident::new("foo")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![
Ident::new("s"),
Ident::new("foo")
])),
joins: vec![],
}],
lateral_views: vec![],
@ -9611,6 +9442,7 @@ fn parse_pivot_table() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
}),
aggregate_functions: vec![
expected_function("a", None),
@ -9686,6 +9518,7 @@ fn parse_unpivot_table() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
}),
value: Ident {
value: "quantity".to_string(),
@ -9756,6 +9589,7 @@ fn parse_pivot_unpivot_table() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
}),
value: Ident {
value: "population".to_string(),
@ -10165,16 +9999,7 @@ fn parse_unload() {
projection: vec![UnnamedExpr(Expr::Identifier(Ident::new("cola"))),],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::new("tab")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::new("tab")])),
joins: vec![],
}],
lateral_views: vec![],
@ -10348,16 +10173,7 @@ fn parse_connect_by() {
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("title"))),
],
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::new("employees")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::new("employees")])),
joins: vec![],
}],
into: None,
@ -10437,16 +10253,7 @@ fn parse_connect_by() {
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("title"))),
],
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::new("employees")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::new("employees")])),
joins: vec![],
}],
into: None,
@ -10601,16 +10408,7 @@ fn test_match_recognize() {
use MatchRecognizeSymbol::*;
use RepetitionQuantifier::*;
let table = TableFactor::Table {
name: ObjectName(vec![Ident::new("my_table")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
};
let table = table_from_name(ObjectName(vec![Ident::new("my_table")]));
fn check(options: &str, expect: TableFactor) {
let select = all_dialects_where(|d| d.supports_match_recognize()).verified_only_select(
@ -12585,3 +12383,16 @@ fn parse_create_table_with_enum_types() {
ParserError::ParserError("Expected: literal string, found: 2".to_string())
);
}
#[test]
fn test_table_sample() {
let dialects = all_dialects_where(|d| d.supports_table_sample_before_alias());
dialects.verified_stmt("SELECT * FROM tbl TABLESAMPLE (50) AS t");
dialects.verified_stmt("SELECT * FROM tbl TABLESAMPLE (50 ROWS) AS t");
dialects.verified_stmt("SELECT * FROM tbl TABLESAMPLE (50 PERCENT) AS t");
let dialects = all_dialects_where(|d| !d.supports_table_sample_before_alias());
dialects.verified_stmt("SELECT * FROM tbl AS t TABLESAMPLE BERNOULLI (50)");
dialects.verified_stmt("SELECT * FROM tbl AS t TABLESAMPLE SYSTEM (50)");
dialects.verified_stmt("SELECT * FROM tbl AS t TABLESAMPLE SYSTEM (50) REPEATABLE (10)");
}

View file

@ -185,16 +185,7 @@ fn test_values_clause() {
"SELECT * FROM values",
));
assert_eq!(
Some(&TableFactor::Table {
name: ObjectName(vec![Ident::new("values")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
}),
Some(&table_from_name(ObjectName(vec![Ident::new("values")]))),
query
.body
.as_select()

View file

@ -268,20 +268,11 @@ fn test_select_union_by_name() {
top_before_distinct: false,
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident {
value: "capitals".to_string(),
quote_style: None,
span: Span::empty(),
}]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident {
value: "capitals".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![],
}],
lateral_views: vec![],
@ -306,20 +297,11 @@ fn test_select_union_by_name() {
top_before_distinct: false,
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident {
value: "weather".to_string(),
quote_style: None,
span: Span::empty(),
}]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident {
value: "weather".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![],
}],
lateral_views: vec![],

View file

@ -459,6 +459,7 @@ fn parse_delimited_identifiers() {
with_ordinality: _,
partitions: _,
json_path: _,
sample: _,
} => {
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
@ -537,6 +538,15 @@ fn parse_use() {
);
}
#[test]
fn test_tample_sample() {
hive().verified_stmt("SELECT * FROM source TABLESAMPLE (BUCKET 3 OUT OF 32 ON rand()) AS s");
hive().verified_stmt("SELECT * FROM source TABLESAMPLE (BUCKET 3 OUT OF 16 ON id)");
hive().verified_stmt("SELECT * FROM source TABLESAMPLE (100M) AS s");
hive().verified_stmt("SELECT * FROM source TABLESAMPLE (0.1 PERCENT) AS s");
hive().verified_stmt("SELECT * FROM source TABLESAMPLE (10 ROWS)");
}
fn hive() -> TestedDialects {
TestedDialects::new(vec![Box::new(HiveDialect {})])
}

View file

@ -73,6 +73,7 @@ fn parse_table_time_travel() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
joins: vec![]
},]
@ -221,6 +222,7 @@ fn parse_mssql_openjson() {
with_ordinality: false,
partitions: vec![],
json_path: None,
sample: None,
},
joins: vec![Join {
relation: TableFactor::OpenJsonTable {
@ -279,6 +281,7 @@ fn parse_mssql_openjson() {
with_ordinality: false,
partitions: vec![],
json_path: None,
sample: None,
},
joins: vec![Join {
relation: TableFactor::OpenJsonTable {
@ -338,6 +341,7 @@ fn parse_mssql_openjson() {
with_ordinality: false,
partitions: vec![],
json_path: None,
sample: None,
},
joins: vec![Join {
relation: TableFactor::OpenJsonTable {
@ -396,6 +400,7 @@ fn parse_mssql_openjson() {
with_ordinality: false,
partitions: vec![],
json_path: None,
sample: None,
},
joins: vec![Join {
relation: TableFactor::OpenJsonTable {
@ -434,6 +439,7 @@ fn parse_mssql_openjson() {
with_ordinality: false,
partitions: vec![],
json_path: None,
sample: None,
},
joins: vec![Join {
relation: TableFactor::OpenJsonTable {
@ -611,9 +617,7 @@ fn parse_delimited_identifiers() {
args,
with_hints,
version,
with_ordinality: _,
partitions: _,
json_path: _,
..
} => {
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
@ -1082,20 +1086,11 @@ fn parse_substring_in_select() {
})],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident {
value: "test".to_string(),
quote_style: None,
span: Span::empty(),
}]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident {
value: "test".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![]
}],
lateral_views: vec![],

View file

@ -1884,16 +1884,9 @@ fn parse_select_with_numeric_prefix_column_name() {
)))],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::with_quote('"', "table")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::with_quote(
'"', "table"
)])),
joins: vec![]
}],
lateral_views: vec![],
@ -1943,16 +1936,9 @@ fn parse_select_with_concatenation_of_exp_number_and_numeric_prefix_column() {
],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::with_quote('"', "table")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::with_quote(
'"', "table"
)])),
joins: vec![]
}],
lateral_views: vec![],
@ -2020,6 +2006,7 @@ fn parse_update_with_joins() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
joins: vec![Join {
relation: TableFactor::Table {
@ -2034,6 +2021,7 @@ fn parse_update_with_joins() {
partitions: vec![],
with_ordinality: false,
json_path: None,
sample: None,
},
global: false,
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
@ -2464,20 +2452,11 @@ fn parse_substring_in_select() {
})],
into: None,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident {
value: "test".to_string(),
quote_style: None,
span: Span::empty(),
}]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident {
value: "test".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![]
}],
lateral_views: vec![],

View file

@ -3581,9 +3581,7 @@ fn parse_delimited_identifiers() {
args,
with_hints,
version,
with_ordinality: _,
partitions: _,
json_path: _,
..
} => {
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);

View file

@ -39,27 +39,18 @@ fn test_square_brackets_over_db_schema_table_name() {
assert_eq!(
select.from[0],
TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![
Ident {
value: "test_schema".to_string(),
quote_style: Some('['),
span: Span::empty(),
},
Ident {
value: "test_table".to_string(),
quote_style: Some('['),
span: Span::empty(),
}
]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![
Ident {
value: "test_schema".to_string(),
quote_style: Some('['),
span: Span::empty(),
},
Ident {
value: "test_table".to_string(),
quote_style: Some('['),
span: Span::empty(),
}
])),
joins: vec![],
}
);
@ -90,27 +81,18 @@ fn test_double_quotes_over_db_schema_table_name() {
assert_eq!(
select.from[0],
TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![
Ident {
value: "test_schema".to_string(),
quote_style: Some('"'),
span: Span::empty(),
},
Ident {
value: "test_table".to_string(),
quote_style: Some('"'),
span: Span::empty(),
}
]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![
Ident {
value: "test_schema".to_string(),
quote_style: Some('"'),
span: Span::empty(),
},
Ident {
value: "test_table".to_string(),
quote_style: Some('"'),
span: Span::empty(),
}
])),
joins: vec![],
}
);
@ -130,9 +112,7 @@ fn parse_delimited_identifiers() {
args,
with_hints,
version,
with_ordinality: _,
partitions: _,
json_path: _,
..
} => {
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);

View file

@ -1188,9 +1188,7 @@ fn parse_delimited_identifiers() {
args,
with_hints,
version,
with_ordinality: _,
partitions: _,
json_path: _,
..
} => {
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
@ -2960,3 +2958,19 @@ fn parse_insert_overwrite() {
let insert_overwrite_into = r#"INSERT OVERWRITE INTO schema.table SELECT a FROM b"#;
snowflake().verified_stmt(insert_overwrite_into);
}
#[test]
fn test_table_sample() {
snowflake_and_generic().verified_stmt("SELECT * FROM testtable SAMPLE (10)");
snowflake_and_generic().verified_stmt("SELECT * FROM testtable TABLESAMPLE (10)");
snowflake_and_generic()
.verified_stmt("SELECT * FROM testtable AS t TABLESAMPLE BERNOULLI (10)");
snowflake_and_generic().verified_stmt("SELECT * FROM testtable AS t TABLESAMPLE ROW (10)");
snowflake_and_generic().verified_stmt("SELECT * FROM testtable AS t TABLESAMPLE ROW (10 ROWS)");
snowflake_and_generic()
.verified_stmt("SELECT * FROM testtable TABLESAMPLE BLOCK (3) SEED (82)");
snowflake_and_generic()
.verified_stmt("SELECT * FROM testtable TABLESAMPLE SYSTEM (3) REPEATABLE (82)");
snowflake_and_generic().verified_stmt("SELECT id FROM mytable TABLESAMPLE (10) REPEATABLE (1)");
snowflake_and_generic().verified_stmt("SELECT id FROM mytable TABLESAMPLE (10) SEED (1)");
}

View file

@ -479,16 +479,7 @@ fn parse_update_tuple_row_values() {
}],
selection: None,
table: TableWithJoins {
relation: TableFactor::Table {
name: ObjectName(vec![Ident::new("x")]),
alias: None,
args: None,
with_hints: vec![],
version: None,
partitions: vec![],
with_ordinality: false,
json_path: None,
},
relation: table_from_name(ObjectName(vec![Ident::new("x")])),
joins: vec![],
},
from: None,