red-arrow 8.0.0 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -7
  3. data/ext/arrow/arrow.cpp +67 -0
  4. data/ext/arrow/converters.cpp +10 -0
  5. data/ext/arrow/converters.hpp +310 -46
  6. data/ext/arrow/extconf.rb +41 -22
  7. data/ext/arrow/raw-records.cpp +165 -2
  8. data/ext/arrow/red-arrow.hpp +2 -0
  9. data/ext/arrow/values.cpp +6 -2
  10. data/lib/arrow/array-builder.rb +89 -14
  11. data/{test/test-time32-data-type.rb → lib/arrow/array-computable.rb} +24 -16
  12. data/{test/test-buffer.rb → lib/arrow/array-statistics.rb} +19 -24
  13. data/lib/arrow/array.rb +40 -4
  14. data/lib/arrow/chunked-array.rb +56 -1
  15. data/lib/arrow/column-containable.rb +9 -0
  16. data/lib/arrow/column.rb +49 -4
  17. data/{test/test-tensor.rb → lib/arrow/csv-write-options.rb} +28 -31
  18. data/lib/arrow/data-type.rb +17 -3
  19. data/lib/arrow/decimal128-array-builder.rb +16 -6
  20. data/lib/arrow/decimal128.rb +14 -0
  21. data/lib/arrow/decimal256-array-builder.rb +16 -6
  22. data/lib/arrow/decimal256.rb +14 -0
  23. data/{test/test-float-scalar.rb → lib/arrow/dense-union-array-builder.rb} +27 -24
  24. data/{test/test-boolean-scalar.rb → lib/arrow/dense-union-array.rb} +7 -7
  25. data/lib/arrow/duration-array-builder.rb +27 -0
  26. data/lib/arrow/duration-array.rb +24 -0
  27. data/lib/arrow/duration-data-type.rb +32 -0
  28. data/lib/arrow/expression.rb +6 -2
  29. data/lib/arrow/field-containable.rb +1 -1
  30. data/lib/arrow/field.rb +44 -3
  31. data/lib/arrow/fixed-size-list-array-builder.rb +29 -0
  32. data/lib/arrow/fixed-size-list-data-type.rb +118 -0
  33. data/lib/arrow/function.rb +0 -1
  34. data/lib/arrow/half-float-array-builder.rb +32 -0
  35. data/lib/arrow/half-float-array.rb +24 -0
  36. data/lib/arrow/half-float.rb +118 -0
  37. data/{test/helper/fixture.rb → lib/arrow/input-referable.rb} +7 -6
  38. data/lib/arrow/jruby/array-builder.rb +114 -0
  39. data/lib/arrow/jruby/array.rb +109 -0
  40. data/lib/arrow/jruby/chunked-array.rb +36 -0
  41. data/lib/arrow/jruby/compression-type.rb +26 -0
  42. data/lib/arrow/jruby/csv-read-options.rb +32 -0
  43. data/{test/test-map-data-type.rb → lib/arrow/jruby/data-type.rb} +24 -12
  44. data/lib/arrow/jruby/decimal128.rb +28 -0
  45. data/lib/arrow/jruby/decimal256.rb +28 -0
  46. data/{test/fixture/float-integer.csv → lib/arrow/jruby/error.rb} +7 -4
  47. data/lib/arrow/jruby/file-system.rb +24 -0
  48. data/{test/test-null-array.rb → lib/arrow/jruby/function.rb} +5 -4
  49. data/lib/arrow/jruby/record-batch-iterator.rb +24 -0
  50. data/{test/fixture/null-with-double-quote.csv → lib/arrow/jruby/record-batch.rb} +8 -4
  51. data/{test/fixture/integer-float.csv → lib/arrow/jruby/sort-key.rb} +8 -4
  52. data/lib/arrow/jruby/sort-options.rb +24 -0
  53. data/lib/arrow/jruby/stream-listener-raw.rb +25 -0
  54. data/{test/test-rolling-window.rb → lib/arrow/jruby/table.rb} +19 -19
  55. data/lib/arrow/jruby/writable.rb +24 -0
  56. data/lib/arrow/jruby.rb +52 -0
  57. data/{test/test-date32-array.rb → lib/arrow/large-list-array-builder.rb} +10 -5
  58. data/lib/arrow/large-list-data-type.rb +83 -0
  59. data/lib/arrow/libraries.rb +140 -0
  60. data/lib/arrow/list-array-builder.rb +1 -68
  61. data/lib/arrow/list-data-type.rb +3 -38
  62. data/{test/test-dictionary-array.rb → lib/arrow/list-field-resolvable.rb} +26 -17
  63. data/lib/arrow/list-slice-options.rb +76 -0
  64. data/lib/arrow/list-values-appendable.rb +88 -0
  65. data/lib/arrow/loader.rb +15 -96
  66. data/{test/test-decimal128-array.rb → lib/arrow/make-struct-options.rb} +18 -18
  67. data/lib/arrow/raw-table-converter.rb +10 -3
  68. data/lib/arrow/raw-tensor-converter.rb +89 -0
  69. data/lib/arrow/record-batch-file-reader.rb +2 -0
  70. data/lib/arrow/record-batch-stream-reader.rb +2 -0
  71. data/lib/arrow/record-batch.rb +6 -2
  72. data/{test/fixture/null-without-double-quote.csv → lib/arrow/ruby.rb} +5 -4
  73. data/lib/arrow/scalar.rb +67 -0
  74. data/lib/arrow/slicer.rb +61 -0
  75. data/lib/arrow/sort-key.rb +3 -3
  76. data/lib/arrow/sparse-union-array-builder.rb +56 -0
  77. data/lib/arrow/sparse-union-array.rb +26 -0
  78. data/lib/arrow/stream-decoder.rb +29 -0
  79. data/{test/test-decimal256-data-type.rb → lib/arrow/stream-listener.rb} +25 -9
  80. data/lib/arrow/string-array-builder.rb +30 -0
  81. data/lib/arrow/struct-array-builder.rb +0 -5
  82. data/lib/arrow/table-formatter.rb +38 -8
  83. data/lib/arrow/table-list-formatter.rb +3 -3
  84. data/lib/arrow/table-loader.rb +11 -5
  85. data/lib/arrow/table-saver.rb +4 -3
  86. data/lib/arrow/table-table-formatter.rb +7 -0
  87. data/lib/arrow/table.rb +180 -33
  88. data/lib/arrow/tensor.rb +144 -0
  89. data/lib/arrow/time-unit.rb +31 -0
  90. data/lib/arrow/time32-array-builder.rb +2 -14
  91. data/lib/arrow/time32-data-type.rb +9 -38
  92. data/lib/arrow/time64-array-builder.rb +2 -14
  93. data/lib/arrow/time64-data-type.rb +9 -38
  94. data/lib/arrow/timestamp-array-builder.rb +3 -15
  95. data/lib/arrow/timestamp-data-type.rb +9 -34
  96. data/{test/test-date64-array.rb → lib/arrow/timestamp-parser.rb} +14 -6
  97. data/lib/arrow/union-array-builder.rb +59 -0
  98. data/lib/arrow/union-array.rb +26 -0
  99. data/lib/arrow/version.rb +1 -1
  100. data/lib/arrow.rb +2 -7
  101. data/red-arrow.gemspec +74 -11
  102. metadata +85 -210
  103. data/test/fixture/TestOrcFile.test1.orc +0 -0
  104. data/test/fixture/with-header-float.csv +0 -20
  105. data/test/fixture/with-header.csv +0 -20
  106. data/test/fixture/without-header-float.csv +0 -19
  107. data/test/fixture/without-header.csv +0 -19
  108. data/test/helper/omittable.rb +0 -36
  109. data/test/helper.rb +0 -30
  110. data/test/raw-records/test-basic-arrays.rb +0 -395
  111. data/test/raw-records/test-dense-union-array.rb +0 -521
  112. data/test/raw-records/test-list-array.rb +0 -610
  113. data/test/raw-records/test-map-array.rb +0 -478
  114. data/test/raw-records/test-multiple-columns.rb +0 -65
  115. data/test/raw-records/test-sparse-union-array.rb +0 -511
  116. data/test/raw-records/test-struct-array.rb +0 -515
  117. data/test/raw-records/test-table.rb +0 -47
  118. data/test/run-test.rb +0 -71
  119. data/test/test-array-builder.rb +0 -136
  120. data/test/test-array.rb +0 -325
  121. data/test/test-bigdecimal.rb +0 -40
  122. data/test/test-binary-dictionary-array-builder.rb +0 -103
  123. data/test/test-chunked-array.rb +0 -183
  124. data/test/test-column.rb +0 -92
  125. data/test/test-csv-loader.rb +0 -250
  126. data/test/test-data-type.rb +0 -83
  127. data/test/test-decimal128-array-builder.rb +0 -112
  128. data/test/test-decimal128-data-type.rb +0 -31
  129. data/test/test-decimal128.rb +0 -102
  130. data/test/test-decimal256-array-builder.rb +0 -112
  131. data/test/test-decimal256-array.rb +0 -38
  132. data/test/test-decimal256.rb +0 -102
  133. data/test/test-dense-union-data-type.rb +0 -41
  134. data/test/test-dictionary-data-type.rb +0 -40
  135. data/test/test-expression.rb +0 -40
  136. data/test/test-feather.rb +0 -49
  137. data/test/test-field.rb +0 -91
  138. data/test/test-file-output-stream.rb +0 -54
  139. data/test/test-fixed-size-binary-array-builder.rb +0 -92
  140. data/test/test-fixed-size-binary-array.rb +0 -36
  141. data/test/test-function.rb +0 -210
  142. data/test/test-group.rb +0 -180
  143. data/test/test-list-array-builder.rb +0 -79
  144. data/test/test-list-array.rb +0 -32
  145. data/test/test-list-data-type.rb +0 -69
  146. data/test/test-map-array-builder.rb +0 -110
  147. data/test/test-map-array.rb +0 -33
  148. data/test/test-memory-view.rb +0 -434
  149. data/test/test-orc.rb +0 -173
  150. data/test/test-record-batch-builder.rb +0 -125
  151. data/test/test-record-batch-file-reader.rb +0 -115
  152. data/test/test-record-batch-iterator.rb +0 -37
  153. data/test/test-record-batch-reader.rb +0 -46
  154. data/test/test-record-batch.rb +0 -182
  155. data/test/test-schema.rb +0 -134
  156. data/test/test-slicer.rb +0 -487
  157. data/test/test-sort-indices.rb +0 -40
  158. data/test/test-sort-key.rb +0 -81
  159. data/test/test-sort-options.rb +0 -58
  160. data/test/test-sparse-union-data-type.rb +0 -41
  161. data/test/test-string-dictionary-array-builder.rb +0 -103
  162. data/test/test-struct-array-builder.rb +0 -184
  163. data/test/test-struct-array.rb +0 -94
  164. data/test/test-struct-data-type.rb +0 -112
  165. data/test/test-table.rb +0 -1123
  166. data/test/test-time.rb +0 -288
  167. data/test/test-time32-array.rb +0 -81
  168. data/test/test-time64-array.rb +0 -81
  169. data/test/test-time64-data-type.rb +0 -42
  170. data/test/test-timestamp-array.rb +0 -45
  171. data/test/test-timestamp-data-type.rb +0 -42
  172. data/test/values/test-basic-arrays.rb +0 -325
  173. data/test/values/test-dense-union-array.rb +0 -509
  174. data/test/values/test-dictionary-array.rb +0 -295
  175. data/test/values/test-list-array.rb +0 -571
  176. data/test/values/test-map-array.rb +0 -466
  177. data/test/values/test-sparse-union-array.rb +0 -500
  178. data/test/values/test-struct-array.rb +0 -512
data/test/test-field.rb DELETED
@@ -1,91 +0,0 @@
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 FieldTest < Test::Unit::TestCase
19
- sub_test_case(".new") do
20
- test("String, Arrow::DataType") do
21
- assert_equal("visible: bool",
22
- Arrow::Field.new("visible", Arrow::BooleanDataType.new).to_s)
23
- end
24
-
25
- test("Symbol, Arrow::DataType") do
26
- assert_equal("visible: bool",
27
- Arrow::Field.new(:visible, Arrow::BooleanDataType.new).to_s)
28
- end
29
-
30
- test("String, Symbol") do
31
- assert_equal("visible: bool",
32
- Arrow::Field.new(:visible, :boolean).to_s)
33
- end
34
-
35
- test("String, Hash") do
36
- assert_equal("visible: bool",
37
- Arrow::Field.new(:visible, type: :boolean).to_s)
38
- end
39
-
40
- test("description: String") do
41
- assert_equal("visible: bool",
42
- Arrow::Field.new(name: "visible",
43
- data_type: :boolean).to_s)
44
- end
45
-
46
- test("description: Symbol") do
47
- assert_equal("visible: bool",
48
- Arrow::Field.new(name: :visible,
49
- data_type: :boolean).to_s)
50
- end
51
-
52
- test("description: shortcut") do
53
- assert_equal("visible: bool",
54
- Arrow::Field.new(name: :visible,
55
- type: :boolean).to_s)
56
- end
57
-
58
- test("Hash: shortcut: additional") do
59
- description = {
60
- name: :tags,
61
- type: :list,
62
- field: {
63
- name: "tag",
64
- type: :string,
65
- },
66
- }
67
- assert_equal("tags: list<tag: string>",
68
- Arrow::Field.new(description).to_s)
69
- end
70
- end
71
-
72
- sub_test_case("instance methods") do
73
- def setup
74
- @field = Arrow::Field.new("count", :uint32)
75
- end
76
-
77
- sub_test_case("#==") do
78
- test("Arrow::Field") do
79
- assert do
80
- @field == @field
81
- end
82
- end
83
-
84
- test("not Arrow::Field") do
85
- assert do
86
- not (@field == 29)
87
- end
88
- end
89
- end
90
- end
91
- end
@@ -1,54 +0,0 @@
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 TestFileOutputStream < Test::Unit::TestCase
19
- sub_test_case(".open") do
20
- def setup
21
- @file = Tempfile.open("arrow-file-output-stream")
22
- @file.write("Hello")
23
- @file.close
24
- end
25
-
26
- def test_default
27
- Arrow::FileOutputStream.open(@file.path) do |file|
28
- file.write(" World")
29
- end
30
- assert_equal(" World", File.read(@file.path))
31
- end
32
-
33
- def test_options_append
34
- Arrow::FileOutputStream.open(@file.path, append: true) do |file|
35
- file.write(" World")
36
- end
37
- assert_equal("Hello World", File.read(@file.path))
38
- end
39
-
40
- def test_append_true
41
- Arrow::FileOutputStream.open(@file.path, true) do |file|
42
- file.write(" World")
43
- end
44
- assert_equal("Hello World", File.read(@file.path))
45
- end
46
-
47
- def test_append_false
48
- Arrow::FileOutputStream.open(@file.path, false) do |file|
49
- file.write(" World")
50
- end
51
- assert_equal(" World", File.read(@file.path))
52
- end
53
- end
54
- end
@@ -1,92 +0,0 @@
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 FixedSizeBinaryArrayBuilderTest < Test::Unit::TestCase
19
- def setup
20
- @data_type = Arrow::FixedSizeBinaryDataType.new(4)
21
- @builder = Arrow::FixedSizeBinaryArrayBuilder.new(@data_type)
22
- end
23
-
24
- sub_test_case("#append_value") do
25
- test("nil") do
26
- @builder.append_value(nil)
27
- array = @builder.finish
28
- assert_equal(nil, array[0])
29
- end
30
-
31
- test("String") do
32
- @builder.append_value("0123")
33
- array = @builder.finish
34
- assert_equal("0123", array[0])
35
- end
36
-
37
- test("GLib::Bytes") do
38
- @builder.append_value(GLib::Bytes.new("0123"))
39
- array = @builder.finish
40
- assert_equal("0123", array[0])
41
- end
42
- end
43
-
44
- sub_test_case("#append_values") do
45
- test("mixed") do
46
- @builder.append_values([
47
- "0123",
48
- nil,
49
- GLib::Bytes.new("abcd"),
50
- ])
51
- array = @builder.finish
52
- assert_equal([
53
- "0123",
54
- nil,
55
- "abcd",
56
- ],
57
- array.to_a)
58
- end
59
-
60
- test("is_valids") do
61
- @builder.append_values([
62
- "0123",
63
- "0123",
64
- "0123",
65
- ],
66
- [
67
- true,
68
- false,
69
- true,
70
- ])
71
- array = @builder.finish
72
- assert_equal([
73
- "0123",
74
- nil,
75
- "0123",
76
- ],
77
- array.to_a)
78
- end
79
-
80
- test("packed") do
81
- @builder.append_values("0123" * 3,
82
- [true, false, true])
83
- array = @builder.finish
84
- assert_equal([
85
- "0123",
86
- nil,
87
- "0123",
88
- ],
89
- array.to_a)
90
- end
91
- end
92
- end
@@ -1,36 +0,0 @@
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 FixedSizeBinaryArrayTest < Test::Unit::TestCase
19
- sub_test_case(".new") do
20
- test("build") do
21
- data_type = Arrow::FixedSizeBinaryDataType.new(4)
22
- values = [
23
- "0123",
24
- nil,
25
- GLib::Bytes.new("abcd"),
26
- ]
27
- array = Arrow::FixedSizeBinaryArray.new(data_type, values)
28
- assert_equal([
29
- "0123",
30
- nil,
31
- "abcd",
32
- ],
33
- array.to_a)
34
- end
35
- end
36
- end
@@ -1,210 +0,0 @@
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::Column") do
57
- or_function = Arrow::Function.find("or")
58
- table = Arrow::Table.new(a: [true, false, false],
59
- b: [true, false, true])
60
- assert_equal([true, false, true],
61
- or_function.execute([table.a, table.b]).value.to_a)
62
- end
63
-
64
- test("Arrow::Scalar") do
65
- add_function = Arrow::Function.find("add")
66
- args = [
67
- Arrow::Int8Array.new([1, 2, 3]),
68
- Arrow::Int8Scalar.new(5),
69
- ]
70
- assert_equal([6, 7, 8],
71
- add_function.execute(args).value.to_a)
72
- end
73
-
74
- test("Integer") do
75
- add_function = Arrow::Function.find("add")
76
- args = [
77
- [1, 2, 3],
78
- 5,
79
- ]
80
- assert_equal([6, 7, 8],
81
- add_function.execute(args).value.to_a)
82
- end
83
-
84
- test("Float") do
85
- add_function = Arrow::Function.find("add")
86
- args = [
87
- [1, 2, 3],
88
- 5.1,
89
- ]
90
- assert_equal([6.1, 7.1, 8.1],
91
- add_function.execute(args).value.to_a)
92
- end
93
-
94
- test("true") do
95
- and_function = Arrow::Function.find("and")
96
- args = [
97
- Arrow::BooleanArray.new([true, false, false]),
98
- true,
99
- ]
100
- assert_equal([true, false, false],
101
- and_function.execute(args).value.to_a)
102
- end
103
-
104
- test("false") do
105
- or_function = Arrow::Function.find("or")
106
- args = [
107
- Arrow::BooleanArray.new([true, false, false]),
108
- false,
109
- ]
110
- assert_equal([true, false, false],
111
- or_function.execute(args).value.to_a)
112
- end
113
-
114
- test("String") do
115
- ascii_upper_function = Arrow::Function.find("ascii_upper")
116
- args = [
117
- "Hello",
118
- ]
119
- assert_equal("HELLO",
120
- ascii_upper_function.execute(args).value.to_s)
121
- end
122
-
123
- test("Date") do
124
- cast_function = Arrow::Function.find("cast")
125
- date = Date.new(2021, 6, 12)
126
- args = [date]
127
- options = {
128
- to_data_type: Arrow::TimestampDataType.new(:second),
129
- }
130
- time = Time.utc(date.year,
131
- date.month,
132
- date.day)
133
- assert_equal(Arrow::TimestampScalar.new(options[:to_data_type],
134
- time.to_i),
135
- cast_function.execute(args, options).value)
136
- end
137
-
138
- test("Arrow::Time: second") do
139
- cast_function = Arrow::Function.find("cast")
140
- arrow_time = Arrow::Time.new(Arrow::TimeUnit::SECOND,
141
- # 00:10:00
142
- 60 * 10)
143
- args = [arrow_time]
144
- options = {
145
- to_data_type: Arrow::Time64DataType.new(:micro),
146
- }
147
- assert_equal(Arrow::Time64Scalar.new(options[:to_data_type],
148
- # 00:10:00.000000
149
- 60 * 10 * 1000 * 1000),
150
- cast_function.execute(args, options).value)
151
- end
152
-
153
- test("Arrow::Time: micro") do
154
- cast_function = Arrow::Function.find("cast")
155
- arrow_time = Arrow::Time.new(Arrow::TimeUnit::MICRO,
156
- # 00:10:00.000000
157
- 60 * 10 * 1000 * 1000)
158
- args = [arrow_time]
159
- options = {
160
- to_data_type: Arrow::Time32DataType.new(:second),
161
- allow_time_truncate: true,
162
- }
163
- assert_equal(Arrow::Time32Scalar.new(options[:to_data_type],
164
- # 00:10:00
165
- 60 * 10),
166
- cast_function.execute(args, options).value)
167
- end
168
-
169
- test("Time") do
170
- cast_function = Arrow::Function.find("cast")
171
- time = Time.utc(2021, 6, 12, 1, 2, 3, 1)
172
- args = [time]
173
- options = {
174
- to_data_type: Arrow::TimestampDataType.new(:second),
175
- allow_time_truncate: true,
176
- }
177
- time = Time.utc(time.year,
178
- time.month,
179
- time.day,
180
- time.hour,
181
- time.min,
182
- time.sec)
183
- assert_equal(Arrow::TimestampScalar.new(options[:to_data_type],
184
- time.to_i),
185
- cast_function.execute(args, options).value)
186
- end
187
-
188
- test("SetLookupOptions") do
189
- is_in_function = Arrow::Function.find("is_in")
190
- args = [
191
- Arrow::Int16Array.new([1, 0, 1, 2]),
192
- ]
193
- options = {
194
- value_set: Arrow::Int16Array.new([2, 0]),
195
- }
196
- assert_equal(Arrow::BooleanArray.new([false, true, false, true]),
197
- is_in_function.execute(args, options).value)
198
- end
199
- end
200
-
201
- def test_call
202
- or_function = Arrow::Function.find("or")
203
- args = [
204
- Arrow::BooleanArray.new([true, false, false]),
205
- Arrow::BooleanArray.new([true, false, true]),
206
- ]
207
- assert_equal([true, false, true],
208
- or_function.call(args).value.to_a)
209
- end
210
- end
data/test/test-group.rb DELETED
@@ -1,180 +0,0 @@
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 GroupTest < Test::Unit::TestCase
19
- include Helper::Fixture
20
-
21
- def setup
22
- raw_table = {
23
- :group_key1 => Arrow::UInt8Array.new([1, 1, 2, 3, 3, 3]),
24
- :group_key2 => Arrow::UInt8Array.new([1, 1, 1, 1, 2, 2]),
25
- :int => Arrow::Int32Array.new([-1, -2, nil, -4, -5, -6]),
26
- :uint => Arrow::UInt32Array.new([1, nil, 3, 4, 5, 6]),
27
- :float => Arrow::FloatArray.new([nil, 2.2, 3.3, 4.4, 5.5, 6.6]),
28
- :string => Arrow::StringArray.new(["a", "b", "c", nil, "e", "f"]),
29
- }
30
- @table = Arrow::Table.new(raw_table)
31
- end
32
-
33
- sub_test_case("key") do
34
- test("Time") do
35
- time_values = [
36
- Time.parse("2018-01-29"),
37
- Time.parse("2018-01-30"),
38
- ]
39
- raw_table = {
40
- :time => Arrow::ArrayBuilder.build(time_values),
41
- :int => Arrow::Int32Array.new([-1, -2]),
42
- }
43
- table = Arrow::Table.new(raw_table)
44
- assert_equal(<<-TABLE, table.group(:time).count.to_s)
45
- count(int) time
46
- 0 1 #{time_values[0].iso8601}
47
- 1 1 #{time_values[1].iso8601}
48
- TABLE
49
- end
50
- end
51
-
52
- sub_test_case("#count") do
53
- test("single") do
54
- assert_equal(<<-TABLE, @table.group(:group_key1).count.to_s)
55
- count(group_key2) count(int) count(uint) count(float) count(string) group_key1
56
- 0 2 2 1 1 2 1
57
- 1 1 0 1 1 1 2
58
- 2 3 3 3 3 2 3
59
- TABLE
60
- end
61
-
62
- test("multiple") do
63
- assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).count.to_s)
64
- count(int) count(uint) count(float) count(string) group_key1 group_key2
65
- 0 2 1 1 2 1 1
66
- 1 0 1 1 1 2 1
67
- 2 1 1 1 0 3 1
68
- 3 2 2 2 2 3 2
69
- TABLE
70
- end
71
-
72
- test("column") do
73
- group = @table.group(:group_key1, :group_key2)
74
- assert_equal(<<-TABLE, group.count(:int, :uint).to_s)
75
- count(int) count(uint) group_key1 group_key2
76
- 0 2 1 1 1
77
- 1 0 1 2 1
78
- 2 1 1 3 1
79
- 3 2 2 3 2
80
- TABLE
81
- end
82
- end
83
-
84
- sub_test_case("#sum") do
85
- test("single") do
86
- assert_equal(<<-TABLE, @table.group(:group_key1).sum.to_s)
87
- sum(group_key2) sum(int) sum(uint) sum(float) group_key1
88
- 0 2 -3 1 2.200000 1
89
- 1 1 (null) 3 3.300000 2
90
- 2 5 -15 15 16.500000 3
91
- TABLE
92
- end
93
-
94
- test("multiple") do
95
- assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).sum.to_s)
96
- sum(int) sum(uint) sum(float) group_key1 group_key2
97
- 0 -3 1 2.200000 1 1
98
- 1 (null) 3 3.300000 2 1
99
- 2 -4 4 4.400000 3 1
100
- 3 -11 11 12.100000 3 2
101
- TABLE
102
- end
103
- end
104
-
105
- sub_test_case("#mean") do
106
- test("single") do
107
- assert_equal(<<-TABLE, @table.group(:group_key1).mean.to_s)
108
- mean(group_key2) mean(int) mean(uint) mean(float) group_key1
109
- 0 1.000000 -1.500000 1.000000 2.200000 1
110
- 1 1.000000 (null) 3.000000 3.300000 2
111
- 2 1.666667 -5.000000 5.000000 5.500000 3
112
- TABLE
113
- end
114
-
115
- test("multiple") do
116
- assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).mean.to_s)
117
- mean(int) mean(uint) mean(float) group_key1 group_key2
118
- 0 -1.500000 1.000000 2.200000 1 1
119
- 1 (null) 3.000000 3.300000 2 1
120
- 2 -4.000000 4.000000 4.400000 3 1
121
- 3 -5.500000 5.500000 6.050000 3 2
122
- TABLE
123
- end
124
- end
125
-
126
- sub_test_case("#min") do
127
- test("single") do
128
- assert_equal(<<-TABLE, @table.group(:group_key1).min.to_s)
129
- min(group_key2) min(int) min(uint) min(float) group_key1
130
- 0 1 -2 1 2.200000 1
131
- 1 1 (null) 3 3.300000 2
132
- 2 1 -6 4 4.400000 3
133
- TABLE
134
- end
135
-
136
- test("multiple") do
137
- assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).min.to_s)
138
- min(int) min(uint) min(float) group_key1 group_key2
139
- 0 -2 1 2.200000 1 1
140
- 1 (null) 3 3.300000 2 1
141
- 2 -4 4 4.400000 3 1
142
- 3 -6 5 5.500000 3 2
143
- TABLE
144
- end
145
- end
146
-
147
- sub_test_case("#max") do
148
- test("single") do
149
- assert_equal(<<-TABLE, @table.group(:group_key1).max.to_s)
150
- max(group_key2) max(int) max(uint) max(float) group_key1
151
- 0 1 -1 1 2.200000 1
152
- 1 1 (null) 3 3.300000 2
153
- 2 2 -4 6 6.600000 3
154
- TABLE
155
- end
156
-
157
- test("multiple") do
158
- assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).max.to_s)
159
- max(int) max(uint) max(float) group_key1 group_key2
160
- 0 -1 1 2.200000 1 1
161
- 1 (null) 3 3.300000 2 1
162
- 2 -4 4 4.400000 3 1
163
- 3 -5 6 6.600000 3 2
164
- TABLE
165
- end
166
- end
167
-
168
- sub_test_case("#aggregate") do
169
- test("function()") do
170
- group = @table.group(:group_key1, :group_key2)
171
- assert_equal(<<-TABLE, group.aggregate("count(int)", "sum(uint)").to_s)
172
- count(int) sum(uint) group_key1 group_key2
173
- 0 2 1 1 1
174
- 1 0 3 2 1
175
- 2 1 4 3 1
176
- 3 2 11 3 2
177
- TABLE
178
- end
179
- end
180
- end