red-arrow 4.0.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class EqualOptions
20
+ class << self
21
+ # @api private
22
+ def try_convert(value)
23
+ case value
24
+ when Hash
25
+ options = new
26
+ value.each do |k, v|
27
+ setter = :"#{k}="
28
+ return unless options.respond_to?(setter)
29
+ options.__send__(setter, v)
30
+ end
31
+ options
32
+ else
33
+ nil
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/arrow/loader.rb CHANGED
@@ -29,6 +29,7 @@ module Arrow
29
29
  def post_load(repository, namespace)
30
30
  require_libraries
31
31
  require_extension_library
32
+ gc_guard
32
33
  end
33
34
 
34
35
  def require_libraries
@@ -52,6 +53,7 @@ module Arrow
52
53
  require "arrow/date32-array-builder"
53
54
  require "arrow/date64-array"
54
55
  require "arrow/date64-array-builder"
56
+ require "arrow/datum"
55
57
  require "arrow/decimal128"
56
58
  require "arrow/decimal128-array"
57
59
  require "arrow/decimal128-array-builder"
@@ -63,6 +65,7 @@ module Arrow
63
65
  require "arrow/dense-union-data-type"
64
66
  require "arrow/dictionary-array"
65
67
  require "arrow/dictionary-data-type"
68
+ require "arrow/equal-options"
66
69
  require "arrow/field"
67
70
  require "arrow/file-output-stream"
68
71
  require "arrow/fixed-size-binary-array"
@@ -80,6 +83,7 @@ module Arrow
80
83
  require "arrow/record-batch-iterator"
81
84
  require "arrow/record-batch-stream-reader"
82
85
  require "arrow/rolling-window"
86
+ require "arrow/scalar"
83
87
  require "arrow/schema"
84
88
  require "arrow/slicer"
85
89
  require "arrow/sort-key"
@@ -112,6 +116,27 @@ module Arrow
112
116
  require "arrow.so"
113
117
  end
114
118
 
119
+ def gc_guard
120
+ require "arrow/constructor-arguments-gc-guardable"
121
+
122
+ [
123
+ @base_module::BinaryScalar,
124
+ @base_module::Buffer,
125
+ @base_module::DenseUnionScalar,
126
+ @base_module::FixedSizeBinaryScalar,
127
+ @base_module::LargeBinaryScalar,
128
+ @base_module::LargeListScalar,
129
+ @base_module::LargeStringScalar,
130
+ @base_module::ListScalar,
131
+ @base_module::MapScalar,
132
+ @base_module::SparseUnionScalar,
133
+ @base_module::StringScalar,
134
+ @base_module::StructScalar,
135
+ ].each do |klass|
136
+ klass.prepend(ConstructorArgumentsGCGuardable)
137
+ end
138
+ end
139
+
115
140
  def load_object_info(info)
116
141
  super
117
142
 
@@ -164,6 +189,12 @@ module Arrow
164
189
  method_name = "dup"
165
190
  end
166
191
  super(info, klass, method_name)
192
+ when "Arrow::BooleanScalar"
193
+ case method_name
194
+ when "value?"
195
+ method_name = "value"
196
+ end
197
+ super(info, klass, method_name)
167
198
  else
168
199
  super
169
200
  end
@@ -0,0 +1,32 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class Scalar
20
+ # @param other [Arrow::Scalar] The scalar to be compared.
21
+ # @param options [Arrow::EqualOptions, Hash] (nil)
22
+ # The options to custom how to compare.
23
+ #
24
+ # @return [Boolean]
25
+ # `true` if both of them have the same data, `false` otherwise.
26
+ #
27
+ # @since 5.0.0
28
+ def equal_scalar?(other, options=nil)
29
+ equal_options(other, options)
30
+ end
31
+ end
32
+ end
data/lib/arrow/table.rb CHANGED
@@ -442,8 +442,8 @@ module Arrow
442
442
  RollingWindow.new(self, size)
443
443
  end
444
444
 
445
- def save(path, options={})
446
- saver = TableSaver.new(self, path, options)
445
+ def save(output, options={})
446
+ saver = TableSaver.new(self, output, options)
447
447
  saver.save
448
448
  end
449
449
 
data/lib/arrow/version.rb CHANGED
@@ -16,7 +16,7 @@
16
16
  # under the License.
17
17
 
18
18
  module Arrow
19
- VERSION = "4.0.1"
19
+ VERSION = "5.0.0"
20
20
 
21
21
  module Version
22
22
  numbers, TAG = VERSION.split("-")
data/red-arrow.gemspec CHANGED
@@ -48,13 +48,14 @@ Gem::Specification.new do |spec|
48
48
 
49
49
  spec.add_runtime_dependency("bigdecimal", ">= 2.0.3")
50
50
  spec.add_runtime_dependency("extpp", ">= 0.0.7")
