@@ -35,8 +35,8 @@ mod tests {
35
35
use datafusion_common:: cast:: as_string_array;
36
36
use datafusion_common:: internal_err;
37
37
use datafusion_common:: stats:: Precision ;
38
- use datafusion_common:: test_util:: arrow_test_data;
39
- use datafusion_common:: { assert_batches_eq , Result } ;
38
+ use datafusion_common:: test_util:: { arrow_test_data, batches_to_string } ;
39
+ use datafusion_common:: Result ;
40
40
use datafusion_datasource:: decoder:: {
41
41
BatchDeserializer , DecoderDeserializer , DeserializerOutput ,
42
42
} ;
@@ -57,6 +57,7 @@ mod tests {
57
57
use chrono:: DateTime ;
58
58
use futures:: stream:: BoxStream ;
59
59
use futures:: StreamExt ;
60
+ use insta:: assert_snapshot;
60
61
use object_store:: local:: LocalFileSystem ;
61
62
use object_store:: path:: Path ;
62
63
use object_store:: {
@@ -557,15 +558,17 @@ mod tests {
557
558
. select_columns ( & [ "c2" , "c3" ] ) ?
558
559
. collect ( )
559
560
. await ?;
560
- #[ rustfmt:: skip]
561
- let expected = [ "+----+------+" ,
562
- "| c2 | c3 |" ,
563
- "+----+------+" ,
564
- "| 5 | 36 |" ,
565
- "| 5 | -31 |" ,
566
- "| 5 | -101 |" ,
567
- "+----+------+" ] ;
568
- assert_batches_eq ! ( expected, & record_batch) ;
561
+
562
+ assert_snapshot ! ( batches_to_string( & record_batch) , @r###"
563
+ +----+------+
564
+ | c2 | c3 |
565
+ +----+------+
566
+ | 5 | 36 |
567
+ | 5 | -31 |
568
+ | 5 | -101 |
569
+ +----+------+
570
+ "### ) ;
571
+
569
572
Ok ( ( ) )
570
573
}
571
574
@@ -671,13 +674,15 @@ mod tests {
671
674
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
672
675
let actual_partitions = count_query_csv_partitions ( & ctx, query) . await ?;
673
676
674
- #[ rustfmt:: skip]
675
- let expected = [ "+--------------+" ,
676
- "| sum(aggr.c2) |" ,
677
- "+--------------+" ,
678
- "| 285 |" ,
679
- "+--------------+" ] ;
680
- assert_batches_eq ! ( expected, & query_result) ;
677
+ insta:: allow_duplicates! { assert_snapshot!( batches_to_string( & query_result) , @r###"
678
+ +--------------+
679
+ | sum(aggr.c2) |
680
+ +--------------+
681
+ | 285 |
682
+ +--------------+
683
+ "### ) ;
684
+ }
685
+
681
686
assert_eq ! ( n_partitions, actual_partitions) ;
682
687
683
688
Ok ( ( ) )
@@ -708,13 +713,15 @@ mod tests {
708
713
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
709
714
let actual_partitions = count_query_csv_partitions ( & ctx, query) . await ?;
710
715
711
- #[ rustfmt:: skip]
712
- let expected = [ "+--------------+" ,
713
- "| sum(aggr.c3) |" ,
714
- "+--------------+" ,
715
- "| 781 |" ,
716
- "+--------------+" ] ;
717
- assert_batches_eq ! ( expected, & query_result) ;
716
+ insta:: allow_duplicates! { assert_snapshot!( batches_to_string( & query_result) , @r###"
717
+ +--------------+
718
+ | sum(aggr.c3) |
719
+ +--------------+
720
+ | 781 |
721
+ +--------------+
722
+ "### ) ;
723
+ }
724
+
718
725
assert_eq ! ( 1 , actual_partitions) ; // Compressed csv won't be scanned in parallel
719
726
720
727
Ok ( ( ) )
@@ -743,13 +750,15 @@ mod tests {
743
750
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
744
751
let actual_partitions = count_query_csv_partitions ( & ctx, query) . await ?;
745
752
746
- #[ rustfmt:: skip]
747
- let expected = [ "+--------------+" ,
748
- "| sum(aggr.c3) |" ,
749
- "+--------------+" ,
750
- "| 781 |" ,
751
- "+--------------+" ] ;
752
- assert_batches_eq ! ( expected, & query_result) ;
753
+ insta:: allow_duplicates! { assert_snapshot!( batches_to_string( & query_result) , @r###"
754
+ +--------------+
755
+ | sum(aggr.c3) |
756
+ +--------------+
757
+ | 781 |
758
+ +--------------+
759
+ "### ) ;
760
+ }
761
+
753
762
assert_eq ! ( 1 , actual_partitions) ; // csv won't be scanned in parallel when newlines_in_values is set
754
763
755
764
Ok ( ( ) )
@@ -772,10 +781,10 @@ mod tests {
772
781
let query = "select * from empty where random() > 0.5;" ;
773
782
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
774
783
775
- # [ rustfmt :: skip ]
776
- let expected = [ "++" ,
777
- "++" ] ;
778
- assert_batches_eq ! ( expected , & query_result ) ;
784
+ assert_snapshot ! ( batches_to_string ( & query_result ) , @ r###"
785
+ ++
786
+ ++
787
+ "### ) ;
779
788
780
789
Ok ( ( ) )
781
790
}
@@ -797,10 +806,10 @@ mod tests {
797
806
let query = "select * from empty where random() > 0.5;" ;
798
807
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
799
808
800
- # [ rustfmt :: skip ]
801
- let expected = [ "++" ,
802
- "++" ] ;
803
- assert_batches_eq ! ( expected , & query_result ) ;
809
+ assert_snapshot ! ( batches_to_string ( & query_result ) , @ r###"
810
+ ++
811
+ ++
812
+ "### ) ;
804
813
805
814
Ok ( ( ) )
806
815
}
@@ -839,10 +848,10 @@ mod tests {
839
848
let query = "select * from empty where random() > 0.5;" ;
840
849
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
841
850
842
- # [ rustfmt :: skip ]
843
- let expected = [ "++" ,
844
- "++" ] ;
845
- assert_batches_eq ! ( expected , & query_result ) ;
851
+ assert_snapshot ! ( batches_to_string ( & query_result ) , @ r###"
852
+ ++
853
+ ++
854
+ "### ) ;
846
855
847
856
Ok ( ( ) )
848
857
}
@@ -891,13 +900,14 @@ mod tests {
891
900
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
892
901
let actual_partitions = count_query_csv_partitions ( & ctx, query) . await ?;
893
902
894
- #[ rustfmt:: skip]
895
- let expected = [ "+---------------------+" ,
896
- "| sum(empty.column_1) |" ,
897
- "+---------------------+" ,
898
- "| 10 |" ,
899
- "+---------------------+" ] ;
900
- assert_batches_eq ! ( expected, & query_result) ;
903
+ insta:: allow_duplicates! { assert_snapshot!( batches_to_string( & query_result) , @r###"
904
+ +---------------------+
905
+ | sum(empty.column_1) |
906
+ +---------------------+
907
+ | 10 |
908
+ +---------------------+
909
+ "### ) ; }
910
+
901
911
assert_eq ! ( n_partitions, actual_partitions) ; // Won't get partitioned if all files are empty
902
912
903
913
Ok ( ( ) )
@@ -930,21 +940,23 @@ mod tests {
930
940
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
931
941
let actual_partitions = count_query_csv_partitions ( & ctx, query) . await ?;
932
942
933
- #[ rustfmt:: skip]
934
- let expected = [ "+-----------------------+" ,
935
- "| sum(one_col.column_1) |" ,
936
- "+-----------------------+" ,
937
- "| 50 |" ,
938
- "+-----------------------+" ] ;
939
-
940
943
let file_size = std:: fs:: metadata ( "tests/data/one_col.csv" ) ?. len ( ) as usize ;
941
944
// A 20-Byte file at most get partitioned into 20 chunks
942
945
let expected_partitions = if n_partitions <= file_size {
943
946
n_partitions
944
947
} else {
945
948
file_size
946
949
} ;
947
- assert_batches_eq ! ( expected, & query_result) ;
950
+
951
+ insta:: allow_duplicates! { assert_snapshot!( batches_to_string( & query_result) , @r###"
952
+ +-----------------------+
953
+ | sum(one_col.column_1) |
954
+ +-----------------------+
955
+ | 50 |
956
+ +-----------------------+
957
+ "### ) ;
958
+ }
959
+
948
960
assert_eq ! ( expected_partitions, actual_partitions) ;
949
961
950
962
Ok ( ( ) )
@@ -975,13 +987,14 @@ mod tests {
975
987
let query_result = ctx. sql ( query) . await ?. collect ( ) . await ?;
976
988
let actual_partitions = count_query_csv_partitions ( & ctx, query) . await ?;
977
989
978
- #[ rustfmt:: skip]
979
- let expected = [ "+---------------+" ,
980
- "| sum_of_5_cols |" ,
981
- "+---------------+" ,
982
- "| 15 |" ,
983
- "+---------------+" ] ;
984
- assert_batches_eq ! ( expected, & query_result) ;
990
+ insta:: allow_duplicates! { assert_snapshot!( batches_to_string( & query_result) , @r###"
991
+ +---------------+
992
+ | sum_of_5_cols |
993
+ +---------------+
994
+ | 15 |
995
+ +---------------+
996
+ "### ) ; }
997
+
985
998
assert_eq ! ( n_partitions, actual_partitions) ;
986
999
987
1000
Ok ( ( ) )
0 commit comments