1818use clap:: Parser ;
1919use datafusion_common:: instant:: Instant ;
2020use datafusion_common:: utils:: get_available_parallelism;
21- use datafusion_common:: { exec_datafusion_err , exec_err, DataFusionError , Result } ;
21+ use datafusion_common:: { exec_err, DataFusionError , Result } ;
2222use datafusion_common_runtime:: SpawnedTask ;
23- use datafusion_sqllogictest:: { DataFusion , TestContext } ;
23+ use datafusion_sqllogictest:: {
24+ df_value_validator, read_dir_recursive, setup_scratch_dir, value_normalizer,
25+ DataFusion , TestContext ,
26+ } ;
2427use futures:: stream:: StreamExt ;
2528use indicatif:: {
2629 HumanDuration , MultiProgress , ProgressBar , ProgressDrawTarget , ProgressStyle ,
2730} ;
2831use itertools:: Itertools ;
29- use log:: Level :: { Info , Warn } ;
30- use log:: { info, log_enabled, warn } ;
32+ use log:: Level :: Info ;
33+ use log:: { info, log_enabled} ;
3134use sqllogictest:: {
3235 parse_file, strict_column_validator, AsyncDB , Condition , Normalizer , Record ,
3336 Validator ,
@@ -38,7 +41,6 @@ use crate::postgres_container::{
3841 initialize_postgres_container, terminate_postgres_container,
3942} ;
4043use std:: ffi:: OsStr ;
41- use std:: fs;
4244use std:: path:: { Path , PathBuf } ;
4345
4446#[ cfg( feature = "postgres" ) ]
@@ -56,14 +58,6 @@ pub fn main() -> Result<()> {
5658 . block_on ( run_tests ( ) )
5759}
5860
59- // Trailing whitespace from lines in SLT will typically be removed, but do not fail if it is not
60- // If particular test wants to cover trailing whitespace on a value,
61- // it should project additional non-whitespace column on the right.
62- #[ allow( clippy:: ptr_arg) ]
63- fn value_normalizer ( s : & String ) -> String {
64- s. trim_end ( ) . to_string ( )
65- }
66-
6761fn sqlite_value_validator (
6862 normalizer : Normalizer ,
6963 actual : & [ Vec < String > ] ,
@@ -93,54 +87,6 @@ fn sqlite_value_validator(
9387 normalized_actual == normalized_expected
9488}
9589
96- fn df_value_validator (
97- normalizer : Normalizer ,
98- actual : & [ Vec < String > ] ,
99- expected : & [ String ] ,
100- ) -> bool {
101- let normalized_expected = expected. iter ( ) . map ( normalizer) . collect :: < Vec < _ > > ( ) ;
102- let normalized_actual = actual
103- . iter ( )
104- . map ( |strs| strs. iter ( ) . join ( " " ) )
105- . map ( |str| str. trim_end ( ) . to_string ( ) )
106- . collect_vec ( ) ;
107-
108- if log_enabled ! ( Warn ) && normalized_actual != normalized_expected {
109- warn ! ( "df validation failed. actual vs expected:" ) ;
110- for i in 0 ..normalized_actual. len ( ) {
111- warn ! ( "[{i}] {}<eol>" , normalized_actual[ i] ) ;
112- warn ! (
113- "[{i}] {}<eol>" ,
114- if normalized_expected. len( ) >= i {
115- & normalized_expected[ i]
116- } else {
117- "No more results"
118- }
119- ) ;
120- }
121- }
122-
123- normalized_actual == normalized_expected
124- }
125-
126- /// Sets up an empty directory at test_files/scratch/<name>
127- /// creating it if needed and clearing any file contents if it exists
128- /// This allows tests for inserting to external tables or copy to
129- /// persist data to disk and have consistent state when running
130- /// a new test
131- fn setup_scratch_dir ( name : & Path ) -> Result < ( ) > {
132- // go from copy.slt --> copy
133- let file_stem = name. file_stem ( ) . expect ( "File should have a stem" ) ;
134- let path = PathBuf :: from ( "test_files" ) . join ( "scratch" ) . join ( file_stem) ;
135-
136- info ! ( "Creating scratch dir in {path:?}" ) ;
137- if path. exists ( ) {
138- fs:: remove_dir_all ( & path) ?;
139- }
140- fs:: create_dir_all ( & path) ?;
141- Ok ( ( ) )
142- }
143-
14490async fn run_tests ( ) -> Result < ( ) > {
14591 // Enable logging (e.g. set RUST_LOG=debug to see debug logs)
14692 env_logger:: init ( ) ;
@@ -573,33 +519,6 @@ fn read_test_files<'a>(
573519 Ok ( Box :: new ( paths. into_iter ( ) ) )
574520}
575521
576- fn read_dir_recursive < P : AsRef < Path > > ( path : P ) -> Result < Vec < PathBuf > > {
577- let mut dst = vec ! [ ] ;
578- read_dir_recursive_impl ( & mut dst, path. as_ref ( ) ) ?;
579- Ok ( dst)
580- }
581-
582- /// Append all paths recursively to dst
583- fn read_dir_recursive_impl ( dst : & mut Vec < PathBuf > , path : & Path ) -> Result < ( ) > {
584- let entries = fs:: read_dir ( path)
585- . map_err ( |e| exec_datafusion_err ! ( "Error reading directory {path:?}: {e}" ) ) ?;
586- for entry in entries {
587- let path = entry
588- . map_err ( |e| {
589- exec_datafusion_err ! ( "Error reading entry in directory {path:?}: {e}" )
590- } ) ?
591- . path ( ) ;
592-
593- if path. is_dir ( ) {
594- read_dir_recursive_impl ( dst, & path) ?;
595- } else {
596- dst. push ( path) ;
597- }
598- }
599-
600- Ok ( ( ) )
601- }
602-
603522/// Parsed command line options
604523///
605524/// This structure attempts to mimic the command line options of the built-in rust test runner
0 commit comments