wgtmac commented on code in PR #55901:
URL: https://github.com/apache/arrow/pull/55901#discussion_r4781013674
##########
cpp/src/parquet/column_writer.cc:
##########
@@ -2363,29 +2376,36 @@ struct SerializeFunctor<Int64Type,
::arrow::TimestampType> {
auto target_type = ::arrow::timestamp(target_unit);
bool truncation_allowed = ctx->properties->truncated_timestamps_allowed();
+ const auto* valid_bits = array.null_count() == 0 ? nullptr :
array.null_bitmap_data();
+
auto DivideBy = [&](const int64_t factor) {
- for (int64_t i = 0; i < array.length(); i++) {
- if (!truncation_allowed && array.IsValid(i) && (values[i] % factor !=
0)) {
- return Status::Invalid("Casting from ", source_type.ToString(), " to
",
- target_type->ToString(),
- " would lose data: ", values[i]);
- }
- out[i] = values[i] / factor;
- }
- return Status::OK();
+ return ::arrow::internal::VisitSetBitRuns(
+ valid_bits, array.offset(), array.length(), [&](int64_t start,
int64_t length) {
+ for (int64_t i = start; i < start + length; ++i) {
+ if (!truncation_allowed && values[i] % factor != 0) {
Review Comment:
nit: move the if check out of the loop by setting `violated = violated ||
(!truncation_allowed && values[i] % factor != 0)` and then check violated in
the end. Or simply add `ARROW_PREDICT_FALSE` just like below?
##########
cpp/src/parquet/encoder.cc:
##########
@@ -124,6 +130,105 @@ class EncoderImpl : virtual public Encoder {
int64_t unencoded_byte_array_data_bytes_ = 0;
};
+// A valid run in an Arrow fixed-width values buffer is contiguous in bytes.
+int64_t AppendFixedWidthArray(const ::arrow::Array& array, const uint8_t*
values,
+ int64_t byte_width, ::arrow::BufferBuilder&
sink) {
+ const int64_t num_valid = array.length() - array.null_count();
+ if (num_valid == 0 || byte_width == 0) {
+ return num_valid;
+ }
+ if (num_valid == array.length()) {
+ PARQUET_THROW_NOT_OK(sink.Append(values, num_valid * byte_width));
+ } else {
+ PARQUET_THROW_NOT_OK(sink.Reserve(num_valid * byte_width));
+ VisitSetBitRunsVoid(array.null_bitmap_data(), array.offset(),
array.length(),
+ [&](int64_t start, int64_t length) {
+ sink.UnsafeAppend(values + start * byte_width,
+ length * byte_width);
+ });
+ }
+ return num_valid;
+}
+
+template <typename DType>
+int64_t EncoderImpl::AppendNumericArray(const ::arrow::Array& values,
+ ::arrow::BufferBuilder& sink) const {
+ using ArrowType = typename EncodingTraits<DType>::ArrowType;
+ using ArrayType = typename ::arrow::TypeTraits<ArrowType>::ArrayType;
+ if (values.type_id() != ArrowType::type_id) {
+ if (encoding_ == Encoding::PLAIN) {
+ throw ParquetException("direct put to ", ArrowType::type_name(), " from
",
Review Comment:
Why do we need to use two different error messages? Just to keep the
original behavior? Is it better to use the same one?
##########
cpp/src/parquet/decoder.cc:
##########
@@ -102,8 +103,9 @@ struct ArrowBinaryHelper<ByteArrayType,
::arrow::BinaryType> {
// If a new chunk is created and estimated_remaining_data_length is provided,
// it will also reserve the estimated data length for this chunk.
- Status AppendValue(const uint8_t* data, int32_t length,
- std::optional<int64_t> estimated_remaining_data_length =
{}) {
+ ARROW_FORCE_INLINE Status
Review Comment:
Why this change?
##########
cpp/src/parquet/decoder.cc:
##########
@@ -1290,138 +1289,77 @@ class DictByteArrayDecoderImpl : public
DictDecoderImpl<ByteArrayType> {
int result = 0;
if (null_count == 0) {
PARQUET_THROW_NOT_OK(DecodeArrowNonNull(num_values, builder, &result));
- } else {
- PARQUET_THROW_NOT_OK(DecodeArrow(num_values, null_count, valid_bits,
- valid_bits_offset, builder, &result));
+ return result;
}
+ PARQUET_THROW_NOT_OK(builder->Reserve(num_values));
+ PARQUET_THROW_NOT_OK(DecodeArrowRuns(
+ num_values, null_count, valid_bits, valid_bits_offset, &result,
+ [&](const ByteArray& value) { return builder->Append(value.ptr,
value.len); },
+ [&](int64_t length) { return builder->AppendNulls(length); }));
return result;
}
int DecodeArrow(int num_values, int null_count, const uint8_t* valid_bits,
int64_t valid_bits_offset,
typename EncodingTraits<ByteArrayType>::Accumulator* out)
override {
int result = 0;
- if (null_count == 0) {
- PARQUET_THROW_NOT_OK(DecodeArrowDense(num_values, null_count,
- /*valid_bits=*/nullptr,
valid_bits_offset,
- out, &result));
- } else {
- PARQUET_THROW_NOT_OK(DecodeArrowDense(num_values, null_count, valid_bits,
- valid_bits_offset, out, &result));
- }
+ // The encoded indices size doesn't tell us how many bytes the values will
occupy.
Review Comment:
Does this comment relate to `/*estimated_data_length=*/{}` below?
--
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]