AntoinePrv commented on code in PR #50629:
URL: https://github.com/apache/arrow/pull/50629#discussion_r3727336463
##########
cpp/src/parquet/column_reader.cc:
##########
@@ -94,134 +89,196 @@ inline void CheckNumberDecoded(int64_t number_decoded,
int64_t expected) {
constexpr std::string_view kErrorRepDefLevelNotMatchesNumValues =
"Number of decoded rep / def levels do not match num_values in page
header";
-} // namespace
+/// Throws if the decoder could not provide as many levels as the page header
announces.
+inline void CheckLevelsDecoded(int64_t number_decoded, int64_t expected) {
+ if (ARROW_PREDICT_FALSE(number_decoded != expected)) {
+ throw ParquetException(kErrorRepDefLevelNotMatchesNumValues);
+ }
+}
-/******************
- * LevelDecoder *
- ******************/
+void CheckMinMax(const int16_t* data, int32_t size, int16_t max_level) {
+ if (size > 0) {
+ internal::MinMax min_max = internal::FindMinMax(data, size);
+ if (ARROW_PREDICT_FALSE(min_max.min < 0 || min_max.max > max_level)) {
+ std::stringstream ss;
+ ss << "Malformed levels. min: " << min_max.min << " max: " << min_max.max
+ << " out of range. Max Level: " << max_level;
+ throw ParquetException(ss.str());
+ }
+ }
+}
-struct LevelDecoder::Impl {
- using RleBitPackedDecoder = ::arrow::util::RleBitPackedDecoder<int16_t>;
- using BitPackedDecoder = ::arrow::util::BitPackedDecoder<int16_t>;
+/// True if a T can hold a U.
+template <typename T, typename U>
+inline constexpr bool can_hold_v =
std::in_range<T>(std::numeric_limits<U>::min()) &&
+
std::in_range<T>(std::numeric_limits<U>::max());
+
Review Comment:
Bad review, this is C++20 https://en.cppreference.com/cpp/utility/in_range
--
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]