-
Notifications
You must be signed in to change notification settings - Fork 55
Add metadata builder functions #12
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
Conversation
a3c3ddc to
66073ee
Compare
Codecov Report
@@ Coverage Diff @@
## main #12 +/- ##
==========================================
- Coverage 91.97% 90.32% -1.66%
==========================================
Files 5 6 +1
Lines 798 930 +132
Branches 30 38 +8
==========================================
+ Hits 734 840 +106
- Misses 41 59 +18
- Partials 23 31 +8
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
src/nanoarrow/metadata.c
Outdated
| return NANOARROW_OK; | ||
| } | ||
|
|
||
| ArrowErrorCode ArrowMetadataBuilderAppendView(struct ArrowBuffer* buffer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth possibly exposing this variant too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a compromise of sorts...all values are now ArrowStringView but all keys stay const char*, which is somewhere inbetween the programmability and non-null terminated-ness of the ArrowStringView and the reality that keys are almost always "a literal string". I tried having both be ArrowStringView but that was rather painful to actually use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if a helper macro to convert const char* to struct ArrowStringView might help work around that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added ArrowCharView():
arrow-nanoarrow/src/nanoarrow/nanoarrow.h
Lines 237 to 238 in 1a4bb88
| /// \brief Create a string view from a null-terminated string | |
| struct ArrowStringView ArrowCharView(const char* value); |
It's still a little awkward feeling if I convert keys to use struct ArrowStringView but I don't really mind either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a big deal for me either, though it is a little awkward to have the types differ between key/value even if there is a pragmatic reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change them to be the string views...anybody looking for convenience isn't writing C code anyway!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
| if (value == NULL) { | ||
| return NANOARROW_OK; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, to me it's a little weird to accept NULL as the value and then just do nothing with it. If we just considered append(key, NULL) to be an error, we could drop this, and then we could pass the views by value instead of indirecting through a pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these to be internal implementation details...the NULL mostly just helps with minimizing the number of times one has to copy a metadata string (correspondingly, I added ArrowMetadatBuilderRemove() to make it more explicit).
eae585a to
56f63d8
Compare
src/nanoarrow/typedefs_inline.h
Outdated
| out.data = value; | ||
| out.n_bytes = 0; | ||
| if (value) { | ||
| while (*value++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not strlen? to avoid the include?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes...too much of a hack? I'll check if string.h gets included in another inline file anyway (it probably does).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+I don't think it's a big deal to include string.h (it'll certainly raise less eyebrows than this)
Fixes #6.
This PR adds functions
ArrowMetadataBuilderAppend()(for blindly but efficiently adding a key/value pair to the end of some metadata) andArrowMetadataBuilderSet()(to less efficiently replace or remove a value for key).The use case I had in mind is building extension type metadata from some input (i.e., make an output schema like the input except with new extension type or with new serialized extension type metadata). It's rather difficult to replicate the "replace" or "remove" behaviour otherwise.