@@ -91,6 +91,11 @@ pub struct CsvReadOptions<'a> {
9191 pub file_sort_order : Vec < Vec < SortExpr > > ,
9292 /// Optional regex to match null values
9393 pub null_regex : Option < String > ,
94+ /// Whether to allow truncated rows when parsing.
95+ /// By default this is set to false and will error if the CSV rows have different lengths.
96+ /// When set to true then it will allow records with less than the expected number of columns and fill the missing columns with nulls.
97+ /// If the record’s schema is not nullable, then it will still return an error.
98+ pub truncated_rows : bool ,
9499}
95100
96101impl Default for CsvReadOptions < ' _ > {
@@ -117,6 +122,7 @@ impl<'a> CsvReadOptions<'a> {
117122 file_sort_order : vec ! [ ] ,
118123 comment : None ,
119124 null_regex : None ,
125+ truncated_rows : false ,
120126 }
121127 }
122128
@@ -223,6 +229,15 @@ impl<'a> CsvReadOptions<'a> {
223229 self . null_regex = null_regex;
224230 self
225231 }
232+
233+ /// Configure whether to allow truncated rows when parsing.
234+ /// By default this is set to false and will error if the CSV rows have different lengths
235+ /// When set to true then it will allow records with less than the expected number of columns and fill the missing columns with nulls.
236+ /// If the record’s schema is not nullable, then it will still return an error.
237+ pub fn truncated_rows ( mut self , truncated_rows : bool ) -> Self {
238+ self . truncated_rows = truncated_rows;
239+ self
240+ }
226241}
227242
228243/// Options that control the reading of Parquet files.
@@ -546,7 +561,8 @@ impl ReadOptions<'_> for CsvReadOptions<'_> {
546561 . with_newlines_in_values ( self . newlines_in_values )
547562 . with_schema_infer_max_rec ( self . schema_infer_max_records )
548563 . with_file_compression_type ( self . file_compression_type . to_owned ( ) )
549- . with_null_regex ( self . null_regex . clone ( ) ) ;
564+ . with_null_regex ( self . null_regex . clone ( ) )
565+ . with_truncated_rows ( self . truncated_rows ) ;
550566
551567 ListingOptions :: new ( Arc :: new ( file_format) )
552568 . with_file_extension ( self . file_extension )
0 commit comments