You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "kou (via GitHub)" <gi...@apache.org> on 2026/07/06 08:29:14 UTC
[PR] GH-50385: [Ruby] Add bitmap builder for red-arrow-format [arrow]
kou opened a new pull request, #50386:
URL: https://github.com/apache/arrow/pull/50386
### 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`
* Use them in integration test
### Are these changes tested?
Yes.
### Are there any user-facing changes?
Yes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50385: [Ruby] Add bitmap builder for red-arrow-format [arrow]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #50386:
URL: https://github.com/apache/arrow/pull/50386#discussion_r3527688802
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,88 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require_relative "buffer-alignable"
+
+module ArrowFormat
+ class DenseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @buffer = +"".b
+ @n_bits = 0
+ @byte = 0
+ end
+
+ def append(value)
+ @byte |= 1 << @n_bits if value
+ @n_bits += 1
+ flush if @n_bits == 8
+ self
+ end
+
+ 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
Review Comment:
`String#append_as_bytes` isn't used anywhere else in red-arrow-format and isn't part of Ruby's standard `String` API, so this may raise `NoMethodError` at runtime. Using `String#<<` (or `String#concat`) here would avoid relying on an extra monkey patch while keeping the same behavior.
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,88 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require_relative "buffer-alignable"
+
+module ArrowFormat
+ class DenseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @buffer = +"".b
+ @n_bits = 0
+ @byte = 0
+ end
+
+ def append(value)
+ @byte |= 1 << @n_bits if value
+ @n_bits += 1
+ flush if @n_bits == 8
+ self
+ end
+
+ 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
+ IO::Buffer.for(@buffer)
+ end
+
+ private
+ def flush
+ @buffer.append_as_bytes([@byte].pack("C"))
+ @n_bits = 0
+ @byte = 0
+ end
+ end
+
+ class SparseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @unset_indexes = {}
+ end
+
+ def unset(index)
+ @unset_indexes[index] = true
+ end
+
+ def finish(size)
+ builder = DenseBitmapBuilder.new
+ set_value = true
+ unset_value = false
+ if @unset_indexes.empty?
Review Comment:
`SparseBitmapBuilder#finish` doesn't validate that all `unset` indexes are within `0...size`. If a caller unsets an index >= size (or a negative index), this will currently append extra bits and return a bitmap longer than the requested size, which will corrupt downstream consumers.
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,88 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require_relative "buffer-alignable"
+
+module ArrowFormat
+ class DenseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @buffer = +"".b
+ @n_bits = 0
+ @byte = 0
+ end
+
+ def append(value)
+ @byte |= 1 << @n_bits if value
+ @n_bits += 1
+ flush if @n_bits == 8
+ self
+ end
+
+ 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
+ IO::Buffer.for(@buffer)
+ end
+
+ private
+ def flush
+ @buffer.append_as_bytes([@byte].pack("C"))
+ @n_bits = 0
+ @byte = 0
+ end
Review Comment:
Same concern as in `finish`: `append_as_bytes` is not referenced anywhere else in this codebase and is not a standard `String` method, so this may fail at runtime. Prefer appending with `<<` to keep the builder self-contained.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50385: [Ruby] Add bitmap builder for red-arrow-format [arrow]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #50386:
URL: https://github.com/apache/arrow/pull/50386#discussion_r3527464984
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,87 @@
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
Review Comment:
The ASF license header is missing the standard first line ("Licensed to the Apache Software Foundation (ASF) under one"). This makes the header inconsistent with most Ruby files in this repo and can trip automated license/header checks.
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,87 @@
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require_relative "buffer-alignable"
+
+module ArrowFormat
+ class DenseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @buffer = +"".b
+ @n_bits = 0
+ @byte = 0
+ end
+
+ def append(value)
+ @byte |= 1 << @n_bits if value
+ @n_bits += 1
+ flush if @n_bits == 8
+ self
+ end
+
+ 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
+ IO::Buffer.for(@buffer)
+ end
+
+ private
+ def flush
+ @buffer.append_as_bytes([@byte].pack("C"))
+ @n_bits = 0
+ @byte = 0
+ end
Review Comment:
`String#append_as_bytes` is likely not available on supported Ruby versions; `flush` should append the packed byte using standard `String#<<` to avoid a runtime `NoMethodError`.
##########
ruby/red-arrow-format/test/test-dense-bitmap-builder.rb:
##########
@@ -0,0 +1,45 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestDenseBitmapBuilder < Test::Unit::TestCase
Review Comment:
This test references `ArrowFormat::DenseBitmapBuilder`, but `test/helper.rb` only requires `arrow-format` (which doesn't load `arrow-format/bitmap-builder`). Add an explicit require so the test doesn't depend on incidental load order.
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,87 @@
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require_relative "buffer-alignable"
+
+module ArrowFormat
+ class DenseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @buffer = +"".b
+ @n_bits = 0
+ @byte = 0
+ end
+
+ def append(value)
+ @byte |= 1 << @n_bits if value
+ @n_bits += 1
+ flush if @n_bits == 8
+ self
+ end
+
+ 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
+ IO::Buffer.for(@buffer)
+ end
+
+ private
+ def flush
+ @buffer.append_as_bytes([@byte].pack("C"))
+ @n_bits = 0
+ @byte = 0
+ end
+ end
+
+ class SparseBitmapBuilder
+ include BufferAlignable
+
+ def initialize(default)
+ @default = default
+ @indexes = []
+ end
+
+ def set(index)
+ @indexes << index
+ end
+
+ 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
Review Comment:
`SparseBitmapBuilder#finish` can silently generate an incorrect bitmap when `set` is called with duplicate indices (it will emit extra bits) or with indices outside `[0, size)` (it can emit more than `size` bits). De-duplicate and validate indices/size so output length is always exactly `size` bits.
##########
ruby/red-arrow-format/test/test-sparse-bitmap-builder.rb:
##########
@@ -0,0 +1,48 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestSparseBitmapBuilder < Test::Unit::TestCase
Review Comment:
This test references `ArrowFormat::SparseBitmapBuilder`, but `test/helper.rb` only requires `arrow-format` (which doesn't load `arrow-format/bitmap-builder`). Add an explicit require so the test doesn't depend on incidental load order.
##########
ruby/red-arrow-format/lib/arrow-format/integration/json-reader.rb:
##########
@@ -205,18 +205,11 @@ def read_schema
end
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
Review Comment:
`read_bitmap` now relies on `DenseBitmapBuilder`, but this integration file doesn't require the new builder. To make it robust to load order (and avoid `NameError`), ensure the builder file is required before instantiating it.
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,87 @@
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require_relative "buffer-alignable"
+
+module ArrowFormat
+ class DenseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @buffer = +"".b
+ @n_bits = 0
+ @byte = 0
+ end
+
+ def append(value)
+ @byte |= 1 << @n_bits if value
+ @n_bits += 1
+ flush if @n_bits == 8
+ self
+ end
+
+ 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
+ IO::Buffer.for(@buffer)
Review Comment:
`String#append_as_bytes` is not used anywhere else in this codebase and may not exist on supported Ruby versions, which would make `finish` crash at runtime. Use standard `String#<<`/`String#concat` instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50385: [Ruby] Add bitmap builder for red-arrow-format [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #50386:
URL: https://github.com/apache/arrow/pull/50386#issuecomment-4900271415
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 65709698477fd8a8405f97e7b28a0e903cb89bf1.
There were no benchmark performance regressions. ๐
The [full Conbench report](https://github.com/apache/arrow/runs/85539273976) has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50385: [Ruby] Add bitmap builder for red-arrow-format [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #50386:
URL: https://github.com/apache/arrow/pull/50386#issuecomment-4890710127
:warning: GitHub issue #50385 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50385: [Ruby] Add bitmap builder for red-arrow-format [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #50386:
URL: https://github.com/apache/arrow/pull/50386#issuecomment-4892825768
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50385: [Ruby] Add bitmap builder for red-arrow-format [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #50386:
URL: https://github.com/apache/arrow/pull/50386
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50385: [Ruby] Add bitmap builder for red-arrow-format [arrow]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #50386:
URL: https://github.com/apache/arrow/pull/50386#discussion_r3527582316
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,89 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require_relative "buffer-alignable"
+
+module ArrowFormat
+ class DenseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @buffer = +"".b
+ @n_bits = 0
+ @byte = 0
+ end
+
+ def append(value)
+ @byte |= 1 << @n_bits if value
+ @n_bits += 1
+ flush if @n_bits == 8
+ self
+ end
+
+ 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
+ IO::Buffer.for(@buffer)
+ end
+
+ private
+ def flush
+ @buffer.append_as_bytes([@byte].pack("C"))
+ @n_bits = 0
+ @byte = 0
+ end
+ end
+
+ class SparseBitmapBuilder
+ include BufferAlignable
+
+ def initialize(default)
+ @default = default
+ @indexes = {}
+ end
+
+ def set(index)
+ @indexes[index] = true
+ end
+
+ def finish(size)
+ builder = DenseBitmapBuilder.new
+ not_set_value = @default
+ set_value = !@default
+ if @indexes.empty?
+ size.times do
+ builder.append(not_set_value)
+ end
+ else
+ previous_index = 0
+ @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
Review Comment:
`SparseBitmapBuilder#finish` can generate a bitmap larger than the requested `size` if `set` was called with an index < 0 or >= `size`. This silently produces extra bits/bytes and can lead to invalid Arrow buffers (buffer length no longer matches the logical bitmap size). Consider validating indexes during `finish` (or in `set`) and raising an ArgumentError when out of range.
##########
ruby/red-arrow-format/lib/arrow-format/bitmap-builder.rb:
##########
@@ -0,0 +1,89 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require_relative "buffer-alignable"
+
+module ArrowFormat
+ class DenseBitmapBuilder
+ include BufferAlignable
+
+ def initialize
+ @buffer = +"".b
+ @n_bits = 0
+ @byte = 0
+ end
+
+ def append(value)
+ @byte |= 1 << @n_bits if value
+ @n_bits += 1
+ flush if @n_bits == 8
+ self
+ end
+
+ 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
+ IO::Buffer.for(@buffer)
+ end
+
+ private
+ def flush
+ @buffer.append_as_bytes([@byte].pack("C"))
+ @n_bits = 0
+ @byte = 0
+ end
+ end
+
+ class SparseBitmapBuilder
+ include BufferAlignable
+
+ def initialize(default)
+ @default = default
+ @indexes = {}
+ end
+
+ def set(index)
+ @indexes[index] = true
+ end
Review Comment:
`SparseBitmapBuilder#set` always writes the *non-default* value (it flips `default`) and doesn't allow setting an explicit bit value. With a `default` of `true`, calling `set(index)` actually clears the bit, which is surprising for a public API and easy to misuse. Consider renaming this method (e.g., `mark`, `flip`, `set_not_default`) or changing the API to accept an explicit value (e.g., `set(index, value)`).
##########
ruby/red-arrow-format/lib/arrow-format/array.rb:
##########
@@ -210,6 +221,26 @@ def clear_cache
super
@values_bitmap = nil
end
+
+ def build_data(data)
+ n = 0
+ validity_buffer_builder = nil
+ values_buffer_builder = DenseBitmapBuilder.new
+ 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
Review Comment:
`BooleanArray.new(values)` currently treats any truthy Ruby object as `true` (e.g., `0`, `"false"`, `Object.new`), which can silently encode unexpected values into a BooleanArray. Since this is a new user-facing constructor, itโs safer to require elements to be `true`, `false`, or `nil` and raise for anything else.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org