melgenek commented on code in PR #4834:
URL: https://github.com/apache/arrow-datafusion/pull/4834#discussion_r1080602268
##########
datafusion/core/tests/sqllogictests/src/main.rs:
##########
@@ -15,112 +15,135 @@
// specific language governing permissions and limitations
// under the License.
-use async_trait::async_trait;
-use datafusion::arrow::record_batch::RecordBatch;
-use datafusion::prelude::SessionContext;
-use datafusion_sql::parser::{DFParser, Statement};
-use log::info;
-use normalize::convert_batches;
-use sqllogictest::DBOutput;
-use sqlparser::ast::Statement as SQLStatement;
-use std::path::Path;
-use std::time::Duration;
-
-use crate::error::{DFSqlLogicTestError, Result};
-use crate::insert::insert;
-
-mod error;
-mod insert;
-mod normalize;
-mod setup;
-mod utils;
+use std::error::Error;
+use std::fs::copy;
+use std::path::{Path, PathBuf};
-const TEST_DIRECTORY: &str = "tests/sqllogictests/test_files";
-
-pub struct DataFusion {
- ctx: SessionContext,
- file_name: String,
-}
+use log::info;
+use tempfile::tempdir;
+use testcontainers::clients::Cli as Docker;
-#[async_trait]
-impl sqllogictest::AsyncDB for DataFusion {
- type Error = DFSqlLogicTestError;
+use datafusion::prelude::SessionContext;
- async fn run(&mut self, sql: &str) -> Result<DBOutput> {
- println!("[{}] Running query: \"{}\"", self.file_name, sql);
- let result = run_query(&self.ctx, sql).await?;
- Ok(result)
- }
+use crate::engines::datafusion::DataFusion;
+use crate::engines::postgres::{Postgres, PG_DB, PG_PASSWORD, PG_PORT, PG_USER};
- /// Engine name of current database.
- fn engine_name(&self) -> &str {
- "DataFusion"
- }
+mod engines;
+mod setup;
+mod utils;
- /// [`Runner`] calls this function to perform sleep.
- ///
- /// The default implementation is `std::thread::sleep`, which is
universial 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) {
- tokio::time::sleep(dur).await;
- }
-}
+const TEST_DIRECTORY: &str = "tests/sqllogictests/test_files";
+const TEST_DIRECTORY_POSTGRES: &str =
"tests/sqllogictests/postgres/test_files";
#[tokio::main]
#[cfg(target_family = "windows")]
-pub async fn main() -> Result<()> {
+pub async fn main() -> Result<(), Box<dyn Error>> {
println!("Skipping test on windows");
Ok(())
}
#[tokio::main]
#[cfg(not(target_family = "windows"))]
-pub async fn main() -> Result<()> {
+pub async fn main() -> Result<(), Box<dyn Error>> {
// Enable logging (e.g. set RUST_LOG=debug to see debug logs)
-
- use sqllogictest::{default_validator, update_test_file};
env_logger::init();
let options = Options::new();
- // default to all files in test directory filtering based on name
- let files: Vec<_> = std::fs::read_dir(TEST_DIRECTORY)
- .unwrap()
- .map(|path| path.unwrap().path())
- .filter(|path| options.check_test_file(path.as_path()))
- .collect();
+ let files: Vec<_> = read_test_files(&options);
info!("Running test files {:?}", files);
for path in files {
- println!("Running: {}", path.display());
-
let file_name =
path.file_name().unwrap().to_str().unwrap().to_string();
- // Create the test runner
- let ctx = context_for_test_file(&file_name).await;
- let mut runner = sqllogictest::Runner::new(DataFusion { ctx, file_name
});
-
- // run each file using its own new DB
- //
- // We could run these tests in parallel eventually if we wanted.
if options.complete_mode {
- info!("Using complete mode to complete {}", path.display());
- let col_separator = " ";
- let validator = default_validator;
- update_test_file(path, runner, col_separator, validator)
- .await
- .map_err(|e| e.to_string())?;
+ run_complete_file(&path, file_name).await?;
+ } else if options.postgres_mode {
+ run_postgres_test_file(&path, file_name).await?;
} else {
- // run the test normally:
- runner.run_file_async(path).await?;
+ run_test_file(&path, file_name).await?;
}
}
Ok(())
}
+async fn run_test_file(path: &PathBuf, file_name: String) -> Result<(),
Box<dyn Error>> {
+ println!("Running: {}", path.display());
+ let ctx = context_for_test_file(&file_name).await;
+ let mut runner = sqllogictest::Runner::new(DataFusion::new(ctx,
file_name));
+ runner.run_file_async(path).await?;
+ Ok(())
+}
+
+async fn run_postgres_test_file(
Review Comment:
I updated the tests to have explicit results.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]