@@ -19,11 +19,10 @@ use parquet::file::properties::WriterProperties;
1919use tokio:: task:: JoinSet ;
2020use tracing:: * ;
2121
22- use crate :: crate_version;
23-
2422use crate :: errors:: { DeltaResult , DeltaTableError } ;
2523use crate :: kernel:: { Add , PartitionsExt } ;
2624use crate :: logstore:: ObjectStoreRef ;
25+ use crate :: parquet_utils:: default_writer_properties;
2726use crate :: writer:: record_batch:: { PartitionResult , divide_by_partition_values} ;
2827use crate :: writer:: stats:: create_add;
2928use crate :: writer:: utils:: {
@@ -88,17 +87,6 @@ fn sort_completed_writes_by_path<T>(results: &mut [(Path, usize, T)]) {
8887 results. sort_unstable_by ( |a, b| a. 0 . cmp ( & b. 0 ) ) ;
8988}
9089
91- fn default_writer_properties ( include_created_by : bool ) -> WriterProperties {
92- let builder = WriterProperties :: builder ( ) . set_compression ( Compression :: SNAPPY ) ;
93- if include_created_by {
94- builder
95- . set_created_by ( format ! ( "delta-rs version {}" , crate_version( ) ) )
96- . build ( )
97- } else {
98- builder. build ( )
99- }
100- }
101-
10290#[ derive( thiserror:: Error , Debug ) ]
10391enum WriteError {
10492 #[ error( "Unexpected Arrow schema: got: {schema}, expected: {expected_schema}" ) ]
@@ -169,7 +157,7 @@ impl WriterConfig {
169157 stats_columns : Option < Vec < String > > ,
170158 ) -> Self {
171159 let writer_properties =
172- writer_properties. unwrap_or_else ( || default_writer_properties ( false ) ) ;
160+ writer_properties. unwrap_or_else ( || default_writer_properties ( Compression :: SNAPPY ) ) ;
173161 let write_batch_size = write_batch_size. unwrap_or ( DEFAULT_WRITE_BATCH_SIZE ) ;
174162
175163 Self {
@@ -335,7 +323,7 @@ impl PartitionWriterConfig {
335323 let part_path = partition_values. hive_partition_path ( ) ;
336324 let prefix = Path :: parse ( part_path) ?;
337325 let writer_properties =
338- writer_properties. unwrap_or_else ( || default_writer_properties ( true ) ) ;
326+ writer_properties. unwrap_or_else ( || default_writer_properties ( Compression :: SNAPPY ) ) ;
339327 let write_batch_size = write_batch_size. unwrap_or ( DEFAULT_WRITE_BATCH_SIZE ) ;
340328
341329 Ok ( Self {
@@ -550,11 +538,13 @@ impl PartitionWriter {
550538mod tests {
551539 use super :: * ;
552540 use crate :: DeltaTableBuilder ;
541+ use crate :: crate_version;
553542 use crate :: logstore:: tests:: flatten_list_stream as list;
554543 use crate :: table:: config:: DEFAULT_NUM_INDEX_COLS ;
555544 use crate :: writer:: test_utils:: * ;
556545 use arrow:: array:: { Int32Array , StringArray } ;
557546 use arrow:: datatypes:: { DataType , Field , Schema as ArrowSchema } ;
547+ use parquet:: schema:: types:: ColumnPath ;
558548 use std:: sync:: Arc ;
559549
560550 fn get_delta_writer (
@@ -601,6 +591,59 @@ mod tests {
601591 . unwrap ( )
602592 }
603593
594+ fn assert_default_created_by ( writer_properties : & WriterProperties ) {
595+ assert_eq ! (
596+ writer_properties. created_by( ) ,
597+ format!( "delta-rs version {}" , crate_version( ) )
598+ ) ;
599+ }
600+
601+ #[ test]
602+ fn test_writer_config_defaults_include_delta_rs_created_by ( ) {
603+ let schema = Arc :: new ( ArrowSchema :: new ( vec ! [ Field :: new(
604+ "id" ,
605+ DataType :: Int32 ,
606+ true ,
607+ ) ] ) ) ;
608+ let config = WriterConfig :: new (
609+ schema,
610+ vec ! [ ] ,
611+ None ,
612+ None ,
613+ None ,
614+ DataSkippingNumIndexedCols :: NumColumns ( DEFAULT_NUM_INDEX_COLS ) ,
615+ None ,
616+ ) ;
617+
618+ assert_default_created_by ( & config. writer_properties ) ;
619+ assert_eq ! (
620+ config
621+ . writer_properties
622+ . compression( & ColumnPath :: from( "id" ) ) ,
623+ Compression :: SNAPPY
624+ ) ;
625+ }
626+
627+ #[ test]
628+ fn test_partition_writer_config_defaults_include_delta_rs_created_by ( ) {
629+ let schema = Arc :: new ( ArrowSchema :: new ( vec ! [ Field :: new(
630+ "id" ,
631+ DataType :: Int32 ,
632+ true ,
633+ ) ] ) ) ;
634+ let config =
635+ PartitionWriterConfig :: try_new ( schema, IndexMap :: new ( ) , None , None , None , None )
636+ . unwrap ( ) ;
637+
638+ assert_default_created_by ( & config. writer_properties ) ;
639+ assert_eq ! (
640+ config
641+ . writer_properties
642+ . compression( & ColumnPath :: from( "id" ) ) ,
643+ Compression :: SNAPPY
644+ ) ;
645+ }
646+
604647 #[ tokio:: test]
605648 async fn test_write_partition ( ) {
606649 let log_store = DeltaTableBuilder :: from_url ( url:: Url :: parse ( "memory:///" ) . unwrap ( ) )
0 commit comments