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

feat: Add Decimal Get/Set utilities #180

Merged
merged 7 commits into from
Apr 14, 2023

Conversation

paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Apr 13, 2023

Closes #170.

This is not designed to be a fully-featured performant decimal math library, but is designed to help with byte shuffling and provide enough support that users can write tests for decimal arrays (e.g., by providing integer getters and setters for numbers that fit within the int64 range).

Adds a struct ArrowDecimal and utility functions:

static inline void ArrowDecimalInit(struct ArrowDecimal* decimal, int32_t bitwidth,
                                    int32_t precision, int32_t scale);
static inline int64_t ArrowDecimalGetIntUnsafe(struct ArrowDecimal* decimal);
static inline void ArrowDecimalGetBytes(struct ArrowDecimal* decimal, uint8_t* out);
static inline int64_t ArrowDecimalSign(struct ArrowDecimal* decimal);
static inline void ArrowDecimalSetInt(struct ArrowDecimal* decimal, int64_t value);
static inline void ArrowDecimalSetBytes(struct ArrowDecimal* decimal,
                                        const uint8_t* value);

...and adds a "getter" and an "appender":

static inline ArrowErrorCode ArrowArrayAppendDecimal(struct ArrowArray* array,
                                                     struct ArrowDecimal* value);
static inline void ArrowArrayViewGetDecimalUnsafe(struct ArrowArrayView* array_view,
                                                  int64_t i, struct ArrowDecimal* out);

@codecov-commenter
Copy link

Codecov Report

Merging #180 (c6bb04a) into main (20e5bae) will decrease coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main     #180      +/-   ##
==========================================
- Coverage   93.43%   93.42%   -0.01%     
==========================================
  Files           7        7              
  Lines        1767     1765       -2     
  Branches       57       57              
==========================================
- Hits         1651     1649       -2     
  Misses         84       84              
  Partials       32       32              
Impacted Files Coverage Δ
src/nanoarrow/array.c 93.29% <ø> (-0.03%) ⬇️
src/nanoarrow/array_inline.h 76.92% <ø> (ø)
src/nanoarrow/nanoarrow_types.h 92.30% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@paleolimbot paleolimbot marked this pull request as ready for review April 13, 2023 16:32
Copy link
Member

@wjones127 wjones127 left a comment

Choose a reason for hiding this comment

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

This looks good. Very clean implementation :)

@paleolimbot paleolimbot merged commit 4a62bab into apache:main Apr 14, 2023
@paleolimbot paleolimbot deleted the decimal-utils branch April 20, 2023 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decimal creation utilities
3 participants