This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 50e3f75ffb GH-48437: [Ruby] Add tests for large list array (#48438)
50e3f75ffb is described below

commit 50e3f75ffb18056c47c88f02a5c31a9f846d2826
Author: Sutou Kouhei <[email protected]>
AuthorDate: Fri Dec 12 06:47:44 2025 +0900

    GH-48437: [Ruby] Add tests for large list array (#48438)
    
    ### Rationale for this change
    
    They should have been included in #48411.
    
    ### What changes are included in this PR?
    
    Add missing tests.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    No.
    * GitHub Issue: #48437
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 .../test/test-large-list-array-builder.rb          | 89 ++++++++++++++++++++++
 ruby/red-arrow/test/test-large-list-array.rb       | 32 ++++++++
 ruby/red-arrow/test/test-large-list-data-type.rb   | 69 +++++++++++++++++
 3 files changed, 190 insertions(+)

diff --git a/ruby/red-arrow/test/test-large-list-array-builder.rb 
b/ruby/red-arrow/test/test-large-list-array-builder.rb
new file mode 100644
index 0000000000..a2674daeb2
--- /dev/null
+++ b/ruby/red-arrow/test/test-large-list-array-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.
+
+class LargeListArrayBuilderTest < Test::Unit::TestCase
+  def setup
+    @data_type = Arrow::LargeListDataType.new(name: "visible", type: :boolean)
+    @builder = Arrow::LargeListArrayBuilder.new(@data_type)
+  end
+
+  sub_test_case("#append_value") do
+    test("nil") do
+      @builder.append_value(nil)
+      array = @builder.finish
+      assert_equal(nil, array[0])
+    end
+
+    test("Array") do
+      @builder.append_value([true, false, true])
+      array = @builder.finish
+      assert_equal([true, false, true], array[0].to_a)
+    end
+
+    test("Struct[]") do
+      item_type = Arrow::StructDataType.new([{name: "visible", type: 
:boolean}])
+      data_type = Arrow::LargeListDataType.new(name: "struct",
+                                               data_type: item_type)
+      builder = Arrow::LargeListArrayBuilder.new(data_type)
+      builder.append_value([])
+      array = builder.finish
+      assert_equal([[]], array.to_a)
+    end
+  end
+
+  sub_test_case("#append_values") do
+    test("[nil, Array]") do
+      @builder.append_values([[false], nil, [true, false, true]])
+      array = @builder.finish
+      assert_equal([
+                     [false],
+                     nil,
+                     [true, false, true],
+                   ],
+                   array.collect {|list| list ? list.to_a : nil})
+    end
+
+    test("is_valids") do
+      @builder.append_values([[false], [true, true], [true, false, true]],
+                             [true, false, true])
+      array = @builder.finish
+      assert_equal([
+                     [false],
+                     nil,
+                     [true, false, true],
+                   ],
+                   array.collect {|list| list ? list.to_a : nil})
+    end
+  end
+
+  sub_test_case("#append") do
+    test("backward compatibility") do
+      @builder.append
+      @builder.value_builder.append(true)
+      @builder.value_builder.append(false)
+      @builder.append
+      @builder.value_builder.append(true)
+      array = @builder.finish
+
+      assert_equal([
+                     [true, false],
+                     [true],
+                   ],
+                   array.collect(&:to_a))
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-large-list-array.rb 
b/ruby/red-arrow/test/test-large-list-array.rb
new file mode 100644
index 0000000000..b2ccfcf9da
--- /dev/null
+++ b/ruby/red-arrow/test/test-large-list-array.rb
@@ -0,0 +1,32 @@
+# 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 LargeListArrayTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    test("build") do
+      data_type = Arrow::LargeListDataType.new(name: "visible", type: :boolean)
+      values = [
+        [true, false],
+        nil,
+        [false, true, false],
+      ]
+      array = Arrow::LargeListArray.new(data_type, values)
+      assert_equal(values,
+                   array.collect {|value| value ? value.to_a : nil})
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-large-list-data-type.rb 
b/ruby/red-arrow/test/test-large-list-data-type.rb
new file mode 100644
index 0000000000..9c08ad594d
--- /dev/null
+++ b/ruby/red-arrow/test/test-large-list-data-type.rb
@@ -0,0 +1,69 @@
+# 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 LargeListDataTypeTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    test("Arrow::Field") do
+      field = Arrow::Field.new(:tag, :string)
+      assert_equal("large_list<tag: string>",
+                   Arrow::LargeListDataType.new(field).to_s)
+    end
+
+    test("name: String") do
+      assert_equal("large_list<tag: string>",
+                   Arrow::LargeListDataType.new(name: "tag", type: 
:string).to_s)
+    end
+
+    test("field: Arrow::Field") do
+      field = Arrow::Field.new(:tag, :string)
+      assert_equal("large_list<tag: string>",
+                   Arrow::LargeListDataType.new(field: field).to_s)
+    end
+
+    test("field: Hash") do
+      field_description = {name: "tag", type: :string}
+      assert_equal("large_list<tag: string>",
+                   Arrow::LargeListDataType.new(field: field_description).to_s)
+    end
+
+    test("Arrow::DataType") do
+      data_type = Arrow::BooleanDataType.new
+      assert_equal("large_list<item: bool>",
+                   Arrow::LargeListDataType.new(data_type).to_s)
+    end
+
+    test("String") do
+      assert_equal("large_list<item: bool>",
+                   Arrow::LargeListDataType.new("boolean").to_s)
+    end
+
+    test("Symbol") do
+      assert_equal("large_list<item: bool>",
+                   Arrow::LargeListDataType.new(:boolean).to_s)
+    end
+
+    test("[data type name, additional information]") do
+      assert_equal("large_list<item: time32[ms]>",
+                   Arrow::LargeListDataType.new([:time32, :milli]).to_s)
+    end
+
+    test("type: Symbol") do
+      assert_equal("large_list<item: bool>",
+                   Arrow::LargeListDataType.new(type: :boolean).to_s)
+    end
+  end
+end

Reply via email to