-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-14842: [C++] Improve precision range error messages for Decimal #11773
Conversation
cpp/src/arrow/type.cc
Outdated
const auto min = kMinPrecision, max = kMaxPrecision; | ||
return Status::Invalid("Decimal precision out of range [", min, ", ", max, | ||
"]: ", precision); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mysterious why direct referencing kMinPrecision in Status::Invalid function leads to "undefined symbol" link error.
Maybe related to constexpr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we forgot to declare the constexpr in the .cc
file. This compiles and links for me:
diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc
index 7b761b3a6..fb872725f 100644
--- a/cpp/src/arrow/type.cc
+++ b/cpp/src/arrow/type.cc
@@ -823,6 +823,10 @@ int32_t DecimalType::DecimalSize(int32_t precision) {
// ----------------------------------------------------------------------
// Decimal128 type
+constexpr int32_t Decimal128Type::kMinPrecision;
+constexpr int32_t Decimal128Type::kMaxPrecision;
+constexpr int32_t Decimal128Type::kByteWidth;
+
Decimal128Type::Decimal128Type(int32_t precision, int32_t scale)
: DecimalType(type_id, 16, precision, scale) {
ARROW_CHECK_GE(precision, kMinPrecision);
@@ -831,9 +835,8 @@ Decimal128Type::Decimal128Type(int32_t precision, int32_t scale)
Result<std::shared_ptr<DataType>> Decimal128Type::Make(int32_t precision, int32_t scale) {
if (precision < kMinPrecision || precision > kMaxPrecision) {
- const auto min = kMinPrecision, max = kMaxPrecision;
- return Status::Invalid("Decimal precision out of range [", min, ", ", max,
- "]: ", precision);
+ return Status::Invalid("Decimal precision out of range [", kMinPrecision, ", ",
+ kMaxPrecision, "]: ", precision);
}
return std::make_shared<Decimal128Type>(precision, scale);
}
@@ -841,6 +844,10 @@ Result<std::shared_ptr<DataType>> Decimal128Type::Make(int32_t precision, int32_
// ----------------------------------------------------------------------
// Decimal256 type
+constexpr int32_t Decimal256Type::kMinPrecision;
+constexpr int32_t Decimal256Type::kMaxPrecision;
+constexpr int32_t Decimal256Type::kByteWidth;
+
Decimal256Type::Decimal256Type(int32_t precision, int32_t scale)
: DecimalType(type_id, 32, precision, scale) {
ARROW_CHECK_GE(precision, kMinPrecision);
@@ -849,9 +856,8 @@ Decimal256Type::Decimal256Type(int32_t precision, int32_t scale)
Result<std::shared_ptr<DataType>> Decimal256Type::Make(int32_t precision, int32_t scale) {
if (precision < kMinPrecision || precision > kMaxPrecision) {
- const auto min = kMinPrecision, max = kMaxPrecision;
- return Status::Invalid("Decimal precision out of range [", min, ", ", max,
- "]: ", precision);
+ return Status::Invalid("Decimal precision out of range [", kMinPrecision, ", ",
+ kMaxPrecision, "]: ", precision);
}
return std::make_shared<Decimal256Type>(precision, scale);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue should have been fixed in C++17.
The workaround in http://ostack.cn/?qa=744640/ looks simpler.
Original post: https://stackoverflow.com/questions/40690260/undefined-reference-error-for-static-constexpr-member
@nealrichardson , looks the RTools 35 job timed out |
cpp/src/arrow/type.cc
Outdated
const auto min = kMinPrecision, max = kMaxPrecision; | ||
return Status::Invalid("Decimal precision out of range [", min, ", ", max, | ||
"]: ", precision); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we forgot to declare the constexpr in the .cc
file. This compiles and links for me:
diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc
index 7b761b3a6..fb872725f 100644
--- a/cpp/src/arrow/type.cc
+++ b/cpp/src/arrow/type.cc
@@ -823,6 +823,10 @@ int32_t DecimalType::DecimalSize(int32_t precision) {
// ----------------------------------------------------------------------
// Decimal128 type
+constexpr int32_t Decimal128Type::kMinPrecision;
+constexpr int32_t Decimal128Type::kMaxPrecision;
+constexpr int32_t Decimal128Type::kByteWidth;
+
Decimal128Type::Decimal128Type(int32_t precision, int32_t scale)
: DecimalType(type_id, 16, precision, scale) {
ARROW_CHECK_GE(precision, kMinPrecision);
@@ -831,9 +835,8 @@ Decimal128Type::Decimal128Type(int32_t precision, int32_t scale)
Result<std::shared_ptr<DataType>> Decimal128Type::Make(int32_t precision, int32_t scale) {
if (precision < kMinPrecision || precision > kMaxPrecision) {
- const auto min = kMinPrecision, max = kMaxPrecision;
- return Status::Invalid("Decimal precision out of range [", min, ", ", max,
- "]: ", precision);
+ return Status::Invalid("Decimal precision out of range [", kMinPrecision, ", ",
+ kMaxPrecision, "]: ", precision);
}
return std::make_shared<Decimal128Type>(precision, scale);
}
@@ -841,6 +844,10 @@ Result<std::shared_ptr<DataType>> Decimal128Type::Make(int32_t precision, int32_
// ----------------------------------------------------------------------
// Decimal256 type
+constexpr int32_t Decimal256Type::kMinPrecision;
+constexpr int32_t Decimal256Type::kMaxPrecision;
+constexpr int32_t Decimal256Type::kByteWidth;
+
Decimal256Type::Decimal256Type(int32_t precision, int32_t scale)
: DecimalType(type_id, 32, precision, scale) {
ARROW_CHECK_GE(precision, kMinPrecision);
@@ -849,9 +856,8 @@ Decimal256Type::Decimal256Type(int32_t precision, int32_t scale)
Result<std::shared_ptr<DataType>> Decimal256Type::Make(int32_t precision, int32_t scale) {
if (precision < kMinPrecision || precision > kMaxPrecision) {
- const auto min = kMinPrecision, max = kMaxPrecision;
- return Status::Invalid("Decimal precision out of range [", min, ", ", max,
- "]: ", precision);
+ return Status::Invalid("Decimal precision out of range [", kMinPrecision, ", ",
+ kMaxPrecision, "]: ", precision);
}
return std::make_shared<Decimal256Type>(precision, scale);
}
I'm not sure why that would be, but it seems to have happened again. |
Decimal128: "Invalid: Decimal precision out of range [1, 38]: 0" Decimal256: "Invalid: Decimal precision out of range [1, 76]: 100"
eaab6ce
to
b83b6ab
Compare
Benchmark runs are scheduled for baseline = debf48d and contender = 29f98dd. 29f98dd is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Decimal128: `Invalid: Decimal precision out of range [1, 38]: 0` Decimal256: `Invalid: Decimal precision out of range [1, 76]: 100` Closes apache#11773 from cyb70289/14842-decimal-error-msg Authored-by: Yibo Cai <yibo.cai@arm.com> Signed-off-by: Yibo Cai <yibo.cai@arm.com>
Decimal128:
Invalid: Decimal precision out of range [1, 38]: 0
Decimal256:
Invalid: Decimal precision out of range [1, 76]: 100