AntoinePrv commented on code in PR #50629:
URL: https://github.com/apache/arrow/pull/50629#discussion_r4334773292
##########
cpp/src/parquet/column_reader.cc:
##########
@@ -91,137 +83,100 @@ 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";
+/// 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());
+
+/// Clamp to a given type.
+template <typename T, typename U>
+constexpr T clamp_to(U val) {
+ if constexpr (can_hold_v<T, U>) {
+ return static_cast<T>(val);
+ }
+ constexpr U kMax = std::numeric_limits<T>::max();
+ constexpr U kMin = std::numeric_limits<T>::min();
+ return static_cast<T>(std::clamp<U>(val, kMin, kMax));
+}
+
+/// Return the int that can be represented by the other.
+template <typename T, typename U>
+using smallest_int_t = std::conditional_t<can_hold_v<T, U>, U, T>;
+
+/// Return the min in the smallest integer size of its inputs.
+template <typename T, typename U>
+constexpr auto narrow_min(T x, U y) -> smallest_int_t<T, U> {
+ using V = smallest_int_t<T, U>;
+ return std::min<V>(clamp_to<V>(x), clamp_to<V>(y));
+}
+
+/// Whether values of type T can be printed to `std::cout`.
+template <typename T>
+concept can_cout = requires(std::ostream& os, const T& value) {
+ os << value;
+}; // NOLINT(readability/braces)
} // namespace
/******************
* LevelDecoder *
******************/
-struct LevelDecoder::Impl {
- using RleBitPackedDecoder = ::arrow::util::RleBitPackedDecoder<int16_t>;
- using BitPackedDecoder = ::arrow::util::BitPackedDecoder<int16_t>;
-
- std::variant<RleBitPackedDecoder, BitPackedDecoder> decoder = {};
-
- [[nodiscard]] int GetBatch(int16_t* out, int batch_size) {
- return std::visit([&](auto& dec) { return dec.GetBatch(out, batch_size);
}, decoder);
- }
+// Replacement for legacy LevelDecoder
+using NewLevelDecoder = PageLevelDecoder<>;
Review Comment:
Went with `PageLevelToIntDecoder` to mirror `PageLevelToBitmapDecoder`.
--
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]