Skip to content

Commit

Permalink
PARQUET-1845: [C++] Add expected results of Int96 in big-endian
Browse files Browse the repository at this point in the history
This PR adds expected results of Int96 for parquet-internals-test in big-endian.

This PR assumes that uint_64 and uint_32 elements in Int96 are handled using a native endian for effectiveness.

Closes apache#6981 from kiszk/PARQUET-1845

Authored-by: Kazuaki Ishizaki <[email protected]>
Signed-off-by: Wes McKinney <[email protected]>
  • Loading branch information
kiszk authored and wesm committed Aug 3, 2020
1 parent f51564b commit 0d25270
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cpp/src/parquet/types_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ TEST(TypePrinter, StatisticsTypes) {
ASSERT_STREQ("1.0245", FormatStatValue(Type::DOUBLE, smin).c_str());
ASSERT_STREQ("2.0489", FormatStatValue(Type::DOUBLE, smax).c_str());

#if ARROW_LITTLE_ENDIAN
Int96 Int96_min = {{1024, 2048, 4096}};
Int96 Int96_max = {{2048, 4096, 8192}};
#else
Int96 Int96_min = {{2048, 1024, 4096}};
Int96 Int96_max = {{4096, 2048, 8192}};
#endif
smin = std::string(reinterpret_cast<char*>(&Int96_min), sizeof(Int96));
smax = std::string(reinterpret_cast<char*>(&Int96_max), sizeof(Int96));
ASSERT_STREQ("1024 2048 4096", FormatStatValue(Type::INT96, smin).c_str());
Expand All @@ -126,9 +131,14 @@ TEST(TypePrinter, StatisticsTypes) {

TEST(TestInt96Timestamp, Decoding) {
auto check = [](int32_t julian_day, uint64_t nanoseconds) {
#if ARROW_LITTLE_ENDIAN
Int96 i96{static_cast<uint32_t>(nanoseconds),
static_cast<uint32_t>(nanoseconds >> 32),
static_cast<uint32_t>(julian_day)};
#else
Int96 i96{static_cast<uint32_t>(nanoseconds >> 32),
static_cast<uint32_t>(nanoseconds), static_cast<uint32_t>(julian_day)};
#endif
// Official formula according to https://github.com/apache/parquet-format/pull/49
int64_t expected =
(julian_day - 2440588) * (86400LL * 1000 * 1000 * 1000) + nanoseconds;
Expand Down

0 comments on commit 0d25270

Please sign in to comment.