Skip to content

GH-50432: [Ruby] Add ArrowFormat::{Array,Bitmap}#==#50433

Merged
kou merged 1 commit into
apache:mainfrom
kou:ruby-array-equal
Jul 9, 2026
Merged

GH-50432: [Ruby] Add ArrowFormat::{Array,Bitmap}#==#50433
kou merged 1 commit into
apache:mainfrom
kou:ruby-array-equal

Conversation

@kou

@kou kou commented Jul 9, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Comparing 2 bitmaps/arrays is a common operation. We should provide content based (not identity based) comparition feature.

What changes are included in this PR?

  • Add ArrowFormat::Bitmap#==
  • Add ArrowFormat::Bitmap#offset
  • Add ArrowFormat::Bitmap#size
  • Add ArrowFormat::Bitmap#length
  • Make ArrowFormat::Array enumerable
  • Add ArrowFormat::Array#==
  • Add ArrowFormat::NullArray#each
  • Add ArrowFormat::PrimiveArray#each
  • Add ArrowFormat::BooleanArray#each

Are these changes tested?

Yes.

Are there any user-facing changes?

Yes.

Copilot AI review requested due to automatic review settings July 9, 2026 03:12
@kou kou force-pushed the ruby-array-equal branch from 822323d to de71398 Compare July 9, 2026 03:12
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

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

@github-actions github-actions Bot added awaiting review Awaiting review awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Jul 9, 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

Adds content-based equality and iteration support to the Ruby red-arrow-format ArrowFormat::Bitmap and ArrowFormat::Array hierarchy, and restructures tests to validate #== behavior across primitive types.

Changes:

  • Add ArrowFormat::Bitmap#== plus readers/aliases (offset, size, length) and adjust iteration to use @size.
  • Make ArrowFormat::Array Enumerable, add/extend #each implementations for NullArray / PrimitiveArray / BooleanArray, and add #== implementations.
  • Replace the monolithic primitive array test with per-type test files, adding explicit #== slice tests.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ruby/red-arrow-format/lib/arrow-format/bitmap.rb Adds bitmap sizing APIs and content-based equality.
ruby/red-arrow-format/lib/arrow-format/array.rb Adds Enumerable, #each, and #== for arrays and key subclasses.
ruby/red-arrow-format/test/test-bitmap.rb Adds bitmap equality tests.
ruby/red-arrow-format/test/test-boolean-array.rb Adds boolean array init and equality tests.
ruby/red-arrow-format/test/test-null-array.rb Adds null array init and equality tests.
ruby/red-arrow-format/test/test-int8-array.rb Adds int8 array init and equality tests.
ruby/red-arrow-format/test/test-int16-array.rb Adds int16 array init and equality tests.
ruby/red-arrow-format/test/test-int32-array.rb Adds int32 array init and equality tests.
ruby/red-arrow-format/test/test-int64-array.rb Adds int64 array init and equality tests.
ruby/red-arrow-format/test/test-uint8-array.rb Adds uint8 array init and equality tests.
ruby/red-arrow-format/test/test-uint16-array.rb Adds uint16 array init and equality tests.
ruby/red-arrow-format/test/test-uint32-array.rb Adds uint32 array init and equality tests.
ruby/red-arrow-format/test/test-uint64-array.rb Adds uint64 array init and equality tests.
ruby/red-arrow-format/test/test-float32-array.rb Adds float32 array init and equality tests.
ruby/red-arrow-format/test/test-float64-array.rb Adds float64 array init and equality tests.
ruby/red-arrow-format/test/test-primitive-array.rb Removes the prior consolidated primitive-array test file.
Comments suppressed due to low confidence (1)

ruby/red-arrow-format/lib/arrow-format/array.rb:34

  • ArrowFormat::Array now includes Enumerable, but the class itself doesn’t define #each. Many subclasses (e.g., VariableSizeBinaryArray, FixedSizeBinaryArray, list/struct/union, etc.) also don’t implement #each, so map, zip, and other Enumerable methods will raise NoMethodError on those arrays. Add a fallback Array#each implementation (subclasses like NullArray / PrimitiveArray / BooleanArray can still override it for efficiency).
  class Array
    include Enumerable

    attr_reader :type
    attr_reader :size
    alias_method :length, :size
    attr_reader :offset
    attr_reader :validity_buffer
    def initialize(type, size, validity_buffer)

