From a3759b5b4bf4c39682a05dae3058d1c38a7f204c Mon Sep 17 00:00:00 2001 From: Yevhenii Melnyk Date: Tue, 4 Apr 2023 09:23:17 +0200 Subject: [PATCH] [sqllogictest] Run tests on Windows --- .../src/engines/datafusion/mod.rs | 10 ++------ .../src/engines/datafusion/normalize.rs | 12 +++++++-- .../core/tests/sqllogictests/src/main.rs | 25 ++++++++++++++++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/datafusion/core/tests/sqllogictests/src/engines/datafusion/mod.rs b/datafusion/core/tests/sqllogictests/src/engines/datafusion/mod.rs index c87f0048ce17..4c64daf15593 100644 --- a/datafusion/core/tests/sqllogictests/src/engines/datafusion/mod.rs +++ b/datafusion/core/tests/sqllogictests/src/engines/datafusion/mod.rs @@ -24,7 +24,6 @@ use self::error::{DFSqlLogicTestError, Result}; use async_trait::async_trait; use datafusion::arrow::record_batch::RecordBatch; use datafusion::prelude::SessionContext; -use datafusion_sql::parser::DFParser; use sqllogictest::DBOutput; mod error; @@ -64,7 +63,7 @@ impl sqllogictest::AsyncDB for DataFusion { /// [`Runner`] calls this function to perform sleep. /// - /// The default implementation is `std::thread::sleep`, which is universial to any async runtime + /// The default implementation is `std::thread::sleep`, which is universal to any async runtime /// but would block the current thread. If you are running in tokio runtime, you should override /// this by `tokio::time::sleep`. async fn sleep(dur: Duration) { @@ -73,12 +72,7 @@ impl sqllogictest::AsyncDB for DataFusion { } async fn run_query(ctx: &SessionContext, sql: impl Into) -> Result { - let sql = sql.into(); - // check if the sql is more than one statement - if let Ok(mut statements) = DFParser::parse_sql(&sql) { - statements.pop_front().expect("at least one SQL statement"); - } - let df = ctx.sql(sql.as_str()).await?; + let df = ctx.sql(sql.into().as_str()).await?; let types = normalize::convert_schema_to_types(df.schema().fields()); let results: Vec = df.collect().await?; diff --git a/datafusion/core/tests/sqllogictests/src/engines/datafusion/normalize.rs b/datafusion/core/tests/sqllogictests/src/engines/datafusion/normalize.rs index 69b6c54c2fec..1f4855730cca 100644 --- a/datafusion/core/tests/sqllogictests/src/engines/datafusion/normalize.rs +++ b/datafusion/core/tests/sqllogictests/src/engines/datafusion/normalize.rs @@ -135,10 +135,18 @@ fn workspace_root() -> object_store::path::Path { .expect("parent of datafusion") .to_string_lossy(); - object_store::path::Path::parse(workspace_root).unwrap() + let sanitized_workplace_root = if cfg!(windows) { + // Object store paths are delimited with `/`, e.g. `D:/a/arrow-datafusion/arrow-datafusion/testing/data/csv/aggregate_test_100.csv`. + // The default windows delimiter is `\`, so the workplace path is `D:\a\arrow-datafusion\arrow-datafusion`. + workspace_root.replace(std::path::MAIN_SEPARATOR, object_store::path::DELIMITER) + } else { + workspace_root.to_string() + }; + + object_store::path::Path::parse(sanitized_workplace_root).unwrap() } -// holds the root directory ( +// holds the root directory lazy_static! { static ref WORKSPACE_ROOT: object_store::path::Path = workspace_root(); } diff --git a/datafusion/core/tests/sqllogictests/src/main.rs b/datafusion/core/tests/sqllogictests/src/main.rs index 556949ec6eb7..93779621b7bf 100644 --- a/datafusion/core/tests/sqllogictests/src/main.rs +++ b/datafusion/core/tests/sqllogictests/src/main.rs @@ -17,6 +17,8 @@ use std::error::Error; use std::path::{Path, PathBuf}; +#[cfg(target_family = "windows")] +use std::thread; use log::info; use sqllogictest::strict_column_validator; @@ -33,16 +35,31 @@ mod utils; const TEST_DIRECTORY: &str = "tests/sqllogictests/test_files/"; const PG_COMPAT_FILE_PREFIX: &str = "pg_compat_"; -#[tokio::main] #[cfg(target_family = "windows")] -pub async fn main() -> Result<(), Box> { - println!("Skipping test on windows"); - Ok(()) +pub fn main() { + // Tests from `tpch.slt` fail with stackoverflow with the default stack size. + thread::Builder::new() + .stack_size(2 * 1024 * 1024) // 2 MB + .spawn(move || { + tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap() + .block_on(async { run_tests().await }) + .unwrap() + }) + .unwrap() + .join() + .unwrap(); } #[tokio::main] #[cfg(not(target_family = "windows"))] pub async fn main() -> Result<(), Box> { + run_tests().await +} + +async fn run_tests() -> Result<(), Box> { // Enable logging (e.g. set RUST_LOG=debug to see debug logs) env_logger::init();