lib/arrow/array-builder.rb in red-arrow-0.8.2 vs lib/arrow/array-builder.rb in red-arrow-0.10.0
- old
+ new
@@ -1,18 +1,21 @@
-# Copyright 2017 Kouhei Sutou <kou@clear-code.com>
+# 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
#
-# Licensed 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
#
-# 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.
+# 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 "date"
module Arrow
class ArrayBuilder
@@ -33,11 +36,11 @@
when String
return StringArray.new(values)
when Float
return DoubleArray.new(values)
when Integer
- if value.negative?
+ if value < 0
builder = IntArrayBuilder.new
return builder.build(values)
else
builder_class = UIntArrayBuilder
end
@@ -61,64 +64,61 @@
end
end
def build(values)
value_convertable = respond_to?(:convert_to_arrow_value, true)
- if respond_to?(:append_values)
- start_index = 0
- current_index = 0
- status = :value
- values.each do |value|
- if value.nil?
- if status == :value
- if start_index != current_index
- target_values = values[start_index...current_index]
- if value_convertable
- target_values = target_values.collect do |v|
- convert_to_arrow_value(v)
- end
+ start_index = 0
+ current_index = 0
+ status = :value
+
+ values.each do |value|
+ if value.nil?
+ if status == :value
+ if start_index != current_index
+ target_values = values[start_index...current_index]
+ if value_convertable
+ target_values = target_values.collect do |v|
+ convert_to_arrow_value(v)
end
- append_values(target_values)
- start_index = current_index
end
- status = :null
- end
- else
- if status == :null
- append_nulls(current_index - start_index)
+ append_values(target_values, nil)
start_index = current_index
- status = :value
end
+ status = :null
end
- current_index += 1
- end
- if start_index != current_index
- if status == :value
- if start_index == 0 and current_index == values.size
- target_values = values
- else
- target_values = values[start_index...current_index]
- end
- if value_convertable
- target_values = target_values.collect do |v|
- convert_to_arrow_value(v)
- end
- end
- append_values(target_values)
- else
+ else
+ if status == :null
append_nulls(current_index - start_index)
+ start_index = current_index
+ status = :value
end
end
- else
- values.each do |value|
- if value.nil?
- append_null
+ current_index += 1
+ end
+ if start_index != current_index
+ if status == :value
+ if start_index == 0 and current_index == values.size
+ target_values = values
else
- value = convert_to_arrow_value(value) if value_convertable
- append(value)
+ target_values = values[start_index...current_index]
end
+ if value_convertable
+ target_values = target_values.collect do |v|
+ convert_to_arrow_value(v)
+ end
+ end
+ append_values(target_values, nil)
+ else
+ append_nulls(current_index - start_index)
end
end
+
finish
+ end
+
+ def append_nulls(n)
+ n.times do
+ append_null
+ end
end
end
end