MCPcopy Create free account
hub / github.com/apache/arrow / DecodeArrowDense

Method DecodeArrowDense

cpp/src/parquet/decoder.cc:756–813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

754
755 private:
756 Status DecodeArrowDense(int num_values, int null_count, const uint8_t* valid_bits,
757 int64_t valid_bits_offset,
758 typename EncodingTraits<ByteArrayType>::Accumulator* out,
759 int* out_values_decoded) {
760 // We're going to decode `num_values - null_count` PLAIN values,
761 // and each value has a 4-byte length header that doesn't count for the
762 // Arrow binary data length.
763 int64_t estimated_data_length =
764 len_ - 4 * static_cast<int64_t>(num_values - null_count);
765 if (ARROW_PREDICT_FALSE(estimated_data_length < 0)) {
766 return Status::Invalid("Invalid or truncated PLAIN-encoded BYTE_ARRAY data");
767 }
768
769 auto visit_binary_helper = [&](auto* helper) {
770 int values_decoded = 0;
771
772 auto visit_run = [&](int64_t position, int64_t run_length, bool is_valid) {
773 if (is_valid) {
774 for (int64_t i = 0; i < run_length; ++i) {
775 // We ensure `len_` is sufficient thanks to:
776 // 1. the initial `estimated_data_length` check above,
777 // 2. the running `value_len > estimated_data_length` check below.
778 // This precondition follows from those two checks.
779 DCHECK_GE(len_, 4);
780 auto value_len = SafeLoadAs<int32_t>(data_);
781 // This check also ensures that `value_len <= len_ - 4` due to the way
782 // `estimated_data_length` is computed.
783 if (ARROW_PREDICT_FALSE(value_len < 0 || value_len > estimated_data_length)) {
784 return Status::Invalid(
785 "Invalid or truncated PLAIN-encoded BYTE_ARRAY data");
786 }
787 RETURN_NOT_OK(
788 helper->AppendValue(data_ + 4, value_len, estimated_data_length));
789 auto increment = value_len + 4;
790 data_ += increment;
791 len_ -= increment;
792 estimated_data_length -= value_len;
793 DCHECK_GE(estimated_data_length, 0);
794 }
795 values_decoded += static_cast<int>(run_length);
796 DCHECK_LE(values_decoded, num_values);
797 return Status::OK();
798 } else {
799 return helper->AppendNulls(run_length);
800 }
801 };
802
803 RETURN_NOT_OK(
804 VisitBitRuns(valid_bits, valid_bits_offset, num_values, std::move(visit_run)));
805
806 num_values_ -= values_decoded;
807 *out_values_decoded = values_decoded;
808 return Status::OK();
809 };
810
811 return DispatchArrowBinaryHelper<ByteArrayType>(
812 out, num_values, estimated_data_length, visit_binary_helper);
813 }

Callers

nothing calls this directly

Calls 5

VisitBitRunsFunction · 0.85
InvalidFunction · 0.50
OKFunction · 0.50
AppendValueMethod · 0.45
AppendNullsMethod · 0.45

Tested by

no test coverage detected