Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

[NSE-400] Fix the bug for negative decimal data #686

Merged
merged 3 commits into from
Jan 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions native-sql-engine/cpp/src/operators/row_to_columnar_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ arrow::Status CreateArrayData(std::shared_ptr<arrow::Schema> schema, int64_t num
for (int k = length - 1; k >= 0; k--) {
bytesValue2[length - 1 - k] = bytesValue[k];
}
if (int8_t(bytesValue[0]) < 0) {
for (int k = length; k < 16; k++) {
bytesValue2[k] = 255;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: for negative decimal, all unused bits are set to 1

}
}
arrow::Decimal128 value =
arrow::Decimal128(arrow::BasicDecimal128(bytesValue2));
array_data[position] = value;
Expand Down Expand Up @@ -950,6 +955,11 @@ arrow::Status CreateArrayData(std::shared_ptr<arrow::Schema> schema, int64_t num
for (int k = elementLength - 1; k >= 0; k--) {
bytesValue2[elementLength - 1 - k] = bytesValue[k];
}
if (int8_t(bytesValue[0]) < 0) {
for (int k = elementLength; k < 16; k++) {
bytesValue2[k] = 255;
}
}
arrow::Decimal128 value =
arrow::Decimal128(arrow::BasicDecimal128(bytesValue2));
RETURN_NOT_OK(child_builder.Append(value));
Expand Down