Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Sep 23, 2024
1 parent 2b406ba commit a93770b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
12 changes: 1 addition & 11 deletions velox/dwio/common/DirectDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,7 @@ class DirectDecoder : public IntDecoder<isSigned> {
} else if constexpr (std::is_same_v<
typename Visitor::DataType,
int128_t>) {
if (super::numBytes_ != 12) {
toSkip = visitor.process(super::template readInt<int128_t>(), atEnd);
} else {
// Reads INT96 timestamp as int128_t type and extracts the days and
// nanos.
const int128_t encoded = super::template readInt<int128_t>();
const int32_t days = encoded & ((1ULL << 32) - 1);
const uint64_t nanos = static_cast<uint64_t>(encoded >> 32);
auto ts = Timestamp::fromDaysAndNanos(days, nanos);
toSkip = visitor.process(reinterpret_cast<int128_t&>(ts), atEnd);
}
toSkip = visitor.process(super::template readInt<int128_t>(), atEnd);
} else {
toSkip = visitor.process(super::template readInt<int64_t>(), atEnd);
}
Expand Down
13 changes: 6 additions & 7 deletions velox/dwio/common/IntDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,24 +457,23 @@ inline int128_t IntDecoder<isSigned>::readInt96() {
unsigned char ch;

// Read 8 unsigned bytes.
uint64_t part1 = 0;
uint64_t nanos = 0;
for (uint32_t i = 0; i < 8; ++i) {
ch = readByte();
part1 |= (ch & BASE_256_MASK) << offset;
nanos |= (ch & BASE_256_MASK) << offset;
offset += 8;
}

// Read 4 signed bytes.
int32_t part2 = 0;
int32_t days = 0;
offset = 0;
for (uint32_t i = 0; i < 4; ++i) {
ch = readByte();
part2 |= (ch & BASE_256_MASK) << offset;
days |= (ch & BASE_256_MASK) << offset;
offset += 8;
}

int128_t result = part1;
return (result << 32) | part2;
auto ts = Timestamp::fromDaysAndNanos(days, nanos);
return reinterpret_cast<int128_t&>(ts);
}

template <bool isSigned>
Expand Down

0 comments on commit a93770b

Please sign in to comment.