red-arrow 3.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -0
  3. data/ext/arrow/arrow.cpp +3 -0
  4. data/ext/arrow/converters.cpp +5 -0
  5. data/ext/arrow/converters.hpp +126 -0
  6. data/ext/arrow/extconf.rb +13 -0
  7. data/ext/arrow/memory-view.cpp +311 -0
  8. data/ext/arrow/memory-view.hpp +26 -0
  9. data/ext/arrow/raw-records.cpp +1 -0
  10. data/ext/arrow/values.cpp +1 -0
  11. data/lib/arrow/aggregate-node-options.rb +35 -0
  12. data/lib/arrow/aggregation.rb +46 -0
  13. data/lib/arrow/array-builder.rb +5 -0
  14. data/lib/arrow/array.rb +130 -0
  15. data/lib/arrow/binary-dictionary-array-builder.rb +27 -0
  16. data/lib/arrow/buffer.rb +10 -6
  17. data/lib/arrow/column-containable.rb +100 -1
  18. data/lib/arrow/constructor-arguments-gc-guardable.rb +25 -0
  19. data/lib/arrow/data-type.rb +14 -5
  20. data/lib/arrow/datum.rb +100 -0
  21. data/lib/arrow/dense-union-data-type.rb +2 -2
  22. data/lib/arrow/dictionary-data-type.rb +2 -2
  23. data/lib/arrow/equal-options.rb +38 -0
  24. data/lib/arrow/expression.rb +48 -0
  25. data/lib/arrow/file-system.rb +34 -0
  26. data/lib/arrow/group.rb +116 -124
  27. data/lib/arrow/loader.rb +46 -0
  28. data/lib/arrow/map-array-builder.rb +109 -0
  29. data/lib/arrow/map-array.rb +26 -0
  30. data/lib/arrow/map-data-type.rb +89 -0
  31. data/lib/arrow/path-extension.rb +1 -1
  32. data/lib/arrow/record-batch-reader.rb +41 -0
  33. data/lib/arrow/record-batch.rb +0 -2
  34. data/lib/arrow/scalar.rb +32 -0
  35. data/lib/arrow/slicer.rb +44 -143
  36. data/lib/arrow/sort-key.rb +193 -0
  37. data/lib/arrow/sort-options.rb +109 -0
  38. data/lib/arrow/source-node-options.rb +32 -0
  39. data/lib/arrow/sparse-union-data-type.rb +2 -2
  40. data/lib/arrow/string-dictionary-array-builder.rb +27 -0
  41. data/lib/arrow/symbol-values-appendable.rb +34 -0
  42. data/lib/arrow/table-concatenate-options.rb +36 -0
  43. data/lib/arrow/table-formatter.rb +141 -17
  44. data/lib/arrow/table-list-formatter.rb +5 -3
  45. data/lib/arrow/table-loader.rb +41 -3
  46. data/lib/arrow/table-saver.rb +29 -3
  47. data/lib/arrow/table-table-formatter.rb +7 -31
  48. data/lib/arrow/table.rb +34 -40
  49. data/lib/arrow/time32-data-type.rb +2 -2
  50. data/lib/arrow/time64-data-type.rb +2 -2
  51. data/lib/arrow/timestamp-data-type.rb +2 -2
  52. data/lib/arrow/version.rb +1 -1
  53. data/red-arrow.gemspec +2 -1
  54. data/test/helper.rb +1 -0
  55. data/test/raw-records/test-dense-union-array.rb +14 -0
  56. data/test/raw-records/test-list-array.rb +19 -0
  57. data/test/raw-records/test-map-array.rb +441 -0
  58. data/test/raw-records/test-sparse-union-array.rb +14 -0
  59. data/test/raw-records/test-struct-array.rb +15 -0
  60. data/test/test-array-builder.rb +7 -0
  61. data/test/test-array.rb +154 -0
  62. data/test/test-binary-dictionary-array-builder.rb +103 -0
  63. data/test/test-boolean-scalar.rb +26 -0
  64. data/test/test-csv-loader.rb +8 -8
  65. data/test/test-decimal128-data-type.rb +2 -2
  66. data/test/test-expression.rb +40 -0
  67. data/test/test-float-scalar.rb +46 -0
  68. data/test/test-function.rb +176 -0
  69. data/test/test-group.rb +75 -51
  70. data/test/test-map-array-builder.rb +110 -0
  71. data/test/test-map-array.rb +33 -0
  72. data/test/test-map-data-type.rb +36 -0
  73. data/test/test-memory-view.rb +434 -0
  74. data/test/test-orc.rb +19 -23
  75. data/test/test-record-batch-reader.rb +46 -0
  76. data/test/test-record-batch.rb +42 -0
  77. data/test/test-slicer.rb +166 -167
  78. data/test/test-sort-indices.rb +40 -0
  79. data/test/test-sort-key.rb +81 -0
  80. data/test/test-sort-options.rb +58 -0
  81. data/test/test-string-dictionary-array-builder.rb +103 -0
  82. data/test/test-table.rb +190 -53
  83. data/test/values/test-dense-union-array.rb +14 -0
  84. data/test/values/test-list-array.rb +17 -0
  85. data/test/values/test-map-array.rb +433 -0
  86. data/test/values/test-sparse-union-array.rb +14 -0
  87. data/test/values/test-struct-array.rb +15 -0
  88. metadata +73 -6
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]),
@@ -168,4 +202,124 @@ class ArrayTest < Test::Unit::TestCase
168
202
  @array.is_in(right))
