Skip to content

Commit

Permalink
internal: add features for all the dialects
Browse files Browse the repository at this point in the history
  • Loading branch information
gvozdvmozgu authored and benfdking committed Sep 17, 2024
1 parent cafd016 commit a8ec417
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: Swatinem/rust-cache@v2
- name: Checkout sources
uses: actions/checkout@v4
- uses: taiki-e/install-action@cargo-hack
- uses: taiki-e/install-action@cargo-machete
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- uses: taiki-e/install-action@cargo-machete
- name: Checkout sources
uses: actions/checkout@v4
- name: Run cargo clippy
run: cargo clippy --all --all-features -- -D warnings
- name: Check unused dependencies
run: cargo machete
- name: Cargo hack
run: cargo hack check --each-feature --exclude-features=codegen-docs

prettier-formatting:
name: Check Prettier formatting
runs-on: ubuntu-latest
Expand Down
28 changes: 27 additions & 1 deletion crates/lib-dialects/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ crate-type = ["cdylib", "rlib"]
name = "dialects"
harness = false

[features]
default = [
"athena",
"bigquery",
"clickhouse",
"duckdb",
"hive",
"postgres",
"redshift",
"snowflake",
"sparksql",
"sqlite",
"trino",
]
athena = []
bigquery = []
clickhouse = []
duckdb = ["postgres"]
hive = []
postgres = []
redshift = ["postgres"]
snowflake = []
sparksql = ["hive"]
sqlite = []
trino = []

[dependencies]
sqruff-lib-core = { path = "../lib-core" }
itertools = "0.13.0"
Expand All @@ -25,4 +51,4 @@ sqruff-lib-core = { path = "../lib-core", features = ["serde", "stringify"] }
rayon = "1.10.0"
expect-test = "1.5.0"
glob = "0.3.1"
serde_yaml = "0.9.34+deprecated"
serde_yaml = "0.9.34+deprecated"
38 changes: 35 additions & 3 deletions crates/lib-dialects/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,71 @@ use sqruff_lib_core::dialects::init::DialectKind;

pub mod ansi;
mod ansi_keywords;
#[cfg(feature = "athena")]
pub mod athena;
#[cfg(feature = "athena")]
mod athena_keywords;
#[cfg(feature = "bigquery")]
pub mod bigquery;
#[cfg(feature = "bigquery")]
mod bigquery_keywords;
#[cfg(feature = "clickhouse")]
pub mod clickhouse;
#[cfg(feature = "clickhouse")]
mod clickhouse_keywords;
#[cfg(feature = "duckdb")]
pub mod duckdb;
#[cfg(feature = "hive")]
pub mod hive;
#[cfg(feature = "postgres")]
pub mod postgres;
#[cfg(feature = "postgres")]
mod postgres_keywords;
#[cfg(feature = "redshift")]
pub mod redshift;
#[cfg(feature = "redshift")]
mod redshift_keywords;
#[cfg(feature = "snowflake")]
pub mod snowflake;
#[cfg(feature = "snowflake")]
mod snowflake_keywords;
#[cfg(feature = "sparksql")]
pub mod sparksql;
#[cfg(feature = "sparksql")]
mod sparksql_keywords;
#[cfg(feature = "sqlite")]
pub mod sqlite;
#[cfg(feature = "sqlite")]
mod sqlite_keywords;
#[cfg(feature = "trino")]
pub mod trino;
#[cfg(feature = "trino")]
mod trino_keywords;

pub fn kind_to_dialect(kind: &DialectKind) -> Dialect {
match kind {
pub fn kind_to_dialect(kind: &DialectKind) -> Option<Dialect> {
#[allow(unreachable_patterns)]
Some(match kind {
DialectKind::Ansi => ansi::dialect(),
#[cfg(feature = "athena")]
DialectKind::Athena => athena::dialect(),
#[cfg(feature = "bigquery")]
DialectKind::Bigquery => bigquery::dialect(),
#[cfg(feature = "clickhouse")]
DialectKind::Clickhouse => clickhouse::dialect(),
#[cfg(feature = "duckdb")]
DialectKind::Duckdb => duckdb::dialect(),
#[cfg(feature = "postgres")]
DialectKind::Postgres => postgres::dialect(),
#[cfg(feature = "redshift")]
DialectKind::Redshift => redshift::dialect(),
#[cfg(feature = "snowflake")]
DialectKind::Snowflake => snowflake::dialect(),
#[cfg(feature = "sparksql")]
DialectKind::Sparksql => sparksql::dialect(),
#[cfg(feature = "sqlite")]
DialectKind::Sqlite => sqlite::dialect(),
#[cfg(feature = "trino")]
DialectKind::Trino => trino::dialect(),
}
_ => return None,
})
}
5 changes: 4 additions & 1 deletion crates/lib-dialects/tests/dialects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ fn main() {
// Go through each of the dialects and check if the files are present
for dialect_name in &dialects {
let dialect_kind = DialectKind::from_str(dialect_name).unwrap();
let dialect = kind_to_dialect(&dialect_kind);
let Some(dialect) = kind_to_dialect(&dialect_kind) else {
println!("{} disabled", dialect_name);
continue;
};

let path = format!("test/fixtures/dialects/{}/*.sql", dialect_name);
let files = glob::glob(&path).unwrap().flatten().collect_vec();
Expand Down
3 changes: 2 additions & 1 deletion crates/lib/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ impl FluffConfig {

let mut this = Self {
raw: configs,
dialect,
dialect: dialect
.expect("Dialect is disabled. Please enable the corresponding feature."),
extra_config_path,
_configs: AHashMap::new(),
indentation: indentation.unwrap_or_default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/core/test_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ pub fn parse_ansi_string(sql: &str) -> ErasedSegment {
}

pub fn fresh_ansi_dialect() -> Dialect {
kind_to_dialect(&DialectKind::Ansi)
kind_to_dialect(&DialectKind::Ansi).unwrap()
}

0 comments on commit a8ec417

Please sign in to comment.