This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 9ac4259417 GH-15085: [Ruby] Add ColumnContainable#column_names (#15089)
9ac4259417 is described below
commit 9ac425941722c07b61331cea1ea0170a936de8be
Author: Hirokazu SUZUKI <[email protected]>
AuthorDate: Tue Dec 27 16:02:54 2022 +0900
GH-15085: [Ruby] Add ColumnContainable#column_names (#15089)
### What I did
* Add `ColumnContainable#column_names`.
* Returns `columns.collect(&:name)`.
* Add tests for the tables that have unique keys and same keys.
* Add document.
### What I didn't
* Check whole code to be replaced for it.
### What I checked
* It works as a method Table#keys in RedAmber using refinements.
### Notes for reviewers
* I will search the code which should be replaced if reviewer requested me.
### Related Issue
* Closes: #15085
Lead-authored-by: Hirokazu SUZUKI (heronshoes) <[email protected]>
Co-authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
ruby/red-arrow/lib/arrow/column-containable.rb | 9 +++++++++
ruby/red-arrow/test/test-table.rb | 12 ++++++++++++
2 files changed, 21 insertions(+)
diff --git a/ruby/red-arrow/lib/arrow/column-containable.rb
b/ruby/red-arrow/lib/arrow/column-containable.rb
index 7d7de66bda..002dcdb5b0 100644
--- a/ruby/red-arrow/lib/arrow/column-containable.rb
+++ b/ruby/red-arrow/lib/arrow/column-containable.rb
@@ -143,5 +143,14 @@ module Arrow
find_column(selector)
end
end
+
+ # Return column names in this object.
+ #
+ # @return [::Array<String>] column names.
+ #
+ # @since 11.0.0
+ def column_names
+ @column_names ||= columns.collect(&:name)
+ end
end
end
diff --git a/ruby/red-arrow/test/test-table.rb
b/ruby/red-arrow/test/test-table.rb
index 8e1ba74df0..a5ca6a821e 100644
--- a/ruby/red-arrow/test/test-table.rb
+++ b/ruby/red-arrow/test/test-table.rb
@@ -602,6 +602,18 @@ class TableTest < Test::Unit::TestCase
end
end
+ sub_test_case("#column_names") do
+ test("unique") do
+ table = Arrow::Table.new(a: [1], b: [2], c: [3])
+ assert_equal(%w[a b c], table.column_names)
+ end
+
+ test("duplicated") do
+ table = Arrow::Table.new([["a", [1, 2, 3]], ["a", [4, 5, 6]]])
+ assert_equal(%w[a a], table.column_names)
+ end
+ end
+
sub_test_case("#save and .load") do
module SaveLoadFormatTests
def test_default