-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-15222: [Ruby] Use Compute for Enum operations on Column #12053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-15222: [Ruby] Use Compute for Enum operations on Column #12053
Conversation
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about implementing them in Arrow::ChunkedArray (and Arrow::Array) with a Module and calling them in Arrow::Column?
diff --git a/ruby/red-arrow/lib/arrow/array-computable.rb b/ruby/red-arrow/lib/arrow/array-computable.rb
new file mode 100644
index 0000000000..850623616a
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/array-computable.rb
@@ -0,0 +1,37 @@
+# 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.
+
+module Arrow
+ module ArrayComputable
+ def min(options: nil)
+ compute("min", options: options)
+ end
+
+ def max(options: nil)
+ compute("max", options: options)
+ end
+
+ def uniq
+ unique.values
+ end
+
+ private
+ def compute(name, options: nil)
+ Function.find(name).execute([self], options).value
+ end
+ end
+end
diff --git a/ruby/red-arrow/lib/arrow/array.rb b/ruby/red-arrow/lib/arrow/array.rb
index c6c0daaec5..5100674f14 100644
--- a/ruby/red-arrow/lib/arrow/array.rb
+++ b/ruby/red-arrow/lib/arrow/array.rb
@@ -18,6 +18,8 @@
module Arrow
class Array
include Enumerable
+
+ include ArrayComputable
include GenericFilterable
include GenericTakeable
diff --git a/ruby/red-arrow/lib/arrow/chunked-array.rb b/ruby/red-arrow/lib/arrow/chunked-array.rb
index 30dffa856b..b8e3faed99 100644
--- a/ruby/red-arrow/lib/arrow/chunked-array.rb
+++ b/ruby/red-arrow/lib/arrow/chunked-array.rb
@@ -18,6 +18,8 @@
module Arrow
class ChunkedArray
include Enumerable
+
+ include ArrayComputable
include GenericFilterable
include GenericTakeable
@@ -87,5 +89,17 @@ module Arrow
first_chunk.class.new(to_a)
end
end
+
+ def count(options: nil)
+ compute("count", options: options)
+ end
+
+ def sum(options: nil)
+ compute("sum", options: options)
+ end
+
+ def unique
+ compute("unique")
+ end
end
end
diff --git a/ruby/red-arrow/lib/arrow/column.rb b/ruby/red-arrow/lib/arrow/column.rb
index 06f3dbdc05..da3f06a065 100644
--- a/ruby/red-arrow/lib/arrow/column.rb
+++ b/ruby/red-arrow/lib/arrow/column.rb
@@ -72,5 +72,25 @@ module Arrow
@field == other.field and
@data == other.data
end
+
+ def count(options: nil)
+ @data.count(options: options)
+ end
+
+ def sum(options: nil)
+ @data.sum(options: options)
+ end
+
+ def min(options: nil)
+ @data.min(options: options)
+ end
+
+ def max(options: nil)
+ @data.max(options: options)
+ end
+
+ def unique
+ @data.unique
+ end
+
+ def uniq
+ @data.uniq
+ end
end
end
diff --git a/ruby/red-arrow/lib/arrow/loader.rb b/ruby/red-arrow/lib/arrow/loader.rb
index 3e9a976221..f041de853c 100644
--- a/ruby/red-arrow/lib/arrow/loader.rb
+++ b/ruby/red-arrow/lib/arrow/loader.rb
@@ -33,6 +33,7 @@ module Arrow
end
def require_libraries
+ require "arrow/array-computable"
require "arrow/column-containable"
require "arrow/field-containable"
require "arrow/generic-filterable"0c9e390 to
9d8f036
Compare
kou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I've applied my suggestion.
No description provided.