51
- spec.add_runtime_dependency("gio2", ">= 3.3.6")
51
+ spec.add_runtime_dependency("gio2", ">= 3.4.5")
52
52
  spec.add_runtime_dependency("native-package-installer")
53
53
  spec.add_runtime_dependency("pkg-config")
54
54
 
55
55
  spec.add_development_dependency("benchmark-driver")
56
56
  spec.add_development_dependency("bundler")
57
57
  spec.add_development_dependency("faker")
58
+ spec.add_development_dependency("fiddle", ">= 1.0.9")
58
59
  spec.add_development_dependency("rake")
59
60
  spec.add_development_dependency("redcarpet")
60
61
  spec.add_development_dependency("test-unit")
data/test/helper.rb CHANGED
@@ -17,6 +17,7 @@
17
17
 
18
18
  require "arrow"
19
19
 
20
+ require "fiddle"
20
21
  require "pathname"
21
22
  require "tempfile"
22
23
  require "zlib"
data/test/test-array.rb CHANGED
@@ -64,6 +64,40 @@ class ArrayTest < Test::Unit::TestCase
64
64
  end
65
65
  end
66
66
 
67
+ sub_test_case("#equal_array?") do
68
+ test("no options") do
69
+ array1 = Arrow::FloatArray.new([1.1, Float::NAN])
70
+ array2 = Arrow::FloatArray.new([1.1, Float::NAN])
71
+ assert do
72
+ not array1.equal_array?(array2)
73
+ end
74
+ end
75
+
76
+ test("approx") do
77
+ array1 = Arrow::FloatArray.new([1.1])
78
+ array2 = Arrow::FloatArray.new([1.100001])
79
+ assert do
80
+ array1.equal_array?(array2, approx: true)
81
+ end
82
+ end
83
+
84
+ test("nans-equal") do
85
+ array1 = Arrow::FloatArray.new([1.1, Float::NAN])
86
+ array2 = Arrow::FloatArray.new([1.1, Float::NAN])
87
+ assert do
88
+ array1.equal_array?(array2, nans_equal: true)
89
+ end
90
+ end
91
+
92
+ test("absolute-tolerance") do
93
+ array1 = Arrow::FloatArray.new([1.1])
94
+ array2 = Arrow::FloatArray.new([1.101])
95
+ assert do
96
+ array1.equal_array?(array2, approx: true, absolute_tolerance: 0.01)
97
+ end
98
+ end
99
+ end
100
+
67
101
  sub_test_case("#cast") do
68
102
  test("Symbol") do
69
103
  assert_equal(Arrow::Int32Array.new([1, 2, 3]),
@@ -0,0 +1,26 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ class BooleanScalarTest < Test::Unit::TestCase
19
+ def setup
20
+ @scalar = Arrow::BooleanScalar.new(true)
21
+ end
22
+
23
+ test("#value") do
24
+ assert_equal(true, @scalar.value)
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ class FloatScalarTest < Test::Unit::TestCase
19
+ sub_test_case("#equal_scalar?") do
20
+ test("no options") do
21
+ scalar1 = Arrow::FloatScalar.new(1.1)
22
+ scalar2 = Arrow::FloatScalar.new(1.1000001)
23
+ assert do
24
+ not scalar1.equal_scalar?(scalar2)
25
+ end
26
+ end
27
+
28
+ test(":approx") do
29
+ scalar1 = Arrow::FloatScalar.new(1.1)
30
+ scalar2 = Arrow::FloatScalar.new(1.1000001)
31
+ assert do
32
+ scalar1.equal_scalar?(scalar2, approx: true)
33
+ end
34
+ end
35
+
36
+ test(":absolute_tolerance") do
37
+ scalar1 = Arrow::FloatScalar.new(1.1)
38
+ scalar2 = Arrow::FloatScalar.new(1.1001)
39
+ assert do
40
+ scalar1.equal_scalar?(scalar2,
41
+ approx: true,
42
+ absolute_tolerance: 0.001)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,176 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ class FunctionTest < Test::Unit::TestCase
19
+ sub_test_case("#execute") do
20
+ test("Arrow::Array") do
21
+ or_function = Arrow::Function.find("or")
22
+ args = [
23
+ Arrow::BooleanArray.new([true, false, false]),
24
+ Arrow::BooleanArray.new([true, false, true]),
25
+ ]
26
+ assert_equal([true, false, true],
27
+ or_function.execute(args).value.to_a)
28
+ end
29
+
30
+ test("Array") do
31
+ or_function = Arrow::Function.find("or")
32
+ args = [
33
+ [true, false, false],
34
+ [true, false, true],
35
+ ]
36
+ assert_equal([true, false, true],
37
+ or_function.execute(args).value.to_a)
38
+ end
39
+
40
+ test("Arrow::ChunkedArray") do
41
+ or_function = Arrow::Function.find("or")
42
+ args = [
43
+ Arrow::ChunkedArray.new([
44
+ Arrow::BooleanArray.new([true]),
45
+ Arrow::BooleanArray.new([false, false]),
46
+ ]),
47
+ Arrow::ChunkedArray.new([
48
+ Arrow::BooleanArray.new([true, false]),
49
+ Arrow::BooleanArray.new([true]),
50
+ ]),
51
+ ]
52
+ assert_equal([true, false, true],
53
+ or_function.execute(args).value.to_a)
54
+ end
55
+
56
+ test("Arrow::Scalar") do
57
+ add_function = Arrow::Function.find("add")
58
+ args = [
59
+ Arrow::Int8Array.new([1, 2, 3]),
60
+ Arrow::Int8Scalar.new(5),
61
+ ]
62
+ assert_equal([6, 7, 8],
63
+ add_function.execute(args).value.to_a)
64
+ end
65
+
66
+ test("Integer") do
67
+ add_function = Arrow::Function.find("add")
68
+ args = [
69
+ [1, 2, 3],
70
+ 5,
71
+ ]
72
+ assert_equal([6, 7, 8],
73
+ add_function.execute(args).value.to_a)
74
+ end
75
+
76
+ test("Float") do
77
+ add_function = Arrow::Function.find("add")
78
+ args = [
79
+ [1, 2, 3],
80
+ 5.1,
81
+ ]
82
+ assert_equal([6.1, 7.1, 8.1],
83
+ add_function.execute(args).value.to_a)
84
+ end
85
+
86
+ test("true") do
87
+ and_function = Arrow::Function.find("and")
88
+ args = [
89
+ Arrow::BooleanArray.new([true, false, false]),
90
+ true,
91
+ ]
92
+ assert_equal([true, false, false],
93
+ and_function.execute(args).value.to_a)
94
+ end
95
+
96
+ test("false") do
97
+ or_function = Arrow::Function.find("or")
98
+ args = [
99
+ Arrow::BooleanArray.new([true, false, false]),
100
+ false,
101
+ ]
102
+ assert_equal([true, false, false],
103
+ or_function.execute(args).value.to_a)
104
+ end
105
+
106
+ test("String") do
107
+ ascii_upper_function = Arrow::Function.find("ascii_upper")
108
+ args = [
109
+ "Hello",
110
+ ]
111
+ assert_equal("HELLO",
112
+ ascii_upper_function.execute(args).value.to_s)
113
+ end
114
+
115
+ test("Date") do
116
+ cast_function = Arrow::Function.find("cast")
117
+ date = Date.new(2021, 6, 12)
118
+ args = [date]
119
+ options = Arrow::CastOptions.new
120
+ options.to_data_type = Arrow::TimestampDataType.new(:second)
121
+ time = Time.utc(date.year,
122
+ date.month,
123
+ date.day)
124
+ assert_equal(Arrow::TimestampScalar.new(options.to_data_type,
125
+ time.to_i),
126
+ cast_function.execute(args, options).value)
127
+ end
128
+
129
+ test("Arrow::Time: second") do
130
+ cast_function = Arrow::Function.find("cast")
131
+ arrow_time = Arrow::Time.new(Arrow::TimeUnit::SECOND,
132
+ # 00:10:00
133
+ 60 * 10)
134
+ args = [arrow_time]
135
+ options = Arrow::CastOptions.new
136
+ options.to_data_type = Arrow::Time64DataType.new(:micro)
137
+ assert_equal(Arrow::Time64Scalar.new(options.to_data_type,
138
+ # 00:10:00.000000
139
+ 60 * 10 * 1000 * 1000),
140
+ cast_function.execute(args, options).value)
141
+ end
142
+
143
+ test("Arrow::Time: micro") do
144
+ cast_function = Arrow::Function.find("cast")
145
+ arrow_time = Arrow::Time.new(Arrow::TimeUnit::MICRO,
146
+ # 00:10:00.000000
147
+ 60 * 10 * 1000 * 1000)
148
+ args = [arrow_time]
149
+ options = Arrow::CastOptions.new
150
+ options.to_data_type = Arrow::Time32DataType.new(:second)
151
+ options.allow_time_truncate = true
152
+ assert_equal(Arrow::Time32Scalar.new(options.to_data_type,
153
+ # 00:10:00
154
+ 60 * 10),
155
+ cast_function.execute(args, options).value)
156
+ end
157
+
158
+ test("Time") do
159
+ cast_function = Arrow::Function.find("cast")
160
+ time = Time.utc(2021, 6, 12, 1, 2, 3, 1)
161
+ args = [time]
162
+ options = Arrow::CastOptions.new
163
+ options.to_data_type = Arrow::TimestampDataType.new(:second)
164
+ options.allow_time_truncate = true
165
+ time = Time.utc(time.year,
166
+ time.month,
167
+ time.day,
168
+ time.hour,
169
+ time.min,
170
+ time.sec)
171
+ assert_equal(Arrow::TimestampScalar.new(options.to_data_type,
172
+ time.to_i),
173
+ cast_function.execute(args, options).value)
174
+ end
175
+ end
176
+ end