Skip to content

ARROW-9948: [C++] Fix scale handling in Decimal{128, 256}::FromString - #10823

Closed
pitrou wants to merge 4 commits into
apache:masterfrom
pitrou:ARROW-9948-decimal-from-string
Closed

pitrou wants to merge 4 commits into
apache:masterfrom
pitrou:ARROW-9948-decimal-from-string

Conversation

@pitrou

@pitrou pitrou commented Jul 28, 2021 •

Copy link
Copy Markdown
Member
  • The wrong scale could be inferred if the input both had fractional digits and an exponent
  • An out-of-bounds access could be provoked when correcting an excessive negative scale (for example "1e39")
  • Make testing more generic and more thorough

@pitrou
pitrou marked this pull request as draft July 28, 2021 15:58
@github-actions

Copy link
Copy Markdown

@pitrou

pitrou commented Jul 28, 2021 •

Copy link
Copy Markdown
Member Author

@emkornfield @cyb70289 Do you want to take a look at this?

Comment thread cpp/src/arrow/util/decimal.cc Resolved
@pitrou
pitrou force-pushed the ARROW-9948-decimal-from-string branch from 258e9c1 to 8704910 Compare July 29, 2021 16:36
@pitrou pitrou changed the title ARROW-9948: [C++] Fix scale handling in Decimal128::FromString ARROW-9948: [C++] Fix scale handling in Decimal{128, 256}::FromString Jul 29, 2021
Comment thread cpp/src/arrow/util/basic_decimal.h Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@bkietz What do you think about this constructor scheme? Is it ok, or is there a better option?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd say it's not idiomatic arrow; I'd expect something like:

Suggested change
: BasicDecimal128(BitUtil::LittleEndianArray::ToNative(array)) {}
static BasicDecimal128 FromLittleEndianArray(const std::array<uint64_t, 2>& array) noexcept {
return {BitUtil::LittleEndianArray::ToNative(array)};
}

... but then we'll have to repeat the declaration for non Basic decimal types.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, yes, having to repeat the declaration is the problem here.

@pitrou
pitrou force-pushed the ARROW-9948-decimal-from-string branch 2 times, most recently from 830b0f1 to 1475fda Compare July 29, 2021 16:43
Comment thread cpp/src/arrow/util/decimal.cc Resolved
pitrou added 2 commits August 2, 2021 11:36
* The wrong scale could be inferred if the input both had fractional digits and an exponent
* An out-of-bounds access could be provoked when correcting an excessive negative scale (for example "1e39")
@pitrou
pitrou force-pushed the ARROW-9948-decimal-from-string branch from 1475fda to 5d694f1 Compare August 2, 2021 10:04
@pitrou
pitrou marked this pull request as ready for review August 2, 2021 11:11
@pitrou
pitrou requested review from bkietz and cyb70289 August 2, 2021 13:32

@cyb70289 cyb70289 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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.

4 participants