You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "emecii (via GitHub)" <gi...@apache.org> on 2026/09/09 12:20:30 UTC

[PR] GH-51262: [Ruby] Add ListArray values constructor [arrow]

emecii opened a new pull request, #51263:
URL: https://github.com/apache/arrow/pull/51263

   ### Rationale for this change
   
   GH-50382 identified list arrays as a prerequisite for a consistent public typed-array builder API. This adds the separately requested list constructor.
   
   ### What changes are included in this PR?
   
   * Add `ArrowFormat::ListArray.new(type, values)` while preserving the existing buffer-based constructor.
   * Build list validity, offsets, and the child array from nested Ruby values using the declared child type.
   * Cover empty lists, null lists, and null child values.
   
   ### Are these changes tested?
   
   Yes. The `red-arrow-format` suite passes locally (694 tests, 705 assertions).
   
   ### Are there any user-facing changes?
   
   Yes. Callers can construct an `ArrowFormat::ListArray` directly from a list type and nested Ruby values.
   
   ### AI assistance
   
   AI assistance drafted the implementation and tests. The final patch was reviewed against the existing typed constructors and low-level list array representation, and the focused and full package tests were run locally.
   
   * GitHub Issue: #51262
   


-- 
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-51262: [Ruby] Add ListArray values constructor [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #51263:
URL: https://github.com/apache/arrow/pull/51263


-- 
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-51262: [Ruby] Add ListArray values constructor [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #51263:
URL: https://github.com/apache/arrow/pull/51263#discussion_r3976418550


##########
ruby/red-arrow-format/test/test-list-array.rb:
##########
@@ -0,0 +1,56 @@
+# 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 TestListArray < Test::Unit::TestCase
+  def setup
+    child = ArrowFormat::Field.new("item", ArrowFormat::Int32Type.singleton)
+    @type = ArrowFormat::ListType.new(child)
+  end
+
+  sub_test_case("#initialize") do
+    def test_no_null
+      values = [[-1, 0], [], [1, 2, 3]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_same(@type, array.type)
+      assert_equal(values, array.to_a)
+    end
+
+    def test_null_list
+      values = [[1, 2], nil, [], [3]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_equal([0, 2, 2, 2, 3], array.offsets)
+      assert_equal(1, array.n_nulls)

Review Comment:
   We don't need this because `assert_equal(values, array.to_a)` checks this too.
   
   ```suggestion
   ```



##########
ruby/red-arrow-format/test/test-list-array.rb:
##########
@@ -0,0 +1,56 @@
+# 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 TestListArray < Test::Unit::TestCase
+  def setup
+    child = ArrowFormat::Field.new("item", ArrowFormat::Int32Type.singleton)
+    @type = ArrowFormat::ListType.new(child)
+  end
+
+  sub_test_case("#initialize") do
+    def test_no_null
+      values = [[-1, 0], [], [1, 2, 3]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_same(@type, array.type)
+      assert_equal(values, array.to_a)
+    end
+
+    def test_null_list
+      values = [[1, 2], nil, [], [3]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_equal([0, 2, 2, 2, 3], array.offsets)
+      assert_equal(1, array.n_nulls)
+      assert_equal([1, 2, 3], array.child.to_a)
+      assert_equal(values, array.to_a)
+    end
+
+    def test_null_child
+      values = [[1, nil], [], [nil, 2]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_equal(2, array.child.n_nulls)

Review Comment:
   We can remove this:
   
   ```suggestion
   ```



-- 
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-51262: [Ruby] Add ListArray values constructor [arrow]

Posted by "emecii (via GitHub)" <gi...@apache.org>.
emecii commented on code in PR #51263:
URL: https://github.com/apache/arrow/pull/51263#discussion_r3976636086


##########
ruby/red-arrow-format/test/test-list-array.rb:
##########
@@ -0,0 +1,56 @@
+# 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 TestListArray < Test::Unit::TestCase
+  def setup
+    child = ArrowFormat::Field.new("item", ArrowFormat::Int32Type.singleton)
+    @type = ArrowFormat::ListType.new(child)
+  end
+
+  sub_test_case("#initialize") do
+    def test_no_null
+      values = [[-1, 0], [], [1, 2, 3]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_same(@type, array.type)
+      assert_equal(values, array.to_a)
+    end
+
+    def test_null_list
+      values = [[1, 2], nil, [], [3]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_equal([0, 2, 2, 2, 3], array.offsets)
+      assert_equal(1, array.n_nulls)

Review Comment:
   Removed the parent null-count assertion in 665a620534cb38e75c9b4a3244db85e1b307e3d1. The value round-trip assertion remains; all four focused tests pass.



##########
ruby/red-arrow-format/test/test-list-array.rb:
##########
@@ -0,0 +1,56 @@
+# 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 TestListArray < Test::Unit::TestCase
+  def setup
+    child = ArrowFormat::Field.new("item", ArrowFormat::Int32Type.singleton)
+    @type = ArrowFormat::ListType.new(child)
+  end
+
+  sub_test_case("#initialize") do
+    def test_no_null
+      values = [[-1, 0], [], [1, 2, 3]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_same(@type, array.type)
+      assert_equal(values, array.to_a)
+    end
+
+    def test_null_list
+      values = [[1, 2], nil, [], [3]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_equal([0, 2, 2, 2, 3], array.offsets)
+      assert_equal(1, array.n_nulls)
+      assert_equal([1, 2, 3], array.child.to_a)
+      assert_equal(values, array.to_a)
+    end
+
+    def test_null_child
+      values = [[1, nil], [], [nil, 2]]
+      array = ArrowFormat::ListArray.new(@type, values)
+      assert_equal(2, array.child.n_nulls)

Review Comment:
   Removed the child null-count assertion in 665a620534cb38e75c9b4a3244db85e1b307e3d1. The value round-trip assertion remains; all four focused tests pass.



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