From 71c4b88352096ca48b9798c802c288b4990900a7 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 31 Dec 2024 15:47:36 +0900 Subject: [PATCH] GH-45119: [Ruby] Use #size for Arrow::Column#size backend (#45133) ### Rationale for this change `#n_rows` is available only on `Arrow::ChunkedArray`. It's not available on `Arrow::Array`. ### What changes are included in this PR? It's available on both of `Arrow::Array` and `Arrow::ChunkedArray`. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #45119 Authored-by: Sutou Kouhei Signed-off-by: Sutou Kouhei --- ruby/red-arrow/lib/arrow/column.rb | 8 ++++---- ruby/red-arrow/test/test-column.rb | 8 ++++++++ ruby/red-arrow/test/test-record-batch.rb | 6 ++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ruby/red-arrow/lib/arrow/column.rb b/ruby/red-arrow/lib/arrow/column.rb index ba575381eefdc..a1de0d61282c2 100644 --- a/ruby/red-arrow/lib/arrow/column.rb +++ b/ruby/red-arrow/lib/arrow/column.rb @@ -58,11 +58,11 @@ def reverse_each(&block) @data.reverse_each(&block) end - def n_rows - @data.n_rows + def size + @data.size end - alias_method :size, :n_rows - alias_method :length, :n_rows + alias_method :length, :size + alias_method :n_rows, :size def n_nulls @data.n_nulls diff --git a/ruby/red-arrow/test/test-column.rb b/ruby/red-arrow/test/test-column.rb index f78377e363ba4..c3a6ee0f4d34f 100644 --- a/ruby/red-arrow/test/test-column.rb +++ b/ruby/red-arrow/test/test-column.rb @@ -49,6 +49,14 @@ def setup assert_equal([false, nil, true], @column.reverse_each.to_a) end + test("#size") do + assert_equal(3, @column.size) + end + + test("#length") do + assert_equal(3, @column.length) + end + test("#n_rows") do assert_equal(3, @column.n_rows) end diff --git a/ruby/red-arrow/test/test-record-batch.rb b/ruby/red-arrow/test/test-record-batch.rb index e94c26f2e329b..fec640343c60a 100644 --- a/ruby/red-arrow/test/test-record-batch.rb +++ b/ruby/red-arrow/test/test-record-batch.rb @@ -178,5 +178,11 @@ def setup @record_batch[[:c, "a", -1, 3..4]]) end end + + sub_test_case("#column") do + test("#size") do + assert_equal(@counts.size, @record_batch[:count].size) + end + end end end