-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARROW-4174: [Ruby] Add support for building composite array from raw …
…Ruby objects Author: Kouhei Sutou <[email protected]> Closes #3327 from kou/ruby-array-builder and squashes the following commits: 20e5874 <Kouhei Sutou> Add support for old GObject Introspection 36b993b <Kouhei Sutou> Add support for building composite array from raw Ruby objects
- Loading branch information
Showing
16 changed files
with
728 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# 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. | ||
|
||
require "bigdecimal" | ||
|
||
module Arrow | ||
class Decimal128ArrayBuilder | ||
class << self | ||
def build(data_type, values) | ||
builder = new(data_type) | ||
builder.build(values) | ||
end | ||
end | ||
|
||
alias_method :append_value_raw, :append_value | ||
def append_value(value) | ||
case value | ||
when nil | ||
return append_null | ||
when String | ||
value = Decimal128.new(value) | ||
when Float | ||
value = Decimal128.new(value.to_s) | ||
when BigDecimal | ||
value = Decimal128.new(value.to_s) | ||
end | ||
append_value_raw(value) | ||
end | ||
|
||
def append_values(values, is_valids=nil) | ||
if is_valids | ||
is_valids.each_with_index do |is_valid, i| | ||
if is_valid | ||
append_value(values[i]) | ||
else | ||
append_null | ||
end | ||
end | ||
else | ||
values.each do |value| | ||
if value.nil? | ||
append_null | ||
else | ||
append_value(value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# 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 | ||
class ListArrayBuilder | ||
class << self | ||
def build(data_type, values) | ||
builder = new(data_type) | ||
builder.build(values) | ||
end | ||
end | ||
|
||
alias_method :append_value_raw, :append_value | ||
|
||
# @overload append_value | ||
# | ||
# Starts appending a list record. You also need to append list | ||
# value by {#value_builder}. | ||
# | ||
# @overload append_value(list) | ||
# | ||
# Appends a list record including list value. | ||
# | ||
# @param value [nil, ::Array] The list value of the record. | ||
# | ||
# If this is `nil`, the list record is null. | ||
# | ||
# If this is `Array`, it's the list value of the record. | ||
# | ||
# @since 0.12.0 | ||
def append_value(*args) | ||
n_args = args.size | ||
|
||
case n_args | ||
when 0 | ||
append_value_raw | ||
when 1 | ||
value = args[0] | ||
case value | ||
when nil | ||
append_null | ||
when ::Array | ||
append_value_raw | ||
@value_builder ||= value_builder | ||
@value_builder.append_values(value, nil) | ||
else | ||
message = "list value must be nil or Array: #{value.inspect}" | ||
raise ArgumentError, message | ||
end | ||
else | ||
message = "wrong number of arguments (given #{n_args}, expected 0..1)" | ||
raise ArgumentError, message | ||
end | ||
end | ||
|
||
def append_values(lists, is_valids=nil) | ||
if is_valids | ||
is_valids.each_with_index do |is_valid, i| | ||
if is_valid | ||
append_value(lists[i]) | ||
else | ||
append_null | ||
end | ||
end | ||
else | ||
lists.each do |list| | ||
append_value(list) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.