| 862 | } |
| 863 | |
| 864 | Result<Datum> Finalize() override { |
| 865 | // We initialize the null bitmap with first_is_nulls and last_is_nulls |
| 866 | // then update it depending on has_values |
| 867 | ARROW_ASSIGN_OR_RAISE(auto first_null_bitmap, first_is_nulls_.Finish()); |
| 868 | ARROW_ASSIGN_OR_RAISE(auto last_null_bitmap, last_is_nulls_.Finish()); |
| 869 | ARROW_ASSIGN_OR_RAISE(auto has_values, has_values_.Finish()); |
| 870 | |
| 871 | auto raw_first_null_bitmap = first_null_bitmap->mutable_data(); |
| 872 | auto raw_last_null_bitmap = last_null_bitmap->mutable_data(); |
| 873 | auto raw_has_values = has_values->data(); |
| 874 | |
| 875 | if (options_.skip_nulls) { |
| 876 | for (int i = 0; i < num_groups_; i++) { |
| 877 | const bool has_value = bit_util::GetBit(has_values->data(), i); |
| 878 | bit_util::SetBitTo(raw_first_null_bitmap, i, has_value); |
| 879 | bit_util::SetBitTo(raw_last_null_bitmap, i, has_value); |
| 880 | } |
| 881 | } else { |
| 882 | for (int i = 0; i < num_groups_; i++) { |
| 883 | // If first is null, we set the mask to false to output null |
| 884 | if (bit_util::GetBit(raw_first_null_bitmap, i)) { |
| 885 | bit_util::SetBitTo(raw_first_null_bitmap, i, false); |
| 886 | } else { |
| 887 | bit_util::SetBitTo(raw_first_null_bitmap, i, |
| 888 | bit_util::GetBit(raw_has_values, i)); |
| 889 | } |
| 890 | } |
| 891 | for (int i = 0; i < num_groups_; i++) { |
| 892 | // If last is null, we set the mask to false to output null |
| 893 | if (bit_util::GetBit(raw_last_null_bitmap, i)) { |
| 894 | bit_util::SetBitTo(raw_last_null_bitmap, i, false); |
| 895 | } else { |
| 896 | bit_util::SetBitTo(raw_last_null_bitmap, i, |
| 897 | bit_util::GetBit(raw_has_values, i)); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | auto firsts = |
| 903 | ArrayData::Make(type_, num_groups_, {std::move(first_null_bitmap), nullptr}); |
| 904 | auto lasts = |
| 905 | ArrayData::Make(type_, num_groups_, {std::move(last_null_bitmap), nullptr}); |
| 906 | ARROW_ASSIGN_OR_RAISE(firsts->buffers[1], firsts_.Finish()); |
| 907 | ARROW_ASSIGN_OR_RAISE(lasts->buffers[1], lasts_.Finish()); |
| 908 | |
| 909 | return ArrayData::Make(out_type(), num_groups_, {nullptr}, |
| 910 | {std::move(firsts), std::move(lasts)}); |
| 911 | } |
| 912 | |
| 913 | std::shared_ptr<DataType> out_type() const override { |
| 914 | return struct_({field("first", type_), field("last", type_)}); |
nothing calls this directly
no test coverage detected