kou commented on code in PR #50226:
URL: https://github.com/apache/arrow/pull/50226#discussion_r3449907169
##########
ruby/red-arrow/lib/arrow/column-containable.rb:
##########
@@ -152,5 +152,76 @@ def [](selector)
def column_names
@column_names ||= columns.collect(&:name)
end
+
+ # Merges columns from the given container or Hash and creates
+ # a new container.
+ #
+ # @param other [Hash, self]
+ # The columns to be merged.
+ #
+ # @return [self]
+ def merge(other)
+ added_columns = {}
+ removed_columns = {}
+
+ case other
+ when Hash
+ other.each do |name, value|
+ name = name.to_s
+ if value
+ added_columns[name] = ensure_raw_column(name, value)
+ else
+ removed_columns[name] = true
+ end
+ end
+ when self.class
+ other.columns.each do |column|
+ name = column.name
+ added_columns[name] = ensure_raw_column(name, column)
+ end
+ else
+ message = "merge target must be Hash or #{self.class}: " +
+ "<#{other.inspect}>: #{inspect}"
+ raise ArgumentError, message
+ end
+
+ new_columns = []
+
+ columns.each do |column|
+ column_name = column.name
+ new_column = added_columns.delete(column_name)
+
+ if new_column
+ new_columns << new_column
+ next
+ end
+
+ next if removed_columns.key?(column_name)
+
+ new_columns << ensure_raw_column(column_name, column)
+ end
+
+ added_columns.each_value do |new_column|
+ new_columns << new_column
+ end
+
+ new_fields = []
+ new_arrays = []
+
+ new_columns.each do |new_column|
+ new_fields << new_column[:field]
+ new_arrays << new_column[:data]
+ end
+
+ create_merged_container(new_fields, new_arrays)
+ end
+
+ private
+
+ def create_merged_container(fields, arrays)
+ container = self.class.new(fields, arrays)
+ share_input(container)
+ container
Review Comment:
Can we merge them?
```suggestion
merged = self.class.new(new_fields, new_arrays)
share_input(merged)
merged
```
##########
ruby/red-arrow/lib/arrow/table.rb:
##########
@@ -628,6 +574,7 @@ def method_missing(name, *args, &block)
end
private
+
Review Comment:
Could you revert needless changes?
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]