diff --git a/Cargo.lock b/Cargo.lock index 3844abd9..0c68c0f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,9 +124,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.88" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "arrayvec" @@ -726,9 +726,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cast" @@ -738,9 +738,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.18" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ "jobserver", "libc", @@ -2105,9 +2105,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -2468,19 +2468,18 @@ dependencies = [ [[package]] name = "lz4" -version = "1.26.0" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "958b4caa893816eea05507c20cfe47574a43d9a697138a7872990bba8a0ece68" +checksum = "a231296ca742e418c43660cb68e082486ff2538e8db432bc818580f3965025ed" dependencies = [ - "libc", "lz4-sys", ] [[package]] name = "lz4-sys" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109de74d5d2353660401699a4174a4ff23fcc649caf553df71933c7fb45ad868" +checksum = "fcb44a01837a858d47e5a630d2ccf304c8efcc4b83b8f9f75b7a9ee4fcc6e57d" dependencies = [ "cc", "libc", @@ -2532,9 +2531,9 @@ dependencies = [ [[package]] name = "minijinja" -version = "2.2.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7d3e3a3eece1fa4618237ad41e1de855ced47eab705cec1c9a920e1d1c5aad" +checksum = "1028b628753a7e1a88fc59c9ba4b02ecc3bc0bd3c7af23df667bc28df9b3310e" dependencies = [ "serde", ] @@ -3117,9 +3116,9 @@ dependencies = [ [[package]] name = "pretty_assertions" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" dependencies = [ "diff", "yansi", @@ -3301,6 +3300,9 @@ dependencies = [ "quary_proto", "regex", "serde_yaml", + "sqruff-lib-core", + "sqruff-lib-dialects", + "sqruff-sqlinference", "tempfile", "testcontainers", "testcontainers-modules", @@ -3326,7 +3328,8 @@ dependencies = [ "rust-embed", "serde_yaml", "sha2", - "sqruff-lib", + "sqruff-lib-core", + "sqruff-lib-dialects", "sqruff-sqlinference", "tokio", ] @@ -3351,6 +3354,9 @@ dependencies = [ "regex", "snowflake-api", "sqlx", + "sqruff-lib-core", + "sqruff-lib-dialects", + "sqruff-sqlinference", "tempfile", "testcontainers", "testcontainers-modules", @@ -3375,7 +3381,8 @@ dependencies = [ "send_wrapper", "serde", "serde_yaml", - "sqruff-lib", + "sqruff-lib-core", + "sqruff-lib-dialects", "sqruff-sqlinference", "tokio", "wasm-bindgen", @@ -4536,15 +4543,14 @@ dependencies = [ [[package]] name = "sqruff-lib" -version = "0.17.0" -source = "git+https://github.com/quarylabs/sqruff.git#ae19d9a4e1785418fc5900e1bb6b2ffc3af3c23f" +version = "0.18.0" +source = "git+https://github.com/quarylabs/sqruff.git#a282063b8f91dd7190a8bd0294cfa3a9d7985d33" dependencies = [ "ahash 0.8.11", "anstyle", "common-path", "configparser", "dyn-clone", - "dyn_ord", "enum_dispatch", "fancy-regex", "getrandom", @@ -4559,7 +4565,8 @@ dependencies = [ "rustc-hash", "slyce", "smol_str", - "sptr", + "sqruff-lib-core", + "sqruff-lib-dialects", "strum 0.26.3", "strum_macros 0.26.4", "tikv-jemallocator", @@ -4568,12 +4575,46 @@ dependencies = [ "walkdir", ] +[[package]] +name = "sqruff-lib-core" +version = "0.18.0" +source = "git+https://github.com/quarylabs/sqruff.git#a282063b8f91dd7190a8bd0294cfa3a9d7985d33" +dependencies = [ + "ahash 0.8.11", + "dyn-clone", + "dyn_ord", + "fancy-regex", + "indexmap 2.5.0", + "itertools 0.13.0", + "nohash-hasher", + "pretty_assertions", + "rustc-hash", + "smol_str", + "sptr", + "strum 0.26.3", + "strum_macros 0.26.4", +] + +[[package]] +name = "sqruff-lib-dialects" +version = "0.18.0" +source = "git+https://github.com/quarylabs/sqruff.git#a282063b8f91dd7190a8bd0294cfa3a9d7985d33" +dependencies = [ + "ahash 0.8.11", + "dyn-clone", + "itertools 0.13.0", + "serde_yaml", + "sqruff-lib-core", + "strum 0.26.3", +] + [[package]] name = "sqruff-sqlinference" -version = "0.17.0" -source = "git+https://github.com/quarylabs/sqruff.git#ae19d9a4e1785418fc5900e1bb6b2ffc3af3c23f" +version = "0.18.0" +source = "git+https://github.com/quarylabs/sqruff.git#a282063b8f91dd7190a8bd0294cfa3a9d7985d33" dependencies = [ "sqruff-lib", + "sqruff-lib-core", ] [[package]] @@ -4982,9 +5023,9 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" dependencies = [ "indexmap 2.5.0", "toml_datetime", @@ -5117,9 +5158,9 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] @@ -5654,9 +5695,9 @@ dependencies = [ [[package]] name = "yansi" -version = "0.5.1" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "yup-oauth2" diff --git a/Cargo.toml b/Cargo.toml index 5c3e8d2f..d5ff5456 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,10 @@ license = "Apache-2.0" rust-version = "1.80.0" [workspace.dependencies] -cargo-nextest = "0.9" \ No newline at end of file +sqlinference = { git = "https://github.com/quarylabs/sqruff.git", package = "sqruff-sqlinference" } +sqruff-lib-core = { git = "https://github.com/quarylabs/sqruff.git", package = "sqruff-lib-core" } +sqruff-lib-dialects = { git = "https://github.com/quarylabs/sqruff.git", package = "sqruff-lib-dialects" } + +[workspace.dev-dependencies] +cargo-nextest = "0.9" + diff --git a/rust/cli/Cargo.toml b/rust/cli/Cargo.toml index 4e168726..b312741f 100644 --- a/rust/cli/Cargo.toml +++ b/rust/cli/Cargo.toml @@ -22,6 +22,9 @@ base64 = "0.22.1" dotenv = "0.15" serde_yaml = "0.9.33" duckdb = { version = "1.0.0", features = ["bundled"] } +sqlinference.workspace = true +sqruff-lib-core.workspace = true +sqruff-lib-dialects.workspace = true [dev-dependencies] chrono = "0.4.38" diff --git a/rust/cli/src/main.rs b/rust/cli/src/main.rs index 6e7fcedf..57fa7018 100644 --- a/rust/cli/src/main.rs +++ b/rust/cli/src/main.rs @@ -344,11 +344,13 @@ async fn main_wrapped() -> Result<(), String> { // TODO Need to reintroduce the progressbar println!("running tests {}", tests.len()); + let dialect = query_generator.get_dialect(); + let parser = sqruff_lib_core::parser::parser::Parser::new(&dialect, Default::default()); return match run_tests_internal( &query_generator, &file_system, &project, - &query_generator.get_dialect(), + &parser, mode, func, test_args.full_source, diff --git a/rust/core/Cargo.toml b/rust/core/Cargo.toml index 8a3b74db..ac0818d1 100644 --- a/rust/core/Cargo.toml +++ b/rust/core/Cargo.toml @@ -10,11 +10,12 @@ rust-version.workspace = true crate-type = ["cdylib", "rlib"] [dependencies] -prost = { default-features = false, version = "0.13" } quary_proto = { path = "../../proto/gen/rust" } -sqlinference = { git = "https://github.com/quarylabs/sqruff.git", package = "sqruff-sqlinference" } -sqruff = { git = "https://github.com/quarylabs/sqruff.git", package = "sqruff-lib" } +sqlinference.workspace = true +sqruff-lib-core.workspace = true +sqruff-lib-dialects.workspace = true +prost = { default-features = false, version = "0.13" } rust-embed = "8" csv = "1" petgraph = { version = "0.6", default-features = false } diff --git a/rust/core/src/database_bigquery.rs b/rust/core/src/database_bigquery.rs index f32d2379..5b86cfe0 100644 --- a/rust/core/src/database_bigquery.rs +++ b/rust/core/src/database_bigquery.rs @@ -1,17 +1,13 @@ -use sqruff::core::{ - config::{FluffConfig, Value}, - parser::parser::Parser, -}; - use crate::databases::{ base_for_seeds_create_table_specifying_text_type, DatabaseQueryGenerator, SnapshotGenerator, }; +use sqruff_lib_core::dialects::base::Dialect; +use sqruff_lib_dialects::bigquery; #[derive(Debug, Clone)] pub struct DatabaseQueryGeneratorBigQuery { project_id: String, dataset_id: String, - config: FluffConfig, } impl DatabaseQueryGeneratorBigQuery { @@ -19,15 +15,6 @@ impl DatabaseQueryGeneratorBigQuery { DatabaseQueryGeneratorBigQuery { project_id, dataset_id, - config: FluffConfig::new( - [( - "core".into(), - Value::Map([("dialect".into(), Value::String("bigquery".into()))].into()), - )] - .into(), - None, - None, - ), } } } @@ -78,8 +65,8 @@ impl DatabaseQueryGenerator for DatabaseQueryGeneratorBigQuery { )] } - fn get_dialect(&self) -> Parser { - Parser::new(&self.config) + fn get_dialect(&self) -> Dialect { + bigquery::dialect() } fn database_name_wrapper(&self, name: &str) -> String { diff --git a/rust/core/src/database_clickhouse.rs b/rust/core/src/database_clickhouse.rs index 97a86601..bc59bca4 100644 --- a/rust/core/src/database_clickhouse.rs +++ b/rust/core/src/database_clickhouse.rs @@ -1,14 +1,11 @@ use std::time::SystemTime; use chrono::{DateTime, Utc}; - #[cfg(target_arch = "wasm32")] use js_sys::Date; use pbjson_types::Struct; -use sqruff::core::{ - config::{FluffConfig, Value}, - parser::parser::Parser, -}; +use sqruff_lib_core::dialects::base::Dialect; +use sqruff_lib_dialects::clickhouse; use crate::databases::{ base_for_seeds_create_table_specifying_text_type, CacheStatus, DatabaseQueryGenerator, @@ -21,7 +18,6 @@ pub struct DatabaseQueryGeneratorClickhouse { /// override_now is used to override the current timestamp in the generated SQL. It is primarily /// used for testing purposes. override_now: Option, - config: FluffConfig, } impl DatabaseQueryGeneratorClickhouse { @@ -32,15 +28,6 @@ impl DatabaseQueryGeneratorClickhouse { DatabaseQueryGeneratorClickhouse { database, override_now, - config: FluffConfig::new( - [( - "core".into(), - Value::Map([("dialect".into(), Value::String("clickhouse".into()))].into()), - )] - .into(), - None, - None, - ), } } } @@ -152,8 +139,8 @@ impl DatabaseQueryGenerator for DatabaseQueryGeneratorClickhouse { )] } - fn get_dialect(&self) -> Parser { - Parser::new(&self.config) + fn get_dialect(&self) -> Dialect { + clickhouse::dialect() } fn database_name_wrapper(&self, name: &str) -> String { diff --git a/rust/core/src/database_dremio.rs b/rust/core/src/database_dremio.rs index 1220c67a..169931e4 100644 --- a/rust/core/src/database_dremio.rs +++ b/rust/core/src/database_dremio.rs @@ -1,7 +1,5 @@ -use sqruff::core::{ - config::{FluffConfig, Value}, - parser::parser::Parser, -}; +use sqruff_lib_core::dialects::base::Dialect; +use sqruff_lib_dialects::postgres; use crate::databases::{DatabaseQueryGenerator, SnapshotGenerator}; @@ -9,7 +7,6 @@ use crate::databases::{DatabaseQueryGenerator, SnapshotGenerator}; pub struct DatabaseQueryGeneratorDremio { pub space: String, pub folder_path: String, - config: FluffConfig, } const SPACE_DEAFULT: &str = "@user"; @@ -20,15 +17,6 @@ impl DatabaseQueryGeneratorDremio { Self { space: space.unwrap_or_else(|| SPACE_DEAFULT.to_string()), folder_path: folder_path.unwrap_or_else(|| FOLDER_PATH_DEFAULT.to_string()), - config: FluffConfig::new( - [( - "core".into(), - Value::Map([("dialect".into(), Value::String("postgres".into()))].into()), - )] - .into(), - None, - None, - ), } } } @@ -76,8 +64,8 @@ impl DatabaseQueryGenerator for DatabaseQueryGeneratorDremio { vec![drop, create] } - fn get_dialect(&self) -> Parser { - Parser::new(&self.config) + fn get_dialect(&self) -> Dialect { + postgres::dialect() } fn database_name_wrapper(&self, name: &str) -> String { diff --git a/rust/core/src/database_duckdb.rs b/rust/core/src/database_duckdb.rs index d87700a1..fd8b786f 100644 --- a/rust/core/src/database_duckdb.rs +++ b/rust/core/src/database_duckdb.rs @@ -6,11 +6,9 @@ use chrono::{DateTime, Utc}; #[cfg(target_arch = "wasm32")] use js_sys::Date; use quary_proto::snapshot::snapshot_strategy::StrategyType; -use sqruff::core::{ - config::{FluffConfig, Value}, - parser::parser::Parser, -}; +use sqruff_lib_core::dialects::base::Dialect; +use sqruff_lib_dialects::duckdb; use std::time::SystemTime; #[derive(Debug, Clone)] @@ -19,7 +17,6 @@ pub struct DatabaseQueryGeneratorDuckDB { /// override_now is used to override the current timestamp in the generated SQL. It is primarily /// used for testing purposes. override_now: Option, - config: FluffConfig, } impl DatabaseQueryGeneratorDuckDB { @@ -30,15 +27,6 @@ impl DatabaseQueryGeneratorDuckDB { DatabaseQueryGeneratorDuckDB { schema, override_now, - config: FluffConfig::new( - [( - "core".into(), - Value::Map([("dialect".into(), Value::String("duckdb".into()))].into()), - )] - .into(), - None, - None, - ), } } } @@ -93,8 +81,8 @@ impl DatabaseQueryGenerator for DatabaseQueryGeneratorDuckDB { )] } - fn get_dialect(&self) -> Parser { - Parser::new(&self.config) + fn get_dialect(&self) -> Dialect { + duckdb::dialect() } fn database_name_wrapper(&self, name: &str) -> String { diff --git a/rust/core/src/database_postgres.rs b/rust/core/src/database_postgres.rs index f18c257a..3077f35a 100644 --- a/rust/core/src/database_postgres.rs +++ b/rust/core/src/database_postgres.rs @@ -6,8 +6,8 @@ use js_sys::Date; use pbjson_types::value::Kind; use pbjson_types::{Struct, Value}; use quary_proto::snapshot::snapshot_strategy::StrategyType; -use sqruff::core::config::FluffConfig; -use sqruff::core::parser::parser::Parser; +use sqruff_lib_core::dialects::base::Dialect; +use sqruff_lib_dialects::postgres; use crate::databases::{ base_for_seeds_create_table_specifying_text_type, CacheStatus, DatabaseQueryGenerator, @@ -21,25 +21,13 @@ pub struct DatabaseQueryGeneratorPostgres { /// override_now is used to override the current timestamp in the generated SQL. It is primarily /// used for testing purposes. override_now: Option, - config: FluffConfig, } impl DatabaseQueryGeneratorPostgres { pub fn new(schema: String, override_now: Option) -> DatabaseQueryGeneratorPostgres { - use sqruff::core::config::Value; - DatabaseQueryGeneratorPostgres { schema, override_now, - config: FluffConfig::new( - [( - "core".into(), - Value::Map([("dialect".into(), Value::String("postgres".into()))].into()), - )] - .into(), - None, - None, - ), } } } @@ -214,8 +202,8 @@ impl DatabaseQueryGenerator for DatabaseQueryGeneratorPostgres { )] } - fn get_dialect(&self) -> Parser { - Parser::new(&self.config) + fn get_dialect(&self) -> Dialect { + postgres::dialect() } fn database_name_wrapper(&self, name: &str) -> String { diff --git a/rust/core/src/database_redshift.rs b/rust/core/src/database_redshift.rs index 3b8b8600..5f923200 100644 --- a/rust/core/src/database_redshift.rs +++ b/rust/core/src/database_redshift.rs @@ -8,11 +8,9 @@ use chrono::{DateTime, Utc}; use js_sys::Date; use pbjson_types::Struct; use quary_proto::snapshot::snapshot_strategy::StrategyType; -use sqruff::core::{ - config::{FluffConfig, Value}, - parser::parser::Parser, -}; +use sqruff_lib_core::dialects::base::Dialect; +use sqruff_lib_dialects::redshift; use std::time::SystemTime; #[derive(Debug, Clone)] @@ -21,7 +19,6 @@ pub struct DatabaseQueryGeneratorRedshift { /// override_now is used to override the current timestamp in the generated SQL. It is primarily /// used for testing purposes. override_now: Option, - config: FluffConfig, } impl DatabaseQueryGeneratorRedshift { @@ -29,16 +26,6 @@ impl DatabaseQueryGeneratorRedshift { DatabaseQueryGeneratorRedshift { schema, override_now, - config: FluffConfig::new( - [( - "core".into(), - // FIXME: redshift -> ansi - Value::Map([("dialect".into(), Value::String("ansi".into()))].into()), - )] - .into(), - None, - None, - ), } } } @@ -166,8 +153,8 @@ impl DatabaseQueryGenerator for DatabaseQueryGeneratorRedshift { )] } - fn get_dialect(&self) -> Parser { - Parser::new(&self.config) + fn get_dialect(&self) -> Dialect { + redshift::dialect() } fn database_name_wrapper(&self, name: &str) -> String { diff --git a/rust/core/src/database_snowflake.rs b/rust/core/src/database_snowflake.rs index bd86ae32..f902a2b1 100644 --- a/rust/core/src/database_snowflake.rs +++ b/rust/core/src/database_snowflake.rs @@ -4,33 +4,18 @@ use crate::databases::{ }; use pbjson_types::Struct; use quary_proto::snapshot::snapshot_strategy::StrategyType; -use sqruff::core::{ - config::{FluffConfig, Value}, - parser::parser::Parser, -}; +use sqruff_lib_core::dialects::base::Dialect; +use sqruff_lib_dialects::snowflake; #[derive(Debug, Clone)] pub struct DatabaseQueryGeneratorSnowflake { database: String, schema: String, - config: FluffConfig, } impl DatabaseQueryGeneratorSnowflake { pub fn new(database: String, schema: String) -> DatabaseQueryGeneratorSnowflake { - DatabaseQueryGeneratorSnowflake { - database, - schema, - config: FluffConfig::new( - [( - "core".into(), - Value::Map([("dialect".into(), Value::String("snowflake".into()))].into()), - )] - .into(), - None, - None, - ), - } + DatabaseQueryGeneratorSnowflake { database, schema } } } @@ -133,8 +118,8 @@ impl DatabaseQueryGenerator for DatabaseQueryGeneratorSnowflake { )] } - fn get_dialect(&self) -> Parser { - Parser::new(&self.config) + fn get_dialect(&self) -> Dialect { + snowflake::dialect() } fn database_name_wrapper(&self, name: &str) -> String { diff --git a/rust/core/src/database_sqlite.rs b/rust/core/src/database_sqlite.rs index 7cf5e653..688cd05f 100644 --- a/rust/core/src/database_sqlite.rs +++ b/rust/core/src/database_sqlite.rs @@ -1,28 +1,13 @@ -use sqruff::core::{ - config::{FluffConfig, Value}, - parser::parser::Parser, -}; - use crate::databases::{DatabaseQueryGenerator, SnapshotGenerator}; +use sqruff_lib_core::dialects::base::Dialect; +use sqruff_lib_dialects::sqlite; #[derive(Debug)] -pub struct DatabaseQueryGeneratorSqlite { - config: FluffConfig, -} +pub struct DatabaseQueryGeneratorSqlite; impl Default for DatabaseQueryGeneratorSqlite { fn default() -> Self { - Self { - config: FluffConfig::new( - [( - "core".into(), - Value::Map([("dialect".into(), Value::String("sqlite".into()))].into()), - )] - .into(), - None, - None, - ), - } + Self {} } } @@ -65,8 +50,8 @@ impl DatabaseQueryGenerator for DatabaseQueryGeneratorSqlite { vec![drop, create] } - fn get_dialect(&self) -> Parser { - Parser::new(&self.config) + fn get_dialect(&self) -> Dialect { + sqlite::dialect() } fn database_name_wrapper(&self, name: &str) -> String { diff --git a/rust/core/src/databases.rs b/rust/core/src/databases.rs index e9e03841..caca216b 100644 --- a/rust/core/src/databases.rs +++ b/rust/core/src/databases.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use pbjson_types::Struct; use quary_proto::snapshot::snapshot_strategy::StrategyType; use quary_proto::TableAddress; -use sqruff::core::parser::parser::Parser; +use sqruff_lib_core::dialects::base::Dialect; use std::fmt::Debug; /// CacheStatus defines whether the cache exists and matches the current model, if so it is possible @@ -143,7 +143,7 @@ pub trait DatabaseQueryGenerator: SnapshotGenerator + Debug + Sync { ) -> Vec; /// get_dialect returns the dialect of the database. - fn get_dialect(&self) -> Parser; + fn get_dialect(&self) -> Dialect; /// database_name_wrapper returns a full path or name wrapped in quotes that work for the specific database fn database_name_wrapper(&self, name: &str) -> String; @@ -155,14 +155,18 @@ pub trait DatabaseQueryGenerator: SnapshotGenerator + Debug + Sync { } impl DatabaseQueryGenerator for Box { - fn supported_materialization_types(&self) -> &'static [&'static str] { - self.as_ref().supported_materialization_types() + fn get_name(&self) -> &'static str { + self.as_ref().get_name() } fn default_materalization_type(&self) -> &'static str { self.as_ref().default_materalization_type() } + fn supported_materialization_types(&self) -> &'static [&'static str] { + self.as_ref().supported_materialization_types() + } + fn models_drop_query( &self, view_name: &str, @@ -229,7 +233,7 @@ impl DatabaseQueryGenerator for Box { .automatic_cache_sql_create_statement(model, model_cache_name) } - fn get_dialect(&self) -> Parser { + fn get_dialect(&self) -> Dialect { self.as_ref().get_dialect() } @@ -240,10 +244,6 @@ impl DatabaseQueryGenerator for Box { fn get_current_timestamp(&self) -> String { self.as_ref().get_current_timestamp() } - - fn get_name(&self) -> &'static str { - self.as_ref().get_name() - } } pub trait SnapshotGenerator { diff --git a/rust/core/src/project.rs b/rust/core/src/project.rs index 36973b5b..d1e5198f 100644 --- a/rust/core/src/project.rs +++ b/rust/core/src/project.rs @@ -28,7 +28,7 @@ use quary_proto::{ TestUnique, }; use sqlinference::infer_tests::{get_column_with_source, ExtractedSelect}; -use sqruff::core::parser::parser::Parser; +use sqruff_lib_core::parser::parser::Parser; use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::path::{Path, PathBuf}; diff --git a/rust/core/src/rpc_proto_defined_functions.rs b/rust/core/src/rpc_proto_defined_functions.rs index a9c6713a..080f5e67 100644 --- a/rust/core/src/rpc_proto_defined_functions.rs +++ b/rust/core/src/rpc_proto_defined_functions.rs @@ -10,7 +10,6 @@ use quary_proto::{ColumnTest, Edge, File, Project, Test}; use sqlinference::infer_tests::{infer_tests, InferenceReason}; use sqlinference::inference::{figure_out_skippable_tests, TestRunnerAction}; -use sqruff::core::parser::parser::Parser; use std::collections::{BTreeSet, HashMap, HashSet}; use std::path::PathBuf; @@ -159,6 +158,7 @@ pub async fn infer_skippable_tests_internal( use crate::project_to_sql::{project_and_fs_to_query_sql, project_and_fs_to_sql_for_views}; use futures::future::try_join_all; +use sqruff_lib_core::parser::parser::Parser; pub async fn name_to_raw_model_map_internal( project: &Project, diff --git a/rust/core/src/test_runner.rs b/rust/core/src/test_runner.rs index b2dc2af0..50204c08 100644 --- a/rust/core/src/test_runner.rs +++ b/rust/core/src/test_runner.rs @@ -8,7 +8,7 @@ use quary_proto::{ failed, passed, FailedRunResults, InferredChain, InferredChainWithOperation, TestResult, }; use quary_proto::{Project, TestResults, TestRunner}; -use sqruff::core::parser::parser::Parser; +use sqruff_lib_core::parser::parser::Parser; use std::collections::{BTreeMap, HashMap, HashSet}; use std::future::Future; use std::pin::Pin; diff --git a/rust/quary-databases/Cargo.toml b/rust/quary-databases/Cargo.toml index f81e5256..fbdd2f47 100644 --- a/rust/quary-databases/Cargo.toml +++ b/rust/quary-databases/Cargo.toml @@ -10,6 +10,9 @@ rust-version.workspace = true [dependencies] quary-core = { path = "../core" } quary_proto = { path = "../../proto/gen/rust" } +sqlinference.workspace = true +sqruff-lib-core.workspace = true +sqruff-lib-dialects.workspace = true arrow-flight = { version = "52.2.0" , default-features = true, features = ["flight-sql-experimental"] } yup-oauth2 = { version = "9", default-features = false } diff --git a/rust/quary-databases/src/databases_dremio.rs b/rust/quary-databases/src/databases_dremio.rs index 703f3a1b..a0b3e6af 100644 --- a/rust/quary-databases/src/databases_dremio.rs +++ b/rust/quary-databases/src/databases_dremio.rs @@ -269,7 +269,7 @@ mod test { assert!(exec.is_ok(), "Failed to execute query {:?}", exec); - let exec = dremio + dremio .exec(r#"CREATE OR REPLACE VIEW test.test.test_view AS SELECT * FROM Samples."samples.dremio.com"."NYC-taxi-trips.csv""#) .await .unwrap(); diff --git a/rust/quary-databases/src/databases_sqlite.rs b/rust/quary-databases/src/databases_sqlite.rs index e68ccc41..328f8556 100644 --- a/rust/quary-databases/src/databases_sqlite.rs +++ b/rust/quary-databases/src/databases_sqlite.rs @@ -427,11 +427,14 @@ mod tests { }) }); + let dialect = query_generator.get_dialect(); + let parser = sqruff_lib_core::parser::parser::Parser::new(&dialect, Default::default()); + let results = run_tests_internal( &query_generator, &file_system, &project, - &query_generator.get_dialect(), + &parser, TestRunner::All, func, false, @@ -509,12 +512,14 @@ mod tests { } }) }); + let dialect = query_generator.get_dialect(); + let parser = sqruff_lib_core::parser::parser::Parser::new(&dialect, Default::default()); let results = run_tests_internal( &query_generator, &file_system, &project, - &query_generator.get_dialect(), + &parser, TestRunner::Skip, func, false, diff --git a/rust/wasm-binding/Cargo.toml b/rust/wasm-binding/Cargo.toml index 33f4c108..99be3bbe 100644 --- a/rust/wasm-binding/Cargo.toml +++ b/rust/wasm-binding/Cargo.toml @@ -15,6 +15,9 @@ default = ["console_error_panic_hook"] [dependencies] wasm-bindgen = { version = "0.2.91", default-features = false } send_wrapper = "0.6" +sqlinference.workspace = true +sqruff-lib-core.workspace = true +sqruff-lib-dialects.workspace = true # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires @@ -25,8 +28,6 @@ console_error_panic_hook = { version = "0.1", optional = true } prost = { default-features = false, version = "0.13" } js-sys = "0.3" quary_proto = { path = "../../proto/gen/rust" } -sqlinference = { git = "https://github.com/quarylabs/sqruff.git", package = "sqruff-sqlinference" } -sqruff = { git = "https://github.com/quarylabs/sqruff.git", package = "sqruff-lib" } async-trait = "0.1" wasm-bindgen-futures = "0.4" futures = { version = "0.3", features = ["async-await"], default-features = false } diff --git a/rust/wasm-binding/src/rpc_proto_defined_functions.rs b/rust/wasm-binding/src/rpc_proto_defined_functions.rs index 920d3fbe..f317dcc0 100644 --- a/rust/wasm-binding/src/rpc_proto_defined_functions.rs +++ b/rust/wasm-binding/src/rpc_proto_defined_functions.rs @@ -1,6 +1,7 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use std::path::PathBuf; +use crate::rpc_proto_scaffolding::{JsFileSystem, Writer}; use quary_core::automatic_branching::{ cache_view_name_to_table_name_and_hash, given_map_and_hash_map_return_sub_graph_all_cached_for_a_particular_model, is_cache_full_path, @@ -60,8 +61,7 @@ use quary_proto::{ }; use sqlinference::columns::get_columns_internal; use sqlinference::infer_tests::infer_tests; - -use crate::rpc_proto_scaffolding::{JsFileSystem, Writer}; +use sqruff_lib_core::parser::parser::Parser; pub(crate) async fn is_path_empty( _: Writer, @@ -1023,17 +1023,16 @@ pub(crate) async fn get_model_table_internal( let project_root = request.project_root; let project = quary_core::project::parse_project(file_system, database, &project_root).await?; - let dialect = database.get_dialect(); let model_map = name_to_raw_model_map_internal(&project, file_system).await?; let model_statement = model_map .get(&request.model_name) .ok_or(format!("Model {} not found", request.model_name))?; - let (columns, _) = get_columns_internal(&database.get_dialect(), model_statement) - .ok() - .unzip(); + let dialect = database.get_dialect(); + let parser = Parser::new(&dialect, Default::default()); + let (columns, _) = get_columns_internal(&parser, model_statement).ok().unzip(); let inferred_tests: Option> = infer_tests( - &database.get_dialect(), + &parser, format!("{}.{}", DEFAULT_SCHEMA_PREFIX, request.model_name).as_str(), model_statement, &project @@ -1048,7 +1047,7 @@ pub(crate) async fn get_model_table_internal( &project, DEFAULT_SCHEMA_PREFIX, &request.model_name, - &dialect, + &parser, file_system, ) .await diff --git a/rust/wasm-binding/src/rpc_rust_defined.rs b/rust/wasm-binding/src/rpc_rust_defined.rs index 7484311d..9ec46baf 100644 --- a/rust/wasm-binding/src/rpc_rust_defined.rs +++ b/rust/wasm-binding/src/rpc_rust_defined.rs @@ -9,6 +9,7 @@ use quary_core::test_runner::{ run_model_tests_internal, run_tests_internal, RunReturnResult, RunStatementFunc, RunTestError, }; use quary_proto::TestRunner; +use sqruff_lib_core::parser::parser::Parser; use std::rc::Rc; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::JsFuture; @@ -91,12 +92,14 @@ pub async fn run_tests( let function = Rc::new(run_statement); let func = create_run_statement_func(function); + let dialect = database.get_dialect(); + let parser = Parser::new(&dialect, Default::default()); let test_results = run_tests_internal( &database, &file_system, &project, - &database.get_dialect(), + &parser, test_runner, func, false,