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

fix: issue introduced in #6833 - less than equal check for scale in decimal conversion #7070

Merged
merged 3 commits into from
Feb 5, 2025

Conversation

himadripal
Copy link
Contributor

@himadripal himadripal commented Feb 3, 2025

Which issue does this PR close?

Closes #.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Feb 3, 2025
@himadripal himadripal changed the title fix issue introduced in #6833 less than equal check for scale in decimal conversion fix: issue introduced in #6833 - less than equal check for scale in decimal conversion Feb 3, 2025
arrow-cast/src/cast/mod.rs Outdated Show resolved Hide resolved
@Blizzara
Copy link
Contributor

Blizzara commented Feb 3, 2025

LGTM, thanks!

name change

Co-authored-by: Arttu <[email protected]>
@himadripal
Copy link
Contributor Author

himadripal commented Feb 4, 2025

@andygrove @tustvold @alamb @viirya please take a look when you get time.

Copy link
Contributor

@kazuyukitanimura kazuyukitanimura left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -167,7 +167,7 @@ where
let array: PrimitiveArray<T> =
if input_scale == output_scale && input_precision <= output_precision {
array.clone()
} else if input_scale < output_scale {
} else if input_scale <= output_scale {
// the scale doesn't change, but precision may change and cause overflow
convert_to_bigger_or_equal_scale_decimal::<T, T>(
Copy link
Member

Choose a reason for hiding this comment

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

As the call is to convert_to_bigger_or_equal_scale_decimal, looks like the condition was not correct before. Btw, the above comment is "the scale doesn't change...", however, the scale is actually changed, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Previous PR introduced this bug and this is to fixing it. Removed comment.

Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

Thanks @himadripal

@alamb alamb merged commit 1019f5b into apache:main Feb 5, 2025
26 checks passed
@alamb
Copy link
Contributor

alamb commented Feb 5, 2025

Thank you @himadripal @Blizzara @andygrove and @viirya

@findepi
Copy link
Member

findepi commented Feb 5, 2025

thanks for fixing this!

additional test case would be nice. casting from value 0 of decimal(3,0) type to decimal(2,0) type used to produce 1 before this fix. it sounds like a test case that should be in the code base (will add)

@himadripal would you want to backport this fix to the 53.0.0_maintenance branch? latest 53.4.0 is affected by this bug

(assuming we would want to release 53.5.0 release, cc @alamb. for a correctness bug like this i think we should, but not my call)

@findepi
Copy link
Member

findepi commented Feb 5, 2025

additional test case would be nice. casting from value 0 of decimal(3,0) type to decimal(2,0) type used to produce 1 before this fix. it sounds like a test case that should be in the code base (will add)

-> #7078

felipecrv pushed a commit to sdf-labs/arrow-rs that referenced this pull request Feb 5, 2025
…e in decimal conversion (apache#7070)

* fix <= check for scale in decimal conversion

* Update arrow-cast/src/cast/mod.rs

name change

Co-authored-by: Arttu <[email protected]>

* remove incorrect comment

---------

Co-authored-by: Arttu <[email protected]>
himadripal added a commit to himadripal/arrow-rs that referenced this pull request Feb 5, 2025
…e in decimal conversion (apache#7070)

* fix <= check for scale in decimal conversion

* Update arrow-cast/src/cast/mod.rs

name change

Co-authored-by: Arttu <[email protected]>

* remove incorrect comment

---------

Co-authored-by: Arttu <[email protected]>
himadripal added a commit to himadripal/arrow-rs that referenced this pull request Feb 5, 2025
…e in decimal conversion (apache#7070)

* fix <= check for scale in decimal conversion

* Update arrow-cast/src/cast/mod.rs

name change

Co-authored-by: Arttu <[email protected]>

* remove incorrect comment

---------

Co-authored-by: Arttu <[email protected]>
phillipleblanc pushed a commit to spiceai/arrow-rs that referenced this pull request Feb 10, 2025
…e in decimal conversion (apache#7070)

* fix <= check for scale in decimal conversion

* Update arrow-cast/src/cast/mod.rs

name change

Co-authored-by: Arttu <[email protected]>

* remove incorrect comment

---------

Co-authored-by: Arttu <[email protected]>
@Blizzara
Copy link
Contributor

@alamb et al, would it be possible to get a release with this fix in? Given it's a very clear correctness issue and regression, I'd feel that should warrant a fix release, but I'm not sure of the process or customs here..

@alamb
Copy link
Contributor

alamb commented Feb 10, 2025

@alamb et al, would it be possible to get a release with this fix in? Given it's a very clear correctness issue and regression, I'd feel that should warrant a fix release, but I'm not sure of the process or customs here..

@Blizzara yes I think we can make a release with the fix given that the issue was a regression -- let's move the conversation to #7083 (comment)

alamb added a commit that referenced this pull request Feb 12, 2025
…e32 (#7074)

* Support converting large dates (i.e. +10999-12-31) from string to Date32

* Fix lint

* Update arrow-cast/src/parse.rs

Co-authored-by: Andrew Lamb <[email protected]>

* fix: issue introduced in #6833 -  less than equal check for scale in decimal conversion (#7070)

* fix <= check for scale in decimal conversion

* Update arrow-cast/src/cast/mod.rs

name change

Co-authored-by: Arttu <[email protected]>

* remove incorrect comment

---------

Co-authored-by: Arttu <[email protected]>

* minor: re-export `OffsetBufferBuilder` in `arrow` crate (#7077)

* Add another decimal cast edge test case (#7078)

* Add another decimal cast edge test case

Before 1019f5b this test would fail, as
the cast produced 1. 0 is an edge case worth explicitly testing for.

* typo/fmt

Co-authored-by: Felipe Oliveira Carvalho <[email protected]>

---------

Co-authored-by: Felipe Oliveira Carvalho <[email protected]>

* Support both 0x01 and 0x02 as type for list of booleans in thrift metadata (#7052)

* Support both 0x01 and 0x02 as type for list of booleans

* Also support 0 for false inside boolean collections

* Use hex notation in tests

* Fix LocalFileSystem with range request that ends beyond end of file (#6751)

* Fix LocalFileSystem with range request that ends beyond end of file

* fix windows

* add comment

* Seek error

* fix seek check

* remove windows flag

* Get file length from file metadata

* Introduce `UnsafeFlag` to manage disabling `ArrayData` validation (#7027)

* Introduce UnsafeFlag to manage disabling validation

* fix docs

* Refactor arrow-ipc: Rename `ArrayReader` to `RecodeBatchDecoder` (#7028)

* Rename `ArrayReader` to `RecordBatchDecoder`

* Remove alias for `self`

* Minor: Update release schedule (#7086)

* Minor: Update release schedule

* realism

* Refactor some decimal-related code and tests (#7062)

* Refactor some decimal-related code and tests in preparation for adding Decimal32 and Decimal64 support

* Fixed symbol

* Apply PR feedback

* Fixed format problem

* Fixed logical merge conflicts

* PR feedback

* Refactor arrow-ipc: Move `create_*_array` methods into `RecordBatchDecoder` (#7029)

* Move `create_primitive_array` into RecordBatchReader

* Move `create_list-array` into RecordBatchReader

* Move `create_dictionay_array` into RecordBatchReader

* Print Parquet BasicTypeInfo id when present (#7094)

* Print Parquet BasicTypeInfo id when present

* Improve print_schema documentation

* tiny cleanup

* Add a custom implementation `LocalFileSystem::list_with_offset`  (#7019)

* Initial change from Daniel.

* Upgrade unit test to be more generic.

* Add comments on why we have filter

* Cleanup unit tests.

* Update object_store/src/local.rs

Co-authored-by: Adam Reeve <[email protected]>

* Add changes suggested by Adam.

* Cleanup match error.

* Apply formatting changes suggested by cargo +stable fmt --all.

* Apply cosmetic changes suggested by clippy.

* Upgrade test_path_with_offset to create temporary directory + files for testing rather than pointing to existing dir.

---------

Co-authored-by: Adam Reeve <[email protected]>

* fix: first none/empty list in `ListArray` panics in `cast_with_options` (#7065)

* fix: first none in `ListArray` panics in `cast_with_options`

* simplify

* fix

* Update arrow-cast/src/cast/list.rs

Co-authored-by: Jeffrey Vo <[email protected]>

---------

Co-authored-by: Jeffrey Vo <[email protected]>

* Benchmarks for Arrow IPC writer (#7090)

* Add benchmarks for Arrow IPC writer

* Add benchmarks for Arrow IPC writer

* reuse target buffer

* rename, etc

* Add compression type

* update

---------

Co-authored-by: Andy Grove <[email protected]>

* Minor: Clarify documentation on `NullBufferBuilder::allocated_size` (#7089)

* Minor: Clarify documentaiton on NullBufferBuilder::allocated_size

* add note about why allocations are 64 bytes

* Add more tests for edge cases

* Add negative test case for incorrectly formatted large dates

---------

Co-authored-by: Andrew Lamb <[email protected]>
Co-authored-by: Himadri Pal <[email protected]>
Co-authored-by: Arttu <[email protected]>
Co-authored-by: Piotr Findeisen <[email protected]>
Co-authored-by: Felipe Oliveira Carvalho <[email protected]>
Co-authored-by: Jörn Horstmann <[email protected]>
Co-authored-by: Kyle Barron <[email protected]>
Co-authored-by: Curt Hagenlocher <[email protected]>
Co-authored-by: Devin Smith <[email protected]>
Co-authored-by: Corwin Joy <[email protected]>
Co-authored-by: Adam Reeve <[email protected]>
Co-authored-by: irenjj <[email protected]>
Co-authored-by: Jeffrey Vo <[email protected]>
Co-authored-by: Andy Grove <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Regression in 54.0.0]. Decimal cast to smaller precision gives invalid (off-by-one) result in some cases
7 participants