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

[NSE-239] Adopt ARROW-7011 #240

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Changes from all 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
8 changes: 1 addition & 7 deletions native-sql-engine/cpp/src/precompile/gandiva.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ T round2(T val, int precision = 2) {
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like this round2 func can also utilize below new cast method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is arrow::Decimal128 stored internally using some char-like stuffs? I didn't see a "Reprecision" method or something is provided so I think it might be OK for just now to use string formatters. By the way I see there is another function std::setprecision might be easier to use than snprintf.


arrow::Decimal128 castDECIMAL(double val, int32_t precision, int32_t scale) {
double dVal = (double)val;
int charsNeeded = 1 + snprintf(NULL, 0, "%.*f", (int)scale, dVal);
char* buffer = reinterpret_cast<char*>(malloc(charsNeeded));
snprintf(buffer, sizeof(buffer), "%.*f", (int)scale, nextafter(val, val + 0.5));
auto decimal_str = std::string(buffer);
free(buffer);
return arrow::Decimal128::FromString(decimal_str).ValueOrDie();
return arrow::Decimal128::FromReal(val, precision, scale).ValueOrDie();
}

std::string castStringFromDecimal(arrow::Decimal128 val, int32_t scale) {
Expand Down