Skip to content

GH-50390: [Ruby] Add int/float array builder for red-arrow-format#50391

Merged
kou merged 1 commit into
apache:mainfrom
kou:ruby-primitive-builder
Jul 7, 2026
Merged

GH-50390: [Ruby] Add int/float array builder for red-arrow-format#50391
kou merged 1 commit into
apache:mainfrom
kou:ruby-primitive-builder

Conversation

@kou

@kou kou commented Jul 6, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Int array and float array use similar structure. We can share common code for builder API for them.

What changes are included in this PR?

Add ArrowFormat::PrimitiveArray#build_data.

Are these changes tested?

Yes.

Are there any user-facing changes?

Yes.

Copilot AI review requested due to automatic review settings July 6, 2026 13:20
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #50390 has been automatically assigned in GitHub to PR creator.

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 adds a shared “builder” path for Ruby primitive arrays in red-arrow-format by introducing ArrowFormat::PrimitiveArray#build_data, reducing duplicated construction logic across int/float arrays and consolidating primitive-array tests.

Changes:

  • Add PrimitiveArray#build_data and update PrimitiveArray#initialize to support constructing from Ruby arrays for numeric primitives.
  • Add pack_template to numeric type classes to drive binary packing for the new builder.
  • Consolidate boolean and numeric primitive array tests into test-primitive-array.rb (removing the standalone boolean test file).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
ruby/red-arrow-format/test/test-primitive-array.rb Adds consolidated coverage for boolean + numeric primitive array roundtrips via .new(values).to_a.
ruby/red-arrow-format/test/test-boolean-array.rb Removes now-redundant boolean-only test file.
ruby/red-arrow-format/lib/arrow-format/type.rb Introduces pack_template for numeric types to support the new builder’s packing.
ruby/red-arrow-format/lib/arrow-format/array.rb Implements shared primitive build/initialization logic and removes redundant subclass initializers.

Comment on lines +165 to 177
def initialize(*args)
if args.size == 1
args = build_data(args[0])
end
n_args = args.size
if args.size != 3
message = "wrong number of arguments (given #{n_args}, expected 1 or 3)"
raise ArgumentError, message
end
size, validity_buffer, values_buffer = args
super(self.class.type, size, validity_buffer)
@values_buffer = values_buffer
end
Comment on lines +165 to +167
def pack_template
"s"
end
@kou kou force-pushed the ruby-primitive-builder branch from 667033a to 3c43272 Compare July 6, 2026 13:39
Copilot AI review requested due to automatic review settings July 6, 2026 21:30
@kou kou force-pushed the ruby-primitive-builder branch from 3c43272 to f548db1 Compare July 6, 2026 21:30

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment on lines +165 to 183
def initialize(*args)
n_args = args.size
if self.class.respond_to?(:type)
type = self.class.type
expected_n_args = "1 or 3"
else
type = args.shift
expected_n_args = "2 or 4"
end
args = build_data(args[0]) if args.size == 1
if args.size != 3
message =
"wrong number of arguments (given #{n_args}, #{expected_n_args})"
raise ArgumentError, message
end
size, validity_buffer, values_buffer = args
super(type, size, validity_buffer)
@values_buffer = values_buffer
end
Comment on lines +206 to +211
def build_data(data)
n = 0
validity_buffer_builder = nil
buffer = +"".b
pack_template = self.class.type.pack_template
data.each_with_index do |value, i|
Comment on lines +165 to 171
def pack_template
"s"
end

def build_array(...)
Int16Array.new(...)
end
Comment on lines +83 to +93
def test_float32
values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
assert_equal(values,
ArrowFormat::Float32Array.new(values).to_a)
end

def test_float64
values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
assert_equal(values,
ArrowFormat::Float64Array.new(values).to_a)
end
@kou kou force-pushed the ruby-primitive-builder branch from f548db1 to 2e51534 Compare July 6, 2026 23:46
@kou

kou commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

+1

@kou kou merged commit dd69699 into apache:main Jul 7, 2026
33 checks passed
@kou kou removed the awaiting committer review Awaiting committer review label Jul 7, 2026
@kou kou deleted the ruby-primitive-builder branch July 7, 2026 00:22
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.

2 participants