| 1076 | /// Overload for GetSpaced for a single run in a RleDecoder |
| 1077 | template <typename Converter, typename BitRunReader, typename BitRun, typename value_type> |
| 1078 | auto RunGetSpaced(Converter* converter, typename Converter::out_type* out, |
| 1079 | rle_size_t batch_size, rle_size_t null_count, |
| 1080 | rle_size_t value_bit_width, BitRunReader* validity_reader, |
| 1081 | BitRun* validity_run, |
| 1082 | RleRunDecoder<value_type>* decoder) -> GetSpacedResult<rle_size_t> { |
| 1083 | ARROW_DCHECK_GT(batch_size, 0); |
| 1084 | // The equality case is handled in the main loop in GetSpaced |
| 1085 | ARROW_DCHECK_LT(null_count, batch_size); |
| 1086 | |
| 1087 | auto batch = BatchCounter::FromBatchSizeAndNulls(batch_size, null_count); |
| 1088 | |
| 1089 | const rle_size_t values_available = decoder->remaining(); |
| 1090 | ARROW_DCHECK_GT(values_available, 0); |
| 1091 | auto values_remaining_run = [&]() { |
| 1092 | auto out = values_available - batch.values_read(); |
| 1093 | ARROW_DCHECK_GE(out, 0); |
| 1094 | return out; |
| 1095 | }; |
| 1096 | |
| 1097 | // Consume as much as possible from the repeated run. |
| 1098 | // We only need to count the number of nulls and non-nulls because we can fill in the |
| 1099 | // same value for nulls and non-nulls. |
| 1100 | // This proves to be a big efficiency win. |
| 1101 | while (values_remaining_run() > 0 && !batch.is_done()) { |
| 1102 | ARROW_DCHECK_GE(validity_run->length, 0); |
| 1103 | ARROW_DCHECK_LT(validity_run->length, max_size_for_v<rle_size_t>); |
| 1104 | ARROW_DCHECK_LE(validity_run->length, batch.total_remaining()); |
| 1105 | const auto& validity_run_size = static_cast<rle_size_t>(validity_run->length); |
| 1106 | |
| 1107 | if (validity_run->set) { |
| 1108 | // We may end the current RLE run in the middle of the validity run |
| 1109 | auto update_size = std::min(validity_run_size, values_remaining_run()); |
| 1110 | batch.AccrueReadValues(update_size); |
| 1111 | validity_run->length -= update_size; |
| 1112 | } else { |
| 1113 | // We can consume all nulls here because it does not matter if we consume on this |
| 1114 | // RLE run, or an a next encoded run. The value filled does not matter. |
| 1115 | auto update_size = std::min(validity_run_size, batch.null_remaining()); |
| 1116 | batch.AccrueReadNulls(update_size); |
| 1117 | validity_run->length -= update_size; |
| 1118 | } |
| 1119 | |
| 1120 | if (ARROW_PREDICT_TRUE(validity_run->length == 0)) { |
| 1121 | *validity_run = validity_reader->NextRun(); |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | const value_type value = decoder->value(); |
| 1126 | if (ARROW_PREDICT_FALSE(!converter->InputIsValid(value))) { |
| 1127 | return {0, 0}; |
| 1128 | } |
| 1129 | converter->WriteRepeated(out, out + batch.total_read(), value); |
| 1130 | const auto actual_values_read = decoder->Advance(batch.values_read()); |
| 1131 | // We always cropped the number of values_read by the remaining values in the run. |
| 1132 | // What's more the RLE decoder should not encounter any errors. |
| 1133 | ARROW_DCHECK_EQ(actual_values_read, batch.values_read()); |
| 1134 | |
| 1135 | return {/* .values_read= */ batch.values_read(), /* .null_read= */ batch.null_read()}; |
no test coverage detected