Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 32a4abe

Browse files
committed
Cleanup iteration a bit
1 parent 920832a commit 32a4abe

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/parquet/arrow/writer.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ Status FileWriter::Impl::TypedWriteBatch<FLBAType, ::arrow::DecimalType>(
797797
const auto& data = static_cast<const Decimal128Array&>(*array);
798798
const int64_t length = data.length();
799799

800+
// TODO(phillipc): This is potentially very wasteful if we have a lot of nulls
800801
std::vector<uint64_t> big_endian_values(static_cast<size_t>(length) * 2);
801802

802803
RETURN_NOT_OK(data_buffer_.Resize(length * sizeof(FLBA), false));
@@ -808,7 +809,13 @@ Status FileWriter::Impl::TypedWriteBatch<FLBAType, ::arrow::DecimalType>(
808809
const int32_t offset =
809810
decimal_type.byte_width() - DecimalSize(decimal_type.precision());
810811

811-
if (writer->descr()->schema_node()->is_required() || data.null_count() == 0) {
812+
const bool does_not_have_nulls =
813+
writer->descr()->schema_node()->is_required() || data.null_count() == 0;
814+
815+
// TODO(phillipc): Look into whether our compilers will perform loop unswitching so we
816+
// don't have to keep writing two loops to handle the case where we know there are no
817+
// nulls
818+
if (does_not_have_nulls) {
812819
// no nulls, just dump the data
813820
// todo(advancedxy): use a writeBatch to avoid this step
814821
for (int64_t i = 0, j = 0; i < length; ++i, j += 2) {
@@ -819,17 +826,13 @@ Status FileWriter::Impl::TypedWriteBatch<FLBAType, ::arrow::DecimalType>(
819826
reinterpret_cast<const uint8_t*>(&big_endian_values[j]) + offset);
820827
}
821828
} else {
822-
int32_t buffer_idx = 0;
823-
int32_t j = 0;
824-
825-
for (int64_t i = 0; i < length; ++i) {
829+
for (int64_t i = 0, buffer_idx = 0, j = 0; i < length; ++i) {
826830
if (!data.IsNull(i)) {
827831
auto unsigned_64_bit = reinterpret_cast<const uint64_t*>(data.GetValue(i));
828832
big_endian_values[j] = ::arrow::BitUtil::ToBigEndian(unsigned_64_bit[1]);
829833
big_endian_values[j + 1] = ::arrow::BitUtil::ToBigEndian(unsigned_64_bit[0]);
830-
buffer_ptr[buffer_idx] = FixedLenByteArray(
834+
buffer_ptr[buffer_idx++] = FixedLenByteArray(
831835
reinterpret_cast<const uint8_t*>(&big_endian_values[j]) + offset);
832-
++buffer_idx;
833836
j += 2;
834837
}
835838
}

0 commit comments

Comments
 (0)