Skip to content

Commit

Permalink
Fix Presto to Velox LongDecimal conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
majetideepak committed Sep 8, 2022
1 parent 638105c commit f36cdec
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static const char* kRle = "RLE";
static const char* kArray = "ARRAY";
static const char* kMap = "MAP";
static const char* kInt128Array = "INT128_ARRAY";
static const __int128_t kInt128Mask = ~(static_cast<__int128_t>(1) << 127);

struct ByteStream {
explicit ByteStream(const char* data, int32_t offset = 0)
Expand Down Expand Up @@ -104,7 +105,6 @@ velox::VectorPtr readScalarBlock(
case velox::TypeKind::VARCHAR:
case velox::TypeKind::DATE:
case velox::TypeKind::INTERVAL_DAY_TIME:
case velox::TypeKind::LONG_DECIMAL:
case velox::TypeKind::SHORT_DECIMAL:
return std::make_shared<velox::FlatVector<U>>(
pool,
Expand All @@ -113,6 +113,22 @@ velox::VectorPtr readScalarBlock(
positionCount,
buffer,
std::vector<velox::BufferPtr>{});
case velox::TypeKind::LONG_DECIMAL: {
for (auto i = 0; i < positionCount; i++) {
// Convert signed magnitude form to 2's complement.
if (rawBuffer[i] < 0) {
rawBuffer[i] &= kInt128Mask;
rawBuffer[i] *= -1;
}
}
return std::make_shared<velox::FlatVector<velox::UnscaledLongDecimal>>(
pool,
type,
nulls,
positionCount,
buffer,
std::vector<velox::BufferPtr>{});
}
case velox::TypeKind::TIMESTAMP: {
velox::BufferPtr timestamps =
velox::AlignedBuffer::allocate<velox::Timestamp>(positionCount, pool);
Expand Down

0 comments on commit f36cdec

Please sign in to comment.