Skip to content

GH-50832: [Ruby] Add ArrowFormat::FixedSizeBinaryArray.new(byte_widt…h, values) - #50854

Draft
otegami wants to merge 1 commit into
apache:mainfrom
otegami:feature/add-fixed-size-binary-constructor
Draft

GH-50832: [Ruby] Add ArrowFormat::FixedSizeBinaryArray.new(byte_widt…h, values)#50854
otegami wants to merge 1 commit into
apache:mainfrom
otegami:feature/add-fixed-size-binary-constructor

Conversation

@otegami

@otegami otegami commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

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.

…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
@otegami
otegami requested a review from kou as a code owner August 12, 2026 11:39
Copilot AI lite review requested due to automatic review settings August 12, 2026 11:39
@github-actions github-actions Bot added the awaiting review Awaiting review label Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.new to accept (byte_width, values) and (type, values) shorthands.
  • Add ArrowFormat::FixedSizeBinaryType.try_convert to support the byte-width shorthand conversion pattern used by other temporal types.
  • Add a dedicated test suite for FixedSizeBinaryArray initialization 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
otegami marked this pull request as draft August 12, 2026 23:56
values.append_as_bytes(null_value)
else
unless value.bytesize == byte_width
message = "value size must be #{byte_width}: #{value.bytesize}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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}"

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants