Skip to content

GH-50385: [Ruby] Add bitmap builder for red-arrow-format#50386

Open
kou wants to merge 1 commit into
apache:mainfrom
kou:ruby-bitmap-builder
Open

GH-50385: [Ruby] Add bitmap builder for red-arrow-format#50386
kou wants to merge 1 commit into
apache:mainfrom
kou:ruby-bitmap-builder

Conversation

@kou

@kou kou commented Jul 6, 2026

Copy link
Copy Markdown
Member

Rationale for this change

It can be used for validity bitmap and boolean array.

What changes are included in this PR?

  • Add ArrowFormat::DenseBitmapBuilder
  • Add ArrowFormat::SparseBitmapBuilder
  • Add ArrowFormat::BooleanArray.new(values)
  • Use them in integration test

Are these changes tested?

Yes.

Are there any user-facing changes?

Yes.

Copilot AI review requested due to automatic review settings July 6, 2026 08:29
@github-actions github-actions Bot added the awaiting committer review Awaiting committer review label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #50385 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

Adds bitmap builder utilities to red-arrow-format to construct Arrow-compatible bitmaps (with 64-byte padding) for validity and boolean buffers, and migrates the integration JSON reader to use the new builder logic.

Changes:

  • Introduce ArrowFormat::DenseBitmapBuilder and ArrowFormat::SparseBitmapBuilder.
  • Add unit tests for both bitmap builders.
  • Update integration JSON reader bitmap construction to use DenseBitmapBuilder.

Reviewed changes

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

File Description
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb Adds dense/sparse bitmap builder implementations with 64-byte padding behavior.
ruby/red-arrow-format/lib/arrow-format/integration/json-reader.rb Switches JSON bitmap decoding to use the new dense bitmap builder.
ruby/red-arrow-format/test/test-dense-bitmap-builder.rb Adds unit tests for dense bitmap builder output and padding.
ruby/red-arrow-format/test/test-sparse-bitmap-builder.rb Adds unit tests for sparse bitmap builder output and padding.

Comment on lines +1 to +2
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
Comment on lines +38 to +41
padding_size = buffer_padding_size(@buffer)
@buffer.append_as_bytes(padding(padding_size)) if padding_size > 0
@buffer.freeze
IO::Buffer.for(@buffer)
Comment on lines +45 to +49
def flush
@buffer.append_as_bytes([@byte].pack("C"))
@n_bits = 0
@byte = 0
end
Comment on lines +64 to +85
def finish(size)
builder = DenseBitmapBuilder.new
not_set_value = @default
set_value = !@default
previous_index = 0
@indexes.sort.each do |index|
previous_index.upto(index - 1) do
builder.append(not_set_value)
end
builder.append(set_value)
previous_index = index + 1
end
if previous_index.zero?
n_remains = size
else
n_remains = size - previous_index
end
n_remains.times do
builder.append(not_set_value)
end
builder.finish
end
Comment on lines +17 to +18

class TestDenseBitmapBuilder < Test::Unit::TestCase
Comment on lines +17 to +18

class TestSparseBitmapBuilder < Test::Unit::TestCase
Comment on lines 207 to 211
def read_bitmap(bitmap)
buffer = +"".b
bitmap.each_slice(8) do |bits|
byte = 0
while bits.size < 8
bits << 0
end
bits.reverse_each do |bit|
byte = (byte << 1) + bit
end
buffer << [byte].pack("C")
builder = DenseBitmapBuilder.new
bitmap.each do |bit|
builder.append(bit == 1 ? true : false)
end
@kou kou force-pushed the ruby-bitmap-builder branch from 8f7481b to 355ab71 Compare July 6, 2026 08:37
Copilot AI review requested due to automatic review settings July 6, 2026 08:42
@kou kou force-pushed the ruby-bitmap-builder branch from 355ab71 to 6927fe1 Compare July 6, 2026 08:42

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@kou kou force-pushed the ruby-bitmap-builder branch from 6927fe1 to a826c10 Compare July 6, 2026 08:45
Copilot AI review requested due to automatic review settings July 6, 2026 08:46
@kou kou force-pushed the ruby-bitmap-builder branch from a826c10 to 611ce65 Compare July 6, 2026 08:46

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

Comment on lines +75 to +81
@indexes.keys.sort.each do |index|
previous_index.upto(index - 1) do
builder.append(not_set_value)
end
builder.append(set_value)
previous_index = index + 1
end
Comment on lines +61 to +63
def set(index)
@indexes[index] = true
end
Comment on lines +229 to +240
data.each_with_index do |value, i|
if value.nil?
validity_buffer_builder ||= SparseBitmapBuilder.new(true)
validity_buffer_builder.set(i)
values_buffer_builder.append(false)
elsif value
values_buffer_builder.append(true)
else
values_buffer_builder.append(false)
end
n += 1
end
@kou kou force-pushed the ruby-bitmap-builder branch from 611ce65 to b89c279 Compare July 6, 2026 09:08
Copilot AI review requested due to automatic review settings July 6, 2026 09:11
@kou kou force-pushed the ruby-bitmap-builder branch from b89c279 to 4a6adbf Compare July 6, 2026 09:11

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

Comment on lines +37 to +41
def finish
flush if @n_bits > 0
padding_size = buffer_padding_size(@buffer)
@buffer.append_as_bytes(padding(padding_size)) if padding_size > 0
@buffer.freeze
Comment on lines +46 to +50
def flush
@buffer.append_as_bytes([@byte].pack("C"))
@n_bits = 0
@byte = 0
end
Comment on lines +64 to +68
def finish(size)
builder = DenseBitmapBuilder.new
set_value = true
unset_value = false
if @unset_indexes.empty?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants