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

Decimal creation utilities #170

Closed
wjones127 opened this issue Mar 27, 2023 · 1 comment · Fixed by #180
Closed

Decimal creation utilities #170

wjones127 opened this issue Mar 27, 2023 · 1 comment · Fixed by #180
Labels
enhancement New feature or request

Comments

@wjones127
Copy link
Member

Arrow specifies a particular format for decimals to be laid out, it would be nice to have a struct like Arrow's Decimal128/Decimal256 that allows us to construct them from integers and have a method ArrowArrayAppendDecimal.

@wjones127 wjones127 added the enhancement New feature or request label Mar 27, 2023
@paleolimbot
Copy link
Member

Thanks for bringing this up - I think it's definitely in scope to add a decimal extractor and appender. We'd probably need a struct to define a decimal...maybe:

struct ArrowDecimal {
  // Words defined from most-significant to least-significant or the other way around?
  // nanoarrow could take care of ensuring that these are copied in the right order on big endian
  int32_t words[8]; // or int64_t words[4]?
  int32_t precision;
  int32_t scale;
};

ArrowErrorCode ArrowArrayAppendDecimal(struct ArrowArray* array, struct ArrowDecimal* value);
void ArrowArrayViewGetDecimal(struct ArrowArrayView* array_view, struct ArrowDecimal* out);

Do we need creation to/from double?

paleolimbot added a commit that referenced this issue Apr 14, 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:

```c
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":

```c
static inline ArrowErrorCode ArrowArrayAppendDecimal(struct ArrowArray* array,
                                                     struct ArrowDecimal* value);
static inline void ArrowArrayViewGetDecimalUnsafe(struct ArrowArrayView* array_view,
                                                  int64_t i, struct ArrowDecimal* out);
```
@paleolimbot paleolimbot added this to the nanoarrow 0.2.0 milestone Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants