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

Commit 46dff15

Browse files
committed
Clean up uint32 test
1 parent 613255e commit 46dff15

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

src/parquet/arrow/arrow-reader-writer-test.cc

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -885,25 +885,43 @@ TEST_F(TestUInt32ParquetIO, Parquet_1_0_Compability) {
885885
ASSERT_OK_NO_THROW(
886886
WriteTable(*table, ::arrow::default_memory_pool(), this->sink_, 512, properties));
887887

888-
std::shared_ptr<Array> expected_values;
889888
std::shared_ptr<PoolBuffer> int64_data =
890889
std::make_shared<PoolBuffer>(::arrow::default_memory_pool());
891890
{
892891
ASSERT_OK(int64_data->Resize(sizeof(int64_t) * values->length()));
893-
int64_t* int64_data_ptr = reinterpret_cast<int64_t*>(int64_data->mutable_data());
894-
const uint32_t* uint32_data_ptr =
895-
reinterpret_cast<const uint32_t*>(values->values()->data());
896-
// std::copy might be faster but this is explicit on the casts)
897-
for (int64_t i = 0; i < values->length(); i++) {
898-
int64_data_ptr[i] = static_cast<int64_t>(uint32_data_ptr[i]);
899-
}
892+
auto int64_data_ptr = reinterpret_cast<int64_t*>(int64_data->mutable_data());
893+
auto uint32_data_ptr = reinterpret_cast<const uint32_t*>(values->values()->data());
894+
const auto cast_uint32_to_int64 = [](uint32_t value) {
895+
return static_cast<int64_t>(value);
896+
};
897+
std::transform(uint32_data_ptr, uint32_data_ptr + values->length(), int64_data_ptr,
898+
cast_uint32_to_int64);
900899
}
901900

902901
std::vector<std::shared_ptr<Buffer>> buffers{values->null_bitmap(), int64_data};
903902
auto arr_data = std::make_shared<::arrow::ArrayData>(::arrow::int64(), values->length(),
904903
buffers, values->null_count());
905-
ASSERT_OK(MakeArray(arr_data, &expected_values));
906-
this->ReadAndCheckSingleColumnTable(expected_values);
904+
std::shared_ptr<Array> expected_values = MakeArray(arr_data);
905+
ASSERT_NE(expected_values, NULLPTR);
906+
907+
const auto& expected = static_cast<const ::arrow::Int64Array&>(*expected_values);
908+
ASSERT_GT(values->length(), 0);
909+
ASSERT_EQ(values->length(), expected.length());
910+
911+
// TODO(phillipc): Is there a better way to compare these two arrays?
912+
// AssertArraysEqual requires the same type, but we only care about values in this case
913+
for (int i = 0; i < expected.length(); ++i) {
914+
const bool value_is_valid = values->IsValid(i);
915+
const bool expected_value_is_valid = expected.IsValid(i);
916+
917+
ASSERT_EQ(value_is_valid, expected_value_is_valid);
918+
919+
if (value_is_valid) {
920+
uint32_t value = values->Value(i);
921+
int64_t expected_value = expected.Value(i);
922+
ASSERT_EQ(value, expected_value);
923+
}
924+
}
907925
}
908926

909927
using TestStringParquetIO = TestParquetIO<::arrow::StringType>;

0 commit comments

Comments
 (0)