169
203
  end
170
204
  end
205
+
206
+ sub_test_case("#concatenate") do
207
+ test("Arrow::Array: same") do
208
+ assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,5, 6]),
209
+ Arrow::Int32Array.new([1, 2, nil]).
210
+ concatenate(Arrow::Int32Array.new([4, 5]),
211
+ Arrow::Int32Array.new([6])))
212
+ end
213
+
214
+ test("Arrow::Array: castable") do
215
+ assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,5, 6]),
216
+ Arrow::Int32Array.new([1, 2, nil]).
217
+ concatenate(Arrow::Int8Array.new([4, 5]),
218
+ Arrow::UInt32Array.new([6])))
219
+ end
220
+
221
+ test("Arrow::Array: non-castable") do
222
+ assert_raise(Arrow::Error::Invalid) do
223
+ Arrow::Int32Array.new([1, 2, nil]).
224
+ concatenate(Arrow::StringArray.new(["X"]))
225
+ end
226
+ end
227
+
228
+ test("Array") do
229
+ assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,nil, 6]),
230
+ Arrow::Int32Array.new([1, 2, nil]).
231
+ concatenate([4, nil],
232
+ [6]))
233
+ end
234
+
235
+ test("invalid") do
236
+ message = "[array][resolve] can't build int32 array: 4"
237
+ assert_raise(ArgumentError.new(message)) do
238
+ Arrow::Int32Array.new([1, 2, nil]).
239
+ concatenate(4)
240
+ end
241
+ end
242
+ end
243
+
244
+ sub_test_case("#+") do
245
+ test("Arrow::Array: same") do
246
+ assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,5, 6]),
247
+ Arrow::Int32Array.new([1, 2, nil]) +
248
+ Arrow::Int32Array.new([4, 5, 6]))
249
+ end
250
+
251
+ test("Arrow::Array: castable") do
252
+ assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,5, 6]),
253
+ Arrow::Int32Array.new([1, 2, nil]) +
254
+ Arrow::Int8Array.new([4, 5, 6]))
255
+ end
256
+
257
+ test("Arrow::Array: non-castable") do
258
+ assert_raise(Arrow::Error::Invalid) do
259
+ Arrow::Int32Array.new([1, 2, nil]) +
260
+ Arrow::StringArray.new(["X"])
261
+ end
262
+ end
263
+
264
+ test("Array") do
265
+ assert_equal(Arrow::Int32Array.new([1, 2, nil, 4 ,nil, 6]),
266
+ Arrow::Int32Array.new([1, 2, nil]) +
267
+ [4, nil, 6])
268
+ end
269
+
270
+ test("invalid") do
271
+ message = "[array][resolve] can't build int32 array: 4"
272
+ assert_raise(ArgumentError.new(message)) do
273
+ Arrow::Int32Array.new([1, 2, nil]) + 4
274
+ end
275
+ end
276
+ end
277
+
278
+ sub_test_case("#resolve") do
279
+ test("Arrow::Array: same") do
280
+ assert_equal(Arrow::Int32Array.new([1, 2, nil]),
281
+ Arrow::Int32Array.new([]).
282
+ resolve(Arrow::Int32Array.new([1, 2, nil])))
283
+ end
284
+
285
+ test("Arrow::Array: castable") do
286
+ assert_equal(Arrow::Int32Array.new([1, 2, nil]),
287
+ Arrow::Int32Array.new([]).
288
+ resolve(Arrow::Int8Array.new([1, 2, nil])))
289
+ end
290
+
291
+ test("Arrow::Array: non-castable") do
292
+ assert_raise(Arrow::Error::Invalid) do
293
+ Arrow::Int32Array.new([]) +
294
+ Arrow::StringArray.new(["X"])
295
+ end
296
+ end
297
+
298
+ test("Array: non-parametric") do
299
+ assert_equal(Arrow::Int32Array.new([1, 2, nil]),
300
+ Arrow::Int32Array.new([]).
301
+ resolve([1, 2, nil]))
302
+ end
303
+
304
+ test("Array: parametric") do
305
+ list_data_type = Arrow::ListDataType.new(name: "visible", type: :boolean)
306
+ list_array = Arrow::ListArray.new(list_data_type, [])
307
+ assert_equal(Arrow::ListArray.new(list_data_type,
308
+ [
309
+ [true, false],
310
+ nil,
311
+ ]),
312
+ list_array.resolve([
313
+ [true, false],
314
+ nil,
315
+ ]))
316
+ end
317
+
318
+ test("invalid") do
319
+ message = "[array][resolve] can't build int32 array: 4"
320
+ assert_raise(ArgumentError.new(message)) do
321
+ Arrow::Int32Array.new([]).resolve(4)
322
+ end
323
+ end
324
+ end
171
325
  end
