Copilot commented on code in PR #55408:
URL: https://github.com/apache/arrow/pull/55408#discussion_r4586675880
##########
cpp/src/parquet/column_reader.cc:
##########
@@ -2128,9 +2130,7 @@ int64_t TypedRecordReader<DT, VS>::DelimitRecords(int64_t
num_records,
const int64_t stride =
std::min(levels_written() - levels_position_, num_records -
records_read);
const int64_t position_end = levels_position_ + stride;
- for (int64_t i = levels_position_; i < position_end; ++i) {
- records_read += rep_levels[i] == 0;
- }
+ records_read += CountLevels(rep_levels + levels_position_, stride, 0);
Review Comment:
These calls use `CountLevels` without the `internal::` qualifier, while
earlier changes in the same file use `internal::CountLevels`. If this code is
not inside `parquet::internal` scope, this will fail to compile or resolve to
an unintended symbol. Please qualify these calls consistently (e.g.,
`internal::CountLevels`), matching the other call sites in this file.
##########
cpp/src/parquet/column_reader.cc:
##########
@@ -2234,8 +2234,9 @@ void TypedRecordReader<DT,
VS>::ReadDenseForOptionalInBuffer(
// When reading dense we need to figure out number of values to read.
const int16_t* def_levels = this->def_levels();
- *values_to_read += std::count(def_levels + start_levels_position,
- def_levels + levels_position_,
this->max_def_level());
+ *values_to_read += CountLevels(def_levels + start_levels_position,
+ levels_position_ - start_levels_position,
+ this->max_def_level());
Review Comment:
These calls use `CountLevels` without the `internal::` qualifier, while
earlier changes in the same file use `internal::CountLevels`. If this code is
not inside `parquet::internal` scope, this will fail to compile or resolve to
an unintended symbol. Please qualify these calls consistently (e.g.,
`internal::CountLevels`), matching the other call sites in this file.
##########
cpp/src/parquet/column_reader.cc:
##########
@@ -2144,8 +2144,8 @@ int64_t TypedRecordReader<DT, VS>::DelimitRecords(int64_t
num_records,
}
}
// Scan definition levels to find number of physical values
- *values_seen = std::count(def_levels + level, def_levels + levels_position_,
- this->max_def_level());
+ *values_seen = CountLevels(def_levels + level, levels_position_ - level,
+ this->max_def_level());
Review Comment:
These calls use `CountLevels` without the `internal::` qualifier, while
earlier changes in the same file use `internal::CountLevels`. If this code is
not inside `parquet::internal` scope, this will fail to compile or resolve to
an unintended symbol. Please qualify these calls consistently (e.g.,
`internal::CountLevels`), matching the other call sites in this file.
##########
cpp/src/parquet/level_comparison.h:
##########
@@ -35,4 +37,56 @@ struct MinMax {
MinMax PARQUET_EXPORT FindMinMax(const int16_t* levels, int64_t num_levels);
+// Out-of-line fallback for inputs larger than uint16_t::max() so the common
+// single-chunk path stays a plain vectorizable loop.
+template <typename Predicate>
+ARROW_NOINLINE int64_t CountLevelsIfChunked(const int16_t* levels, int64_t
num_levels,
+ Predicate&& pred) {
+ constexpr int64_t kMaxCount = std::numeric_limits<uint16_t>::max();
+ int64_t total = 0;
+ while (num_levels > 0) {
+ const int64_t chunk_length = std::min(num_levels, kMaxCount);
+ uint16_t chunk_count = 0;
+ for (int64_t i = 0; i < chunk_length; ++i) {
+ chunk_count += pred(levels[i]) ? 1 : 0;
+ }
+ total += chunk_count;
+ levels += chunk_length;
+ num_levels -= chunk_length;
+ }
+ return total;
+}
+
+/// \brief Count the levels that satisfy `pred`.
+///
+/// Accumulates matches in a `uint16_t` so the compiler can vectorize the loop
+/// using 16-bit lanes without widening each comparison result to 64 bits.
+/// Inputs longer than `uint16_t::max()` are counted in chunks to avoid
overflow.
+template <typename Predicate>
+inline int64_t CountLevelsIf(const int16_t* levels, int64_t num_levels,
+ Predicate&& pred) {
+ constexpr int64_t kMaxCount = std::numeric_limits<uint16_t>::max();
+ if (num_levels > kMaxCount) {
+ return CountLevelsIfChunked(levels, num_levels,
std::forward<Predicate>(pred));
+ }
+ uint16_t count = 0;
+ for (int64_t i = 0; i < num_levels; ++i) {
+ count += pred(levels[i]) ? 1 : 0;
+ }
+ return count;
+}
Review Comment:
The PR description mentions introducing a `num_levels < 32` fast-path
because small inputs may not vectorize and could be slower otherwise, but the
code here doesn't implement that threshold. Please either (a) add the
documented small-input path, or (b) update the PR description to match the
actual implementation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]