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
1 change: 1 addition & 0 deletions fuzz/fuzz_seeds/bigquery_tablesample_reservoir.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM t TABLESAMPLE RESERVOIR (100 ROWS) REPEATABLE (10)
7 changes: 7 additions & 0 deletions src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,12 @@ pub enum TableSampleMethod {
System,
/// `BLOCK` sampling method.
Block,
/// `RESERVOIR` sampling method.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a documentation link here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added a link to the docs and short description.

///
/// Picks a fixed number of rows (`n ROWS`) at random, or every row when the input has fewer.
///
/// [Spanner](https://cloud.google.com/spanner/docs/reference/standard-sql/query-syntax#tablesample_operator)
Reservoir,
}

impl fmt::Display for TableSampleMethod {
Expand All @@ -1892,6 +1898,7 @@ impl fmt::Display for TableSampleMethod {
TableSampleMethod::Row => write!(f, "ROW"),
TableSampleMethod::System => write!(f, "SYSTEM"),
TableSampleMethod::Block => write!(f, "BLOCK"),
TableSampleMethod::Reservoir => write!(f, "RESERVOIR"),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ define_keywords!(
REPLICATE,
REPLICATION,
REQUIRE,
RESERVOIR,
RESET,
RESOLVE,
RESOURCE,
Expand Down
2 changes: 2 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17941,11 +17941,13 @@ impl<'a> Parser<'a> {
Keyword::ROW,
Keyword::SYSTEM,
Keyword::BLOCK,
Keyword::RESERVOIR,
]) {
Some(Keyword::BERNOULLI) => Some(TableSampleMethod::Bernoulli),
Some(Keyword::ROW) => Some(TableSampleMethod::Row),
Some(Keyword::SYSTEM) => Some(TableSampleMethod::System),
Some(Keyword::BLOCK) => Some(TableSampleMethod::Block),
Some(Keyword::RESERVOIR) => Some(TableSampleMethod::Reservoir),
_ => None,
};

Expand Down
8 changes: 8 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17628,6 +17628,14 @@ fn test_table_sample() {
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)");
dialects.verified_stmt("SELECT * FROM tbl AS t TABLESAMPLE RESERVOIR (50 ROWS)");

assert_eq!(
dialects
.parse_sql_statements("SELECT * FROM tbl TABLESAMPLE RESERVOIR ()")
.unwrap_err(),
ParserError::ParserError("Expecting number or byte length e.g. 100M".to_string())
);
}

#[test]
Expand Down