@@ -763,38 +763,41 @@ class NullValueReducer {
763
763
return context_row.slice_and_key ().slice_ .row_range .first ;
764
764
}
765
765
766
- void backfill_all_zero_validity_bitmaps_up_to (std::optional< size_t > up_to_block_offset) {
766
+ void backfill_all_zero_validity_bitmaps_up_to (size_t up_to_block_offset) {
767
767
// Fills up all validity bitmaps with zeros from `column_block_idx_` until reaching `up_to_block_offset`.
768
- // If `up_to_block_offset` is `std::nullopt` then fills up until the end of the column.
769
768
const auto & block_offsets = column_.block_offsets ();
770
- util::check (! up_to_block_offset. has_value () || up_to_block_offset. value () <= block_offsets.back (), " up_to_block_offset outside of range" );
771
- for (; column_block_idx_ < block_offsets.size () - 1 ; ++column_block_idx_) {
772
- if (up_to_block_offset. has_value () && block_offsets.at (column_block_idx_) >= up_to_block_offset. value () ) {
769
+ util::check (up_to_block_offset <= block_offsets.back (), " up_to_block_offset {} outside of range {} " , up_to_block_offset, block_offsets. back () );
770
+ for (; column_block_idx_ < block_offsets.size () - 1 && block_offsets. at (column_block_idx_) < up_to_block_offset ; ++column_block_idx_) {
771
+ if (block_offsets.at (column_block_idx_) >= up_to_block_offset) {
773
772
break ;
774
773
}
775
774
auto rows = (block_offsets.at (column_block_idx_ + 1 ) - block_offsets.at (column_block_idx_)) / type_bytes_;
776
775
create_dense_bitmap_all_zeros (block_offsets.at (column_block_idx_), rows, column_, AllocationType::DETACHABLE);
777
776
}
778
777
}
779
778
780
- void reduce (PipelineContextRow &context_row){
781
- auto &slice_and_key = context_row.slice_and_key ();
782
- auto sz_to_advance = slice_and_key.slice_ .row_range .diff ();
783
- auto current_pos = context_row.slice_and_key ().slice_ .row_range .first ;
784
- if (current_pos != pos_) {
785
- const auto num_rows = current_pos - pos_;
779
+ void backfill_up_to_frame_offset (size_t up_to) {
780
+ if (pos_ != up_to) {
781
+ const auto num_rows = up_to - pos_;
786
782
const auto start_row = pos_ - frame_.offset ();
787
- const auto end_row = current_pos - frame_.offset ();
783
+ const auto end_row = up_to - frame_.offset ();
788
784
if (const std::shared_ptr<TypeHandler>& handler = get_type_handler (output_format_, column_.type ()); handler) {
789
785
handler->default_initialize (column_.buffer (), start_row * handler->type_size (), num_rows * handler->type_size (), shared_data_, handler_data_);
790
- } else if (output_format_ != OutputFormat::ARROW) {
786
+ } else if (output_format_ != OutputFormat::ARROW || default_value_. has_value () ) {
791
787
// Arrow does not care what values are in the main buffer where the validity bitmap is zero
792
788
column_.default_initialize_rows (start_row, num_rows, false , default_value_);
793
789
}
794
- if (output_format_ == OutputFormat::ARROW) {
790
+ if (output_format_ == OutputFormat::ARROW && !default_value_. has_value () ) {
795
791
backfill_all_zero_validity_bitmaps_up_to (end_row * type_bytes_);
796
792
}
797
793
}
794
+ }
795
+
796
+ void reduce (PipelineContextRow &context_row){
797
+ auto &slice_and_key = context_row.slice_and_key ();
798
+ auto sz_to_advance = slice_and_key.slice_ .row_range .diff ();
799
+ auto current_pos = context_row.slice_and_key ().slice_ .row_range .first ;
800
+ backfill_up_to_frame_offset (current_pos);
798
801
pos_ = current_pos + sz_to_advance;
799
802
if (output_format_ == OutputFormat::ARROW) {
800
803
++column_block_idx_;
@@ -804,20 +807,8 @@ class NullValueReducer {
804
807
void finalize () {
805
808
const auto total_rows = frame_.row_count ();
806
809
const auto end = frame_.offset () + total_rows;
807
- if (pos_ != end) {
808
- util::check (pos_ < end, " Overflow in finalize {} > {}" , pos_, end);
809
- const auto num_rows = end - pos_;
810
- const auto start_row = pos_ - frame_.offset ();
811
- if (const std::shared_ptr<TypeHandler>& handler = get_type_handler (output_format_, column_.type ()); handler) {
812
- handler->default_initialize (column_.buffer (), start_row * handler->type_size (), num_rows * handler->type_size (), shared_data_, handler_data_);
813
- } else if (output_format_ != OutputFormat::ARROW) {
814
- // Arrow does not care what values are in the main buffer where the validity bitmap is zero
815
- column_.default_initialize_rows (start_row, num_rows, false , default_value_);
816
- }
817
- if (output_format_ == OutputFormat::ARROW) {
818
- backfill_all_zero_validity_bitmaps_up_to (std::nullopt );
819
- }
820
- }
810
+ util::check (pos_ <= end, " Overflow in finalize {} > {}" , pos_, end);
811
+ backfill_up_to_frame_offset (end);
821
812
}
822
813
};
823
814
0 commit comments