@@ -892,7 +892,7 @@ impl RowConverter {
892892 // and therefore must be valid
893893 let result = unsafe { self . convert_raw ( & mut rows, validate_utf8) } ?;
894894
895- if cfg ! ( test ) {
895+ if cfg ! ( debug_assertions ) {
896896 for ( i, row) in rows. iter ( ) . enumerate ( ) {
897897 if !row. is_empty ( ) {
898898 return Err ( ArrowError :: InvalidArgumentError ( format ! (
@@ -1131,8 +1131,8 @@ impl Rows {
11311131 pub fn size ( & self ) -> usize {
11321132 // Size of fields is accounted for as part of RowConverter
11331133 std:: mem:: size_of :: < Self > ( )
1134- + self . buffer . len ( )
1135- + self . offsets . len ( ) * std:: mem:: size_of :: < usize > ( )
1134+ + self . buffer . capacity ( )
1135+ + self . offsets . capacity ( ) * std:: mem:: size_of :: < usize > ( )
11361136 }
11371137
11381138 /// Create a [BinaryArray] from the [Rows] data without reallocating the
@@ -1644,24 +1644,22 @@ fn encode_column(
16441644 }
16451645 }
16461646 DataType :: Binary => {
1647- variable:: encode ( data, offsets, as_generic_binary_array:: <i32 >( column) . iter ( ) , opts)
1647+ variable:: encode_generic_byte_array ( data, offsets, as_generic_binary_array:: <i32 >( column) , opts)
16481648 }
16491649 DataType :: BinaryView => {
16501650 variable:: encode( data, offsets, column. as_binary_view( ) . iter( ) , opts)
16511651 }
16521652 DataType :: LargeBinary => {
1653- variable:: encode ( data, offsets, as_generic_binary_array:: <i64 >( column) . iter ( ) , opts)
1653+ variable:: encode_generic_byte_array ( data, offsets, as_generic_binary_array:: <i64 >( column) , opts)
16541654 }
1655- DataType :: Utf8 => variable:: encode (
1655+ DataType :: Utf8 => variable:: encode_generic_byte_array (
16561656 data, offsets,
1657- column. as_string:: <i32 >( ) . iter ( ) . map ( |x| x . map ( |x| x . as_bytes ( ) ) ) ,
1657+ column. as_string:: <i32 >( ) ,
16581658 opts,
16591659 ) ,
1660- DataType :: LargeUtf8 => variable:: encode (
1660+ DataType :: LargeUtf8 => variable:: encode_generic_byte_array (
16611661 data, offsets,
1662- column. as_string:: <i64 >( )
1663- . iter( )
1664- . map( |x| x. map( |x| x. as_bytes( ) ) ) ,
1662+ column. as_string:: <i64 >( ) ,
16651663 opts,
16661664 ) ,
16671665 DataType :: Utf8View => variable:: encode(
@@ -4050,4 +4048,47 @@ mod tests {
40504048 // "a" < "z"
40514049 assert ! ( rows. row( 3 ) < rows. row( 1 ) ) ;
40524050 }
4051+
4052+ #[ test]
4053+ fn rows_size_should_count_for_capacity ( ) {
4054+ let row_converter = RowConverter :: new ( vec ! [ SortField :: new( DataType :: UInt8 ) ] ) . unwrap ( ) ;
4055+
4056+ let empty_rows_size_with_preallocate_rows_and_data = {
4057+ let rows = row_converter. empty_rows ( 1000 , 1000 ) ;
4058+
4059+ rows. size ( )
4060+ } ;
4061+ let empty_rows_size_with_preallocate_rows = {
4062+ let rows = row_converter. empty_rows ( 1000 , 0 ) ;
4063+
4064+ rows. size ( )
4065+ } ;
4066+ let empty_rows_size_with_preallocate_data = {
4067+ let rows = row_converter. empty_rows ( 0 , 1000 ) ;
4068+
4069+ rows. size ( )
4070+ } ;
4071+ let empty_rows_size_without_preallocate = {
4072+ let rows = row_converter. empty_rows ( 0 , 0 ) ;
4073+
4074+ rows. size ( )
4075+ } ;
4076+
4077+ assert ! (
4078+ empty_rows_size_with_preallocate_rows_and_data > empty_rows_size_with_preallocate_rows,
4079+ "{empty_rows_size_with_preallocate_rows_and_data} should be larger than {empty_rows_size_with_preallocate_rows}"
4080+ ) ;
4081+ assert ! (
4082+ empty_rows_size_with_preallocate_rows_and_data > empty_rows_size_with_preallocate_data,
4083+ "{empty_rows_size_with_preallocate_rows_and_data} should be larger than {empty_rows_size_with_preallocate_data}"
4084+ ) ;
4085+ assert ! (
4086+ empty_rows_size_with_preallocate_rows > empty_rows_size_without_preallocate,
4087+ "{empty_rows_size_with_preallocate_rows} should be larger than {empty_rows_size_without_preallocate}"
4088+ ) ;
4089+ assert ! (
4090+ empty_rows_size_with_preallocate_data > empty_rows_size_without_preallocate,
4091+ "{empty_rows_size_with_preallocate_data} should be larger than {empty_rows_size_without_preallocate}"
4092+ ) ;
4093+ }
40534094}
0 commit comments