@@ -0,0 +1,103 @@
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 BinaryDictionaryArrayBuilderTest < Test::Unit::TestCase
19
+ def setup
20
+ @builder = Arrow::BinaryDictionaryArrayBuilder.new
21
+ end
22
+
23
+ sub_test_case("#append_values") do
24
+ test("[nil]") do
25
+ @builder.append_values([nil])
26
+ array = @builder.finish
27
+ assert_equal([
28
+ [],
29
+ [nil],
30
+ ],
31
+ [
32
+ array.dictionary.to_a,
33
+ array.indices.to_a,
34
+ ])
35
+ end
36
+
37
+ test("[String]") do
38
+ @builder.append_values(["he\xffllo"])
39
+ array = @builder.finish
40
+ assert_equal([
41
+ ["he\xffllo".b],
42
+ [0],
43
+ ],
44
+ [
45
+ array.dictionary.to_a,
46
+ array.indices.to_a,
47
+ ])
48
+ end
49
+
50
+ test("[Symbol]") do
51
+ @builder.append_values([:hello])
52
+ array = @builder.finish
53
+ assert_equal([
54
+ ["hello"],
55
+ [0],
56
+ ],
57
+ [
58
+ array.dictionary.to_a,
59
+ array.indices.to_a,
60
+ ])
61
+ end
62
+
63
+ test("[nil, String, Symbol]") do
64
+ @builder.append_values([
65
+ nil,
66
+ "He\xffllo",
67
+ :world,
68
+ "world",
69
+ ])
70
+ array = @builder.finish
71
+ assert_equal([
72
+ ["He\xffllo".b, "world"],
73
+ [nil, 0, 1, 1],
74
+ ],
75
+ [
76
+ array.dictionary.to_a,
77
+ array.indices.to_a,
78
+ ])
79
+ end
80
+
81
+ test("is_valids") do
82
+ @builder.append_values([
83
+ "He\xffllo",
84
+ :world,
85
+ :goodbye,
86
+ ],
87
+ [
88
+ true,
89
+ false,
90
+ true,
91
+ ])
92
+ array = @builder.finish
93
+ assert_equal([
94
+ ["He\xffllo".b, "goodbye"],
95
+ [0, nil, 1],
96
+ ],
97
+ [
98
+ array.dictionary.to_a,
99
+ array.indices.to_a,
100
+ ])
101
+ end
102
+ end
103
+ end
@@ -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
@@ -86,20 +86,20 @@ class CSVLoaderTest < Test::Unit::TestCase
86
86
  test("null: with double quote") do
87
87
  path = fixture_path("null-with-double-quote.csv").to_s
88
88
  assert_equal(<<-TABLE, load_csv(path).to_s)
89
- name score
90
- 0 alice 10
91
- 1 bob
92
- 2 chris -1
89
+ name score
90
+ 0 alice 10
91
+ 1 bob (null)
92
+ 2 chris -1
93
93
  TABLE
94
94
  end
95
95
 
96
96
  test("null: without double quote") do
97
97
  path = fixture_path("null-without-double-quote.csv").to_s
98
98
  assert_equal(<<-TABLE, load_csv(path).to_s)
99
- name score
100
- 0 alice 10
101
- 1 bob
102
- 2 chris -1
99
+ name score
100
+ 0 alice 10
101
+ 1 bob (null)
102
+ 2 chris -1
103
103
  TABLE
104
104
  end
105
105
 
@@ -18,12 +18,12 @@
18
18
  class Decimal128DataTypeTest < Test::Unit::TestCase
19
19
  sub_test_case(".new") do
20
20
  test("ordered arguments") do
21
- assert_equal("decimal(8, 2)",
21
+ assert_equal("decimal128(8, 2)",
22
22
  Arrow::Decimal128DataType.new(8, 2).to_s)
23
23
  end
24
24
 
25
25
  test("description") do
26
- assert_equal("decimal(8, 2)",
26
+ assert_equal("decimal128(8, 2)",
27
27
  Arrow::Decimal128DataType.new(precision: 8,
28
28
  scale: 2).to_s)
29
29
  end
@@ -0,0 +1,40 @@
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 TestExpression < Test::Unit::TestCase
19
+ sub_test_case(".try_convert") do
20
+ test("Symbol") do
21
+ assert_equal(Arrow::FieldExpression.new("visible"),
22
+ Arrow::Expression.try_convert(:visible))
23
+ end
24
+
25
+ test("[String]") do
26
+ assert_equal(Arrow::CallExpression.new("func", []),
27
+ Arrow::Expression.try_convert(["func"]))
28
+ end
29
+
30
+ test("[Symbol]") do
31
+ assert_equal(Arrow::CallExpression.new("func", []),
32
+ Arrow::Expression.try_convert([:func]))
33
+ end
34
+
35
+ test("[String, String]") do
36
+ assert_equal(Arrow::CallExpression.new("func", ["argument1"]),
37
+ Arrow::Expression.try_convert(["func", "argument1"]))
38
+ end
39
+ end
40
+ 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