-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Drive sqllogictest runner on directory contents rather than hard coded list #4472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1e1df56
Update sqllogictest runner based on files
alamb 5710572
port some tests
alamb 7ae1f03
fmt
alamb cd9f9a3
improve comments
alamb 1b89ed3
Merge remote-tracking branch 'apache/master' into alamb/file_based_ru…
alamb 923053a
fix compilation on windows
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,8 @@ | |
| use async_trait::async_trait; | ||
| use datafusion::arrow::csv::WriterBuilder; | ||
| use datafusion::arrow::record_batch::RecordBatch; | ||
| use datafusion::prelude::SessionContext; | ||
| use std::path::PathBuf; | ||
| use datafusion::prelude::{SessionConfig, SessionContext}; | ||
| use std::path::Path; | ||
| use std::time::Duration; | ||
|
|
||
| use sqllogictest::TestError; | ||
|
|
@@ -29,53 +29,18 @@ mod setup; | |
| mod utils; | ||
|
|
||
| const TEST_DIRECTORY: &str = "tests/sqllogictests/test_files"; | ||
| const TEST_CATEGORIES: [TestCategory; 2] = | ||
| [TestCategory::Aggregate, TestCategory::ArrowTypeOf]; | ||
|
|
||
| pub enum TestCategory { | ||
| Aggregate, | ||
| ArrowTypeOf, | ||
| } | ||
|
|
||
| impl TestCategory { | ||
| fn as_str(&self) -> &'static str { | ||
| match self { | ||
| TestCategory::Aggregate => "Aggregate", | ||
| TestCategory::ArrowTypeOf => "ArrowTypeOf", | ||
| } | ||
| } | ||
|
|
||
| fn test_filename(&self) -> &'static str { | ||
| match self { | ||
| TestCategory::Aggregate => "aggregate.slt", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than hard coding this list, I propose instead listing the files in the directory instead
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You did what I want to do 🤣 |
||
| TestCategory::ArrowTypeOf => "arrow_typeof.slt", | ||
| } | ||
| } | ||
|
|
||
| async fn register_test_tables(&self, ctx: &SessionContext) { | ||
| println!("[{}] Registering tables", self.as_str()); | ||
| match self { | ||
| TestCategory::Aggregate => setup::register_aggregate_tables(ctx).await, | ||
| TestCategory::ArrowTypeOf => (), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct DataFusion { | ||
| ctx: SessionContext, | ||
| test_category: TestCategory, | ||
| file_name: String, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl sqllogictest::AsyncDB for DataFusion { | ||
| type Error = TestError; | ||
|
|
||
| async fn run(&mut self, sql: &str) -> Result<String> { | ||
| println!( | ||
| "[{}] Running query: \"{}\"", | ||
| self.test_category.as_str(), | ||
| sql | ||
| ); | ||
| println!("[{}] Running query: \"{}\"", self.file_name, sql); | ||
| let result = run_query(&self.ctx, sql).await?; | ||
| Ok(result) | ||
| } | ||
|
|
@@ -96,26 +61,70 @@ impl sqllogictest::AsyncDB for DataFusion { | |
| } | ||
|
|
||
| #[tokio::main] | ||
| #[cfg(target_family = "windows")] | ||
| pub async fn main() -> Result<()> { | ||
| for test_category in TEST_CATEGORIES { | ||
| let filename = PathBuf::from(format!( | ||
| "{}/{}", | ||
| TEST_DIRECTORY, | ||
| test_category.test_filename() | ||
| )); | ||
| let ctx = SessionContext::new(); | ||
| test_category.register_test_tables(&ctx).await; | ||
|
|
||
| if !cfg!(target_os = "windows") { | ||
| let mut tester = sqllogictest::Runner::new(DataFusion { ctx, test_category }); | ||
| // TODO: use tester.run_parallel_async() | ||
| tester.run_file_async(filename).await?; | ||
| } | ||
| println!("Skipping test on windows"); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::main] | ||
| #[cfg(not(target_family = "windows"))] | ||
| pub async fn main() -> Result<()> { | ||
| let paths = std::fs::read_dir(TEST_DIRECTORY).unwrap(); | ||
|
|
||
| // run each file using its own new SessionContext | ||
| // | ||
| // Note: can't use tester.run_parallel_async() | ||
| // as that will reuse the same SessionContext | ||
| // | ||
| // We could run these tests in parallel eventually if we wanted. | ||
|
|
||
| for path in paths { | ||
| // TODO better error handling | ||
| let path = path.unwrap().path(); | ||
|
|
||
| run_file(&path).await?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Run the tests in the specified `.slt` file | ||
| async fn run_file(path: &Path) -> Result<()> { | ||
| println!("Running: {}", path.display()); | ||
|
|
||
| let file_name = path.file_name().unwrap().to_str().unwrap().to_string(); | ||
|
|
||
| let ctx = context_for_test_file(&file_name).await; | ||
|
|
||
| let mut tester = sqllogictest::Runner::new(DataFusion { ctx, file_name }); | ||
| tester.run_file_async(path).await?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Create a SessionContext, configured for the specific test | ||
| async fn context_for_test_file(file_name: &str) -> SessionContext { | ||
| match file_name { | ||
| "aggregate.slt" => { | ||
| println!("Registering aggregate tables"); | ||
| let ctx = SessionContext::new(); | ||
| setup::register_aggregate_tables(&ctx).await; | ||
| ctx | ||
| } | ||
| "information_schema.slt" => { | ||
| println!("Enabling information schema"); | ||
| SessionContext::with_config( | ||
| SessionConfig::new().with_information_schema(true), | ||
| ) | ||
| } | ||
| _ => { | ||
| println!("Using default SessionContex"); | ||
| SessionContext::new() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn format_batches(batches: &[RecordBatch]) -> Result<String> { | ||
| let mut bytes = vec![]; | ||
| { | ||
|
|
||
61 changes: 61 additions & 0 deletions
61
datafusion/core/tests/sqllogictests/test_files/information_schema.slt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
|
|
||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # show all variables | ||
| query R | ||
| SHOW ALL | ||
| ---- | ||
| datafusion.catalog.location NULL | ||
| datafusion.catalog.type NULL | ||
| datafusion.execution.batch_size 8192 | ||
| datafusion.execution.coalesce_batches true | ||
| datafusion.execution.coalesce_target_batch_size 4096 | ||
| datafusion.execution.parquet.enable_page_index false | ||
| datafusion.execution.parquet.metadata_size_hint NULL | ||
| datafusion.execution.parquet.pruning true | ||
| datafusion.execution.parquet.pushdown_filters false | ||
| datafusion.execution.parquet.reorder_filters false | ||
| datafusion.execution.parquet.skip_metadata true | ||
| datafusion.execution.time_zone +00:00 | ||
| datafusion.explain.logical_plan_only false | ||
| datafusion.explain.physical_plan_only false | ||
| datafusion.optimizer.filter_null_join_keys false | ||
| datafusion.optimizer.hash_join_single_partition_threshold 1048576 | ||
| datafusion.optimizer.max_passes 3 | ||
| datafusion.optimizer.prefer_hash_join true | ||
| datafusion.optimizer.skip_failed_rules true | ||
| datafusion.optimizer.top_down_join_key_reordering true | ||
|
|
||
| # show_variable_in_config_options | ||
| query R | ||
| SHOW datafusion.execution.batch_size | ||
| ---- | ||
| datafusion.execution.batch_size 8192 | ||
|
|
||
| # show_time_zone_default_utc | ||
| # https://github.com/apache/arrow-datafusion/issues/3255 | ||
| query R | ||
| SHOW TIME ZONE | ||
| ---- | ||
| datafusion.execution.time_zone +00:00 | ||
|
|
||
| # show_timezone_default_utc | ||
| # https://github.com/apache/arrow-datafusion/issues/3255 | ||
| query R | ||
| SHOW TIMEZONE | ||
| ---- | ||
| datafusion.execution.time_zone +00:00 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to a data file rather than .rs file 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, step by step migration in progress