Comment on lines +69 to +78
def ==(other)
return false unless other.is_a?(self.class)
return true if @validity_buffer.nil? and other.validity_buffer.nil?
if @offset == other.offset and
@size == other.size and
@validity_buffer == other.validity_buffer
return true
end
validity_bitmap == other.validity_bitmap
end
expected_n_args = "2 or 4"
end
args = build_data(args[0], type) if args.size == 1
args = build_data(args[0], type) if n_args == 1
Comment on lines +248 to +258
def ==(other)
return false unless super(other)
if @offset == other.offset and
@size == other.size and
@values_buffer == other.values_buffer
return true
end
zip(other).all? do |value, other_value|
value == other_value
end
end
Copilot AI review requested due to automatic review settings July 9, 2026 04:29
@kou kou force-pushed the ruby-array-equal branch from de71398 to c3cc68d Compare July 9, 2026 04:29
@kou kou force-pushed the ruby-array-equal branch from c3cc68d to 600a7e9 Compare July 9, 2026 04: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 16 out of 16 changed files in this pull request and generated 3 comments.

Comment on lines +31 to 37
def ==(other)
return false unless other.is_a?(self.class)
return false unless @size == other.size
zip(other).all? do |bit, other_bit|
bit == other_bit
end
end
Comment on lines 65 to +69
def empty?
@size.zero?
end

def ==(other)
Comment on lines +247 to +255
def ==(other)
return false unless super(other)
if @offset == other.offset and @values_buffer == other.values_buffer
return true
end
zip(other).all? do |value, other_value|
value == other_value
end
end
Copilot AI review requested due to automatic review settings July 9, 2026 04:36

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 16 out of 16 changed files in this pull request and generated 3 comments.

Comment on lines +69 to +73
def ==(other)
return false unless other.is_a?(self.class)
return false unless @size == other.size
return true if @validity_buffer.nil? and other.validity_buffer.nil?
if @offset == other.offset and @validity_buffer == other.validity_buffer
Comment on lines +247 to +255
def ==(other)
return false unless super(other)
if @offset == other.offset and @values_buffer == other.values_buffer
return true
end
zip(other).all? do |value, other_value|
value == other_value
end
end
Comment on lines +34 to +36
zip(other).all? do |bit, other_bit|
bit == other_bit
end
Copilot AI review requested due to automatic review settings July 9, 2026 04:54
@kou kou force-pushed the ruby-array-equal branch from 600a7e9 to fbf7513 Compare July 9, 2026 04:54

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 16 out of 16 changed files in this pull request and generated 2 comments.

Comment on lines +69 to +73
def ==(other)
return false unless other.is_a?(self.class)
return false unless @size == other.size
return true if @validity_buffer.nil? and other.validity_buffer.nil?
if @offset == other.offset and @validity_buffer == other.validity_buffer
assert_equal(array1, array2.slice(1, 3))
end

def test_sliced_diffrent_content
Comparing 2 bitmaps/arrays is a common operation. We should provide
content based (not identity based) comparition feature.
@kou kou force-pushed the ruby-array-equal branch from fbf7513 to 4040e58 Compare July 9, 2026 05:12
Copilot AI review requested due to automatic review settings July 9, 2026 05:12

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 16 out of 16 changed files in this pull request and generated 2 comments.

Comment on lines +69 to +77
def ==(other)
return false unless other.is_a?(self.class)
return false unless @size == other.size
return true if @validity_buffer.nil? and other.validity_buffer.nil?
if @offset == other.offset and @validity_buffer == other.validity_buffer
return true
end
validity_bitmap == other.validity_bitmap
end
Comment on lines +69 to +71
def ==(other)
return false unless other.is_a?(self.class)
return false unless @size == other.size
@kou

kou commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

+1

@kou kou merged commit e191b95 into apache:main Jul 9, 2026
32 of 33 checks passed
@kou kou deleted the ruby-array-equal branch July 9, 2026 06:15
@kou kou removed the awaiting committer review Awaiting committer review label Jul 9, 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.

2 participants