@@ -101,43 +101,15 @@ impl Oracle for TlpHavingOracle {
101101mod tests {
102102 use super :: * ;
103103 use crate :: common:: { FuzzerDataType , LogicalColumn , LogicalTable , init_available_data_types} ;
104- use datafusion:: arrow:: array:: { Array , Int64Array } ;
105- use datafusion:: arrow:: datatypes:: { DataType , Field , Schema } ;
106- use datafusion:: arrow:: record_batch:: RecordBatch ;
107- use datafusion:: prelude:: SessionContext ;
108-
109- fn make_query_context ( label : & str ) -> Arc < QueryContext > {
110- Arc :: new ( QueryContext :: new (
111- format ! ( "SELECT {}" , label) ,
112- Arc :: new ( SessionContext :: new ( ) ) ,
113- ) )
114- }
115-
116- fn make_success_result ( label : & str , values : Vec < i64 > ) -> QueryExecutionResult {
117- let schema = Arc :: new ( Schema :: new ( vec ! [ Field :: new( "g" , DataType :: Int64 , false ) ] ) ) ;
118- let array = Arc :: new ( Int64Array :: from ( values) ) as Arc < dyn Array > ;
119- let batch = RecordBatch :: try_new ( schema, vec ! [ array] ) . unwrap ( ) ;
120-
121- QueryExecutionResult {
122- query_context : make_query_context ( label) ,
123- result : Ok ( vec ! [ batch] ) ,
124- }
125- }
126-
127- fn make_error_result ( label : & str ) -> QueryExecutionResult {
128- QueryExecutionResult {
129- query_context : make_query_context ( label) ,
130- result : Err ( fuzzer_err ( "expected execution error in test" ) ) ,
131- }
132- }
104+ use crate :: oracle:: test_helpers;
133105
134106 #[ tokio:: test]
135107 async fn tlp_having_validate_passes_for_matching_values ( ) {
136108 let oracle =
137109 TlpHavingOracle :: new ( 1 , Arc :: new ( crate :: fuzz_context:: GlobalContext :: default ( ) ) ) ;
138110 let results = vec ! [
139- make_success_result( "all" , vec![ 1 , 2 , 3 ] ) ,
140- make_success_result( "partition_union" , vec![ 1 , 2 , 3 ] ) ,
111+ test_helpers :: make_success_result( "all" , "g ", vec![ 1 , 2 , 3 ] ) ,
112+ test_helpers :: make_success_result( "partition_union" , "g ", vec![ 1 , 2 , 3 ] ) ,
141113 ] ;
142114
143115 assert ! ( oracle. validate_consistency( & results) . await . is_ok( ) ) ;
@@ -148,8 +120,8 @@ mod tests {
148120 let oracle =
149121 TlpHavingOracle :: new ( 1 , Arc :: new ( crate :: fuzz_context:: GlobalContext :: default ( ) ) ) ;
150122 let results = vec ! [
151- make_success_result( "all" , vec![ 1 , 2 ] ) ,
152- make_success_result( "partition_union" , vec![ 1 , 2 , 2 ] ) ,
123+ test_helpers :: make_success_result( "all" , "g ", vec![ 1 , 2 ] ) ,
124+ test_helpers :: make_success_result( "partition_union" , "g ", vec![ 1 , 2 , 2 ] ) ,
153125 ] ;
154126
155127 let err = oracle. validate_consistency ( & results) . await . unwrap_err ( ) ;
@@ -164,44 +136,27 @@ mod tests {
164136 let oracle =
165137 TlpHavingOracle :: new ( 1 , Arc :: new ( crate :: fuzz_context:: GlobalContext :: default ( ) ) ) ;
166138 let results = vec ! [
167- make_success_result( "all" , vec![ 1 , 2 ] ) ,
168- make_error_result( "partition_union" ) ,
139+ test_helpers :: make_success_result( "all" , "g ", vec![ 1 , 2 ] ) ,
140+ test_helpers :: make_error_result( "partition_union" ) ,
169141 ] ;
170142
171143 assert ! ( oracle. validate_consistency( & results) . await . is_ok( ) ) ;
172144 }
173145
174146 #[ tokio:: test]
175147 async fn tlp_having_validate_fails_for_schema_mismatch ( ) {
176- let one_col_schema = Arc :: new ( Schema :: new ( vec ! [ Field :: new( "c1" , DataType :: Int64 , false ) ] ) ) ;
177- let one_col_batch = RecordBatch :: try_new (
178- one_col_schema,
179- vec ! [ Arc :: new( Int64Array :: from( vec![ 1 , 2 ] ) ) as Arc <dyn Array >] ,
180- )
181- . unwrap ( ) ;
182-
183- let two_col_schema = Arc :: new ( Schema :: new ( vec ! [
184- Field :: new( "c1" , DataType :: Int64 , false ) ,
185- Field :: new( "c2" , DataType :: Int64 , false ) ,
186- ] ) ) ;
187- let two_col_batch = RecordBatch :: try_new (
188- two_col_schema,
189- vec ! [
190- Arc :: new( Int64Array :: from( vec![ 1 ] ) ) as Arc <dyn Array >,
191- Arc :: new( Int64Array :: from( vec![ 9 ] ) ) as Arc <dyn Array >,
192- ] ,
193- )
194- . unwrap ( ) ;
148+ let one_col_batch = test_helpers:: make_one_col_batch ( vec ! [ 1 , 2 ] ) ;
149+ let two_col_batch = test_helpers:: make_two_col_batch ( vec ! [ 1 ] , vec ! [ 9 ] ) ;
195150
196151 let oracle =
197152 TlpHavingOracle :: new ( 1 , Arc :: new ( crate :: fuzz_context:: GlobalContext :: default ( ) ) ) ;
198153 let results = vec ! [
199154 QueryExecutionResult {
200- query_context: make_query_context( "all" ) ,
155+ query_context: test_helpers :: make_query_context( "all" ) ,
201156 result: Ok ( vec![ one_col_batch. clone( ) ] ) ,
202157 } ,
203158 QueryExecutionResult {
204- query_context: make_query_context( "partition_union" ) ,
159+ query_context: test_helpers :: make_query_context( "partition_union" ) ,
205160 result: Ok ( vec![ two_col_batch] ) ,
206161 } ,
207162 ] ;
0 commit comments