MCPcopy Create free account
hub / github.com/apache/arrow / WriteEncodedRuns

Function WriteEncodedRuns

cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:49–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48template <typename RunEndType, typename ValueType, bool has_validity_buffer>
49class RunEndEncodingLoop {
50 public:
51 using RunEndCType = typename RunEndType::c_type;
52
53 private:
54 using ReadWriteValue = ree_util::ReadWriteValue<ValueType, has_validity_buffer>;
55 using ValueRepr = typename ReadWriteValue::ValueRepr;
56
57 private:
58 const int64_t input_length_;
59 const int64_t input_offset_;
60 ReadWriteValue read_write_value_;
61 // Needed only by WriteEncodedRuns()
62 RunEndCType* output_run_ends_;
63
64 public:
65 explicit RunEndEncodingLoop(const ArraySpan& input_array,
66 ArrayData* output_values_array_data,
67 RunEndCType* output_run_ends)
68 : input_length_(input_array.length),
69 input_offset_(input_array.offset),
70 read_write_value_(input_array, output_values_array_data),
71 output_run_ends_(output_run_ends) {
72 DCHECK_GT(input_array.length, 0);
73 }
74
75 /// \brief Give a pass over the input data and count the number of runs
76 ///
77 /// \return a tuple with the number of non-null run values, the total number of runs,
78 /// and the data buffer size for string and binary types
79 ARROW_NOINLINE std::tuple<int64_t, int64_t, int64_t> CountNumberOfRuns() const {
80 int64_t read_offset = input_offset_;
81 ValueRepr current_run;
82 bool current_run_valid = read_write_value_.ReadValue(&current_run, read_offset);
83 read_offset += 1;
84 int64_t num_valid_runs = current_run_valid ? 1 : 0;
85 int64_t num_output_runs = 1;
86 int64_t data_buffer_size = 0;
87 if constexpr (is_base_binary_like(ValueType::type_id)) {
88 data_buffer_size = current_run_valid ? current_run.size() : 0;
89 }
90 for (; read_offset < input_offset_ + input_length_; read_offset += 1) {
91 ValueRepr value;
92 const bool valid = read_write_value_.ReadValue(&value, read_offset);
93
94 const bool open_new_run =
95 valid != current_run_valid || !read_write_value_.Compare(value, current_run);
96 if (open_new_run) {
97 // Open the new run
98 current_run = value;
99 current_run_valid = valid;
100 // Count the new run
101 num_output_runs += 1;
102 num_valid_runs += valid ? 1 : 0;
103 if constexpr (is_base_binary_like(ValueType::type_id)) {
104 data_buffer_size += valid ? current_run.size() : 0;
105 }
106 }

Callers

nothing calls this directly

Calls 3

ReadValueMethod · 0.45
CompareMethod · 0.45
WriteValueMethod · 0.45

Tested by

no test coverage detected