Skip to content

Commit

Permalink
Remove redundant code now that syntax roundtrip is more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavcloud committed Dec 13, 2024
1 parent 464fca3 commit f58f9bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
5 changes: 0 additions & 5 deletions src/dialect/hive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,4 @@ impl Dialect for HiveDialect {
fn supports_table_sample_before_alias(&self) -> bool {
true
}

/// See Hive <https://cwiki.apache.org/confluence/display/hive/languagemanual+sampling>
fn supports_implicit_table_sample_method(&self) -> bool {
true
}
}
10 changes: 0 additions & 10 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,16 +718,6 @@ pub trait Dialect: Debug + Any {
fn supports_table_sample_before_alias(&self) -> bool {
false
}

/// Returns true if this dialect support not specifying a table sample method. For example:
///
/// Implicit table sample method: `SELECT * FROM tbl TABLESAMPLE (10)`
/// Explicit table sample method: `SELECT * FROM tbl TABLESAMPLE BERNOULLI (10)`
///
/// <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#sample-clause>
fn supports_implicit_table_sample_method(&self) -> bool {
false
}
}

/// This represents the operators for which precedence must be defined
Expand Down
15 changes: 6 additions & 9 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12386,16 +12386,13 @@ fn parse_create_table_with_enum_types() {

#[test]
fn test_table_sample() {
let dialects = all_dialects_where(|d| !d.supports_implicit_table_sample_method());
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)");

// The only dialect that supports implicit tablesample is Hive and it requires aliase after the table sample
let dialects = all_dialects_where(|d| {
d.supports_implicit_table_sample_method() && d.supports_table_sample_before_alias()
});
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)");
}

0 comments on commit f58f9bb

Please sign in to comment.