Skip to content

Commit

Permalink
PARQUET-1819: [C++] Refactor decoding
Browse files Browse the repository at this point in the history
Also add an additional size check before reading the length of a byte array.

Closes #6685 from pitrou/PARQUET-1819-refactor

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
pitrou committed Mar 24, 2020
1 parent 218cb5e commit 4fb888f
Show file tree
Hide file tree
Showing 2 changed files with 257 additions and 324 deletions.
41 changes: 41 additions & 0 deletions cpp/src/arrow/visitor_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,45 @@ inline Status VisitScalarInline(const Scalar& scalar, VISITOR* visitor) {

#undef TYPE_VISIT_INLINE

// Visit a null bitmap, in order, without overhead.
//
// The given `VisitFunc` should be a callable with either of these signatures:
// - void(bool is_valid)
// - Status(bool is_valid)

template <typename VisitFunc>
typename internal::call_traits::enable_if_return<VisitFunc, Status>::type
VisitNullBitmapInline(const uint8_t* valid_bits, int64_t valid_bits_offset,
int64_t num_values, int64_t null_count, VisitFunc&& func) {
if (null_count != 0) {
internal::BitmapReader bit_reader(valid_bits, valid_bits_offset, num_values);
for (int i = 0; i < num_values; ++i) {
RETURN_NOT_OK(func(bit_reader.IsSet()));
bit_reader.Next();
}
} else {
for (int i = 0; i < num_values; ++i) {
RETURN_NOT_OK(func(true));
}
}
return Status::OK();
}

template <typename VisitFunc>
typename internal::call_traits::enable_if_return<VisitFunc, void>::type
VisitNullBitmapInline(const uint8_t* valid_bits, int64_t valid_bits_offset,
int64_t num_values, int64_t null_count, VisitFunc&& func) {
if (null_count != 0) {
internal::BitmapReader bit_reader(valid_bits, valid_bits_offset, num_values);
for (int64_t i = 0; i < num_values; ++i) {
func(bit_reader.IsSet());
bit_reader.Next();
}
} else {
for (int64_t i = 0; i < num_values; ++i) {
func(true);
}
}
}

} // namespace arrow
Loading

0 comments on commit 4fb888f

Please sign in to comment.