GH-50832: [Ruby] Add ArrowFormat::FixedSizeBinaryArray.new(byte_widt…h, values) - #50854
Draft
otegami wants to merge 1 commit into
Draft
GH-50832: [Ruby] Add ArrowFormat::FixedSizeBinaryArray.new(byte_widt…h, values)#50854otegami wants to merge 1 commit into
ArrowFormat::FixedSizeBinaryArray.new(byte_widt…h, values)#50854otegami wants to merge 1 commit into
Conversation
…e_width, values)` ### Rationale for this change Building a fixed size binary Arrow array from Ruby objects is convenient. ### What changes are included in this PR? Accept: * `ArrowFormat::FixedSizeBinaryArray.new(byte_width, values)` * `ArrowFormat::FixedSizeBinaryArray.new(type, values)` `ArrowFormat::FixedSizeBinaryType.try_convert` is added for the byte width shorthand, in the same way as `ArrowFormat::Time32Array.new(unit, values)`. The existing 4 arguments form is kept. Decimal arrays are out of scope. `ArrowFormat::DecimalArray#to_a` returns `BigDecimal`, so building one from Ruby objects needs a conversion between `BigDecimal` and two's complement. I would like to open a separate issue for it. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: apache#50832
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the Ruby red-arrow-format bindings to make it easier to construct ArrowFormat::FixedSizeBinaryArray instances from Ruby objects by accepting either a byte width shorthand (Integer) or a FixedSizeBinaryType, while keeping the existing 4-argument constructor form.
Changes:
- Extend
ArrowFormat::FixedSizeBinaryArray.newto accept(byte_width, values)and(type, values)shorthands. - Add
ArrowFormat::FixedSizeBinaryType.try_convertto support the byte-width shorthand conversion pattern used by other temporal types. - Add a dedicated test suite for
FixedSizeBinaryArrayinitialization and equality behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ruby/red-arrow-format/test/test-fixed-size-binary-array.rb | Adds test coverage for the new FixedSizeBinaryArray construction forms and basic behavior. |
| ruby/red-arrow-format/lib/arrow-format/type.rb | Adds FixedSizeBinaryType.try_convert to support shorthand conversion from Integer byte widths. |
| ruby/red-arrow-format/lib/arrow-format/array.rb | Implements the new FixedSizeBinaryArray initializer paths and builds buffers from Ruby values. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
885
to
889
|
|
||
| byte_width = @type.byte_width | ||
| values = 0.step(@size * byte_width - 1, byte_width).collect do |offset| | ||
| @values_buffer.get_string(offset, byte_width) | ||
| end |
Comment on lines
854
to
+858
| class FixedSizeBinaryArray < Array | ||
| def initialize(type, size, validity_buffer, values_buffer) | ||
| include BufferAlignable | ||
|
|
||
| def initialize(type, *args) | ||
| unless type.is_a?(Type) |
otegami
marked this pull request as draft
August 12, 2026 23:56
kou
reviewed
Aug 13, 2026
| values.append_as_bytes(null_value) | ||
| else | ||
| unless value.bytesize == byte_width | ||
| message = "value size must be #{byte_width}: #{value.bytesize}" |
Member
There was a problem hiding this comment.
Could you show the actual value for easy to debug?
Suggested change
| message = "value size must be #{byte_width}: #{value.bytesize}" | |
| message = "value size must be #{byte_width}: #{value.inspect}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Building a fixed size binary Arrow array from Ruby objects is convenient.
What changes are included in this PR?
Accept:
ArrowFormat::FixedSizeBinaryArray.new(byte_width, values)ArrowFormat::FixedSizeBinaryArray.new(type, values)ArrowFormat::FixedSizeBinaryType.try_convertis added for the byte width shorthand, in the same way asArrowFormat::Time32Array.new(unit, values). The existing 4 arguments form is kept.Decimal arrays are out of scope.
ArrowFormat::DecimalArray#to_areturnsBigDecimal, so building one from Ruby objects needs a conversion betweenBigDecimaland two's complement. I would like to open a separate issue for it.Are these changes tested?
Yes.
Are there any user-facing changes?
Yes.
ArrowFormat::FixedSizeBinaryArray.new(byte_width, values)#50832