fix: arrow_buffer:size/1 use 64 byte padding not 8 - #114
Conversation
Previously, arrow_buffer:size/1 took 8 byte padding to calculate size when the buffers actually used 64 bytes. This resulted in various gross errors in offsets and other metadata, rendering any IPC binaries produced unusable.
|
Preview URL: https://Benjamin-Philip.github.io/arrow-erlang-1 If the preview URL doesn't work, you may have forgotten to configure your fork repository for preview. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/arrow_buffer.erl:120
arrow_buffer:size/1can legally return0for empty buffers (e.g. arrays created from[]end up withBuffer#buffer.length = 0), but the spec currently claimspos_integer(). This will likely trigger Dialyzer warnings and is inconsistent with the implementation.
-spec size(Buffer :: arrow_buffer:buffer()) -> pos_integer().
size(Buffer) ->
Len = Buffer#buffer.length,
Len + arrow_utils:pad_len(Len).
@kou, according to https://arrow.apache.org/docs/format/Columnar.html#buffer-alignment-and-padding, do empty buffers need to be padded? Right now, I'm taking 0 to be a multiple of 64, so I'm not padding. If we do need to pad 0-bit buffers, I'll have to fix that. As of now, Copilot is right. |
|
For now I've fixed the typespec assuming no padding for 0-bit buffers, in the interest of time. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/arrow_buffer.erl:123
size/1doesn’t validate its input (unliketo_arrow/1andto_erlang/1). Passing a non-#buffer{} will currently raise a low-levelbadrecorderror instead of the module’s consistentbadargcontract.
size(Buffer) ->
Len = Buffer#buffer.length,
Len + arrow_utils:pad_len(Len).
This is fine. |
kou
left a comment
There was a problem hiding this comment.
+1
We don't need 64 bits padding for 0 bytes buffer.
What issue does this PR close?
Closes #113.
Previously, arrow_buffer:size/1 took 8 byte padding to calculate size
when the buffers actually used 64 bytes. This resulted in various gross
errors in offsets and other metadata, rendering any IPC binaries
produced unusable.
What's Changed
arrow_buffer:size/1now correctly uses 64 byte padding. Record Batch test datahas been updated with the correct offsets.