Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

cyb70289
Copy link
Contributor

@cyb70289 cyb70289 commented Nov 25, 2021

Decimal128: Invalid: Decimal precision out of range [1, 38]: 0
Decimal256: Invalid: Decimal precision out of range [1, 76]: 100

@github-actions
Copy link

Comment on lines 834 to 836
const auto min = kMinPrecision, max = kMaxPrecision;
return Status::Invalid("Decimal precision out of range [", min, ", ", max,
"]: ", precision);
Copy link
Contributor Author

@cyb70289 cyb70289 Nov 25, 2021

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?

Copy link
Member

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);
 }

Copy link
Contributor Author

@cyb70289 cyb70289 Nov 30, 2021

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

@cyb70289
Copy link
Contributor Author

Comment on lines 834 to 836
const auto min = kMinPrecision, max = kMaxPrecision;
return Status::Invalid("Decimal precision out of range [", min, ", ", max,
"]: ", precision);
Copy link
Member

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);
 }

@nealrichardson
Copy link
Member

@nealrichardson , looks the RTools 35 job timed out https://github.com/apache/arrow/runs/4320157653?check_suite_focus=true

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"
@cyb70289 cyb70289 closed this in 29f98dd Nov 30, 2021
@cyb70289 cyb70289 deleted the 14842-decimal-error-msg branch November 30, 2021 05:11
@ursabot
Copy link

ursabot commented Nov 30, 2021

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.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Failed ⬇️0.53% ⬆️0.53%] ursa-i9-9960x
[Finished ⬇️0.13% ⬆️0.09%] ursa-thinkcentre-m75q
Supported benchmarks:
ursa-i9-9960x: langs = Python, R, JavaScript
ursa-thinkcentre-m75q: langs = C++, Java
ec2-t3-xlarge-us-east-2: cloud = True

kou pushed a commit to kou/arrow that referenced this pull request Dec 1, 2021
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants