18
18
use clap:: Parser ;
19
19
use datafusion_common:: instant:: Instant ;
20
20
use 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 } ;
22
22
use 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
+ } ;
24
27
use futures:: stream:: StreamExt ;
25
28
use indicatif:: {
26
29
HumanDuration , MultiProgress , ProgressBar , ProgressDrawTarget , ProgressStyle ,
27
30
} ;
28
31
use 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} ;
31
34
use sqllogictest:: {
32
35
parse_file, strict_column_validator, AsyncDB , Condition , Normalizer , Record ,
33
36
Validator ,
@@ -38,7 +41,6 @@ use crate::postgres_container::{
38
41
initialize_postgres_container, terminate_postgres_container,
39
42
} ;
40
43
use std:: ffi:: OsStr ;
41
- use std:: fs;
42
44
use std:: path:: { Path , PathBuf } ;
43
45
44
46
#[ cfg( feature = "postgres" ) ]
@@ -56,14 +58,6 @@ pub fn main() -> Result<()> {
56
58
. block_on ( run_tests ( ) )
57
59
}
58
60
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
-
67
61
fn sqlite_value_validator (
68
62
normalizer : Normalizer ,
69
63
actual : & [ Vec < String > ] ,
@@ -93,54 +87,6 @@ fn sqlite_value_validator(
93
87
normalized_actual == normalized_expected
94
88
}
95
89
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
-
144
90
async fn run_tests ( ) -> Result < ( ) > {
145
91
// Enable logging (e.g. set RUST_LOG=debug to see debug logs)
146
92
env_logger:: init ( ) ;
@@ -573,33 +519,6 @@ fn read_test_files<'a>(
573
519
Ok ( Box :: new ( paths. into_iter ( ) ) )
574
520
}
575
521
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
-
603
522
/// Parsed command line options
604
523
///
605
524
/// This structure attempts to mimic the command line options of the built-in rust test runner
0 commit comments