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 a4bcee3e38 GH-35681: [Ruby] Add support for #select_columns with empty 
table (#35682)
a4bcee3e38 is described below

commit a4bcee3e389f73669c64637c93cd691ee26b1cd2
Author: Sutou Kouhei <[email protected]>
AuthorDate: Sat May 20 04:50:09 2023 +0900

    GH-35681: [Ruby] Add support for #select_columns with empty table (#35682)
    
    ### Rationale for this change
    
    We can't use `garrow_chunked_array_combine()` with an empty 
`GArrowChunkedArray`.
    
    ### What changes are included in this PR?
    
    Create an empty array instead of combining with an empty 
`GArrowChunkedArray`.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    * Closes: #35681
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 ruby/red-arrow/lib/arrow/chunked-array.rb | 6 +++++-
 ruby/red-arrow/test/test-table.rb         | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ruby/red-arrow/lib/arrow/chunked-array.rb 
b/ruby/red-arrow/lib/arrow/chunked-array.rb
index dd0fb3bfbf..7d83becc6d 100644
--- a/ruby/red-arrow/lib/arrow/chunked-array.rb
+++ b/ruby/red-arrow/lib/arrow/chunked-array.rb
@@ -29,7 +29,11 @@ module Arrow
     end
 
     def to_arrow_array
-      combine
+      if n_chunks.zero?
+        value_data_type.build_array([])
+      else
+        combine
+      end
     end
 
     def to_arrow_chunked_array
diff --git a/ruby/red-arrow/test/test-table.rb 
b/ruby/red-arrow/test/test-table.rb
index 689f47384f..7c372bd44f 100644
--- a/ruby/red-arrow/test/test-table.rb
+++ b/ruby/red-arrow/test/test-table.rb
@@ -589,6 +589,13 @@ class TableTest < Test::Unit::TestCase
 0      1
       TABLE
     end
+
+    test("empty result") do
+      selected_table = @table.filter([false] * @table.size).select_columns(:a)
+      assert_equal(<<-TABLE, selected_table.to_s)
+       a
+      TABLE
+    end
   end
 
   sub_test_case("#column_names") do

Reply via email to