red-arrow 4.0.0 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -0
- data/ext/arrow/arrow.cpp +3 -0
- data/ext/arrow/converters.cpp +5 -0
- data/ext/arrow/converters.hpp +126 -0
- data/ext/arrow/extconf.rb +13 -0
- data/ext/arrow/memory-view.cpp +311 -0
- data/ext/arrow/memory-view.hpp +26 -0
- data/ext/arrow/raw-records.cpp +1 -0
- data/ext/arrow/values.cpp +1 -0
- data/lib/arrow/aggregate-node-options.rb +35 -0
- data/lib/arrow/aggregation.rb +46 -0
- data/lib/arrow/array-builder.rb +5 -0
- data/lib/arrow/array.rb +12 -0
- data/lib/arrow/binary-dictionary-array-builder.rb +27 -0
- data/lib/arrow/buffer.rb +10 -6
- data/lib/arrow/column-containable.rb +100 -1
- data/lib/arrow/constructor-arguments-gc-guardable.rb +25 -0
- data/lib/arrow/datum.rb +100 -0
- data/lib/arrow/equal-options.rb +38 -0
- data/lib/arrow/expression.rb +48 -0
- data/lib/arrow/file-system.rb +34 -0
- data/lib/arrow/group.rb +116 -124
- data/lib/arrow/loader.rb +44 -0
- data/lib/arrow/map-array-builder.rb +109 -0
- data/lib/arrow/map-array.rb +26 -0
- data/lib/arrow/map-data-type.rb +89 -0
- data/lib/arrow/path-extension.rb +1 -1
- data/lib/arrow/record-batch-reader.rb +41 -0
- data/lib/arrow/record-batch.rb +0 -2
- data/lib/arrow/scalar.rb +32 -0
- data/lib/arrow/slicer.rb +44 -143
- data/lib/arrow/source-node-options.rb +32 -0
- data/lib/arrow/string-dictionary-array-builder.rb +27 -0
- data/lib/arrow/symbol-values-appendable.rb +34 -0
- data/lib/arrow/table-concatenate-options.rb +36 -0
- data/lib/arrow/table-formatter.rb +141 -17
- data/lib/arrow/table-list-formatter.rb +5 -3
- data/lib/arrow/table-loader.rb +41 -3
- data/lib/arrow/table-saver.rb +29 -3
- data/lib/arrow/table-table-formatter.rb +7 -31
- data/lib/arrow/table.rb +34 -40
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +2 -1
- data/test/helper.rb +1 -0
- data/test/raw-records/test-dense-union-array.rb +14 -0
- data/test/raw-records/test-list-array.rb +19 -0
- data/test/raw-records/test-map-array.rb +441 -0
- data/test/raw-records/test-sparse-union-array.rb +14 -0
- data/test/raw-records/test-struct-array.rb +15 -0
- data/test/test-array-builder.rb +7 -0
- data/test/test-array.rb +34 -0
- data/test/test-binary-dictionary-array-builder.rb +103 -0
- data/test/test-boolean-scalar.rb +26 -0
- data/test/test-csv-loader.rb +8 -8
- data/test/test-expression.rb +40 -0
- data/test/test-float-scalar.rb +46 -0
- data/test/test-function.rb +176 -0
- data/test/test-group.rb +75 -51
- data/test/test-map-array-builder.rb +110 -0
- data/test/test-map-array.rb +33 -0
- data/test/test-map-data-type.rb +36 -0
- data/test/test-memory-view.rb +434 -0
- data/test/test-record-batch-reader.rb +46 -0
- data/test/test-record-batch.rb +42 -0
- data/test/test-slicer.rb +166 -167
- data/test/test-string-dictionary-array-builder.rb +103 -0
- data/test/test-table.rb +190 -53
- data/test/values/test-dense-union-array.rb +14 -0
- data/test/values/test-list-array.rb +17 -0
- data/test/values/test-map-array.rb +433 -0
- data/test/values/test-sparse-union-array.rb +14 -0
- data/test/values/test-struct-array.rb +15 -0
- metadata +132 -73
@@ -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
|
data/test/test-group.rb
CHANGED
@@ -42,9 +42,9 @@ class GroupTest < Test::Unit::TestCase
|
|
42
42
|
}
|
43
43
|
table = Arrow::Table.new(raw_table)
|
44
44
|
assert_equal(<<-TABLE, table.group(:time).count.to_s)
|
45
|
-
time
|
46
|
-
0 #{time_values[0].iso8601}
|
47
|
-
1 #{time_values[1].iso8601}
|
45
|
+
count(int) time
|
46
|
+
0 1 #{time_values[0].iso8601}
|
47
|
+
1 1 #{time_values[1].iso8601}
|
48
48
|
TABLE
|
49
49
|
end
|
50
50
|
end
|
@@ -52,20 +52,31 @@ class GroupTest < Test::Unit::TestCase
|
|
52
52
|
sub_test_case("#count") do
|
53
53
|
test("single") do
|
54
54
|
assert_equal(<<-TABLE, @table.group(:group_key1).count.to_s)
|
55
|
-
|
56
|
-
0
|
57
|
-
1
|
58
|
-
2
|
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
59
|
TABLE
|
60
60
|
end
|
61
61
|
|
62
62
|
test("multiple") do
|
63
63
|
assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).count.to_s)
|
64
|
-
|
65
|
-
0 1
|
66
|
-
1
|
67
|
-
2
|
68
|
-
3
|
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
|
69
80
|
TABLE
|
70
81
|
end
|
71
82
|
end
|
@@ -73,41 +84,41 @@ class GroupTest < Test::Unit::TestCase
|
|
73
84
|
sub_test_case("#sum") do
|
74
85
|
test("single") do
|
75
86
|
assert_equal(<<-TABLE, @table.group(:group_key1).sum.to_s)
|
76
|
-
|
77
|
-
0
|
78
|
-
1
|
79
|
-
2
|
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
|
80
91
|
TABLE
|
81
92
|
end
|
82
93
|
|
83
94
|
test("multiple") do
|
84
95
|
assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).sum.to_s)
|
85
|
-
|
86
|
-
0
|
87
|
-
1
|
88
|
-
2
|
89
|
-
3
|
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
|
90
101
|
TABLE
|
91
102
|
end
|
92
103
|
end
|
93
104
|
|
94
|
-
sub_test_case("#
|
105
|
+
sub_test_case("#mean") do
|
95
106
|
test("single") do
|
96
|
-
assert_equal(<<-TABLE, @table.group(:group_key1).
|
97
|
-
|
98
|
-
0
|
99
|
-
1
|
100
|
-
2
|
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
|
101
112
|
TABLE
|
102
113
|
end
|
103
114
|
|
104
115
|
test("multiple") do
|
105
|
-
assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).
|
106
|
-
group_key1 group_key2
|
107
|
-
0
|
108
|
-
1
|
109
|
-
2
|
110
|
-
3
|
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
|
111
122
|
TABLE
|
112
123
|
end
|
113
124
|
end
|
@@ -115,20 +126,20 @@ class GroupTest < Test::Unit::TestCase
|
|
115
126
|
sub_test_case("#min") do
|
116
127
|
test("single") do
|
117
128
|
assert_equal(<<-TABLE, @table.group(:group_key1).min.to_s)
|
118
|
-
|
119
|
-
0
|
120
|
-
1
|
121
|
-
2
|
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
|
122
133
|
TABLE
|
123
134
|
end
|
124
135
|
|
125
136
|
test("multiple") do
|
126
137
|
assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).min.to_s)
|
127
|
-
|
128
|
-
0
|
129
|
-
1
|
130
|
-
2
|
131
|
-
3
|
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
|
132
143
|
TABLE
|
133
144
|
end
|
134
145
|
end
|
@@ -136,20 +147,33 @@ class GroupTest < Test::Unit::TestCase
|
|
136
147
|
sub_test_case("#max") do
|
137
148
|
test("single") do
|
138
149
|
assert_equal(<<-TABLE, @table.group(:group_key1).max.to_s)
|
139
|
-
|
140
|
-
0
|
141
|
-
1
|
142
|
-
2
|
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
|
143
154
|
TABLE
|
144
155
|
end
|
145
156
|
|
146
157
|
test("multiple") do
|
147
158
|
assert_equal(<<-TABLE, @table.group(:group_key1, :group_key2).max.to_s)
|
148
|
-
|
149
|
-
0
|
150
|
-
1
|
151
|
-
2
|
152
|
-
3
|
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
|
153
177
|
TABLE
|
154
178
|
end
|
155
179
|
end
|
@@ -0,0 +1,110 @@
|
|
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 MapArrayBuilderTest < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
key_type = Arrow::StringDataType.new
|
21
|
+
item_type = Arrow::Int16DataType.new
|
22
|
+
data_type = Arrow::MapDataType.new(key_type, item_type)
|
23
|
+
@builder = Arrow::MapArrayBuilder.new(data_type)
|
24
|
+
end
|
25
|
+
|
26
|
+
sub_test_case("#append_value") do
|
27
|
+
test("nil") do
|
28
|
+
@builder.append_value(nil)
|
29
|
+
array = @builder.finish
|
30
|
+
assert_equal([nil], array.collect {|value| value})
|
31
|
+
end
|
32
|
+
|
33
|
+
test("Hash") do
|
34
|
+
@builder.append_value({"a" => 0, "b" => 1})
|
35
|
+
@builder.append_value({"c" => 0, "d" => 1})
|
36
|
+
array = @builder.finish
|
37
|
+
assert_equal([
|
38
|
+
{"a" => 0, "b" => 1},
|
39
|
+
{"c" => 0, "d" => 1}
|
40
|
+
],
|
41
|
+
array.collect {|value| value})
|
42
|
+
end
|
43
|
+
|
44
|
+
test("#each") do
|
45
|
+
@builder.append_value([["a", 0], ["b", 1]])
|
46
|
+
@builder.append_value([["c", 0], ["d", 1]])
|
47
|
+
array = @builder.finish
|
48
|
+
assert_equal([
|
49
|
+
{"a" => 0, "b" => 1},
|
50
|
+
{"c" => 0, "d" => 1}
|
51
|
+
],
|
52
|
+
array.collect {|value| value})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
sub_test_case("#append_values") do
|
57
|
+
test("[nil]") do
|
58
|
+
@builder.append_values([nil])
|
59
|
+
array = @builder.finish
|
60
|
+
assert_equal([nil], array.collect {|value| value})
|
61
|
+
end
|
62
|
+
|
63
|
+
test("[Hash]") do
|
64
|
+
@builder.append_values([{"a" => 0, "b" => 1}, {"c" => 0, "d" => 1}])
|
65
|
+
array = @builder.finish
|
66
|
+
assert_equal([
|
67
|
+
{"a" => 0, "b" => 1},
|
68
|
+
{"c" => 0, "d" => 1}
|
69
|
+
],
|
70
|
+
array.collect {|value| value})
|
71
|
+
end
|
72
|
+
|
73
|
+
test("[#each]") do
|
74
|
+
@builder.append_values([[["a", 0], ["b", 1]], [["c", 0], ["d", 1]]])
|
75
|
+
array = @builder.finish
|
76
|
+
assert_equal([
|
77
|
+
{"a" => 0, "b" => 1},
|
78
|
+
{"c" => 0, "d" => 1}
|
79
|
+
],
|
80
|
+
array.collect {|value| value})
|
81
|
+
end
|
82
|
+
|
83
|
+
test("[nil, Hash, #each]") do
|
84
|
+
@builder.append_values([nil, {"a" => 0, "b" => 1}, [["c", 0], ["d", 1]]])
|
85
|
+
array = @builder.finish
|
86
|
+
assert_equal([
|
87
|
+
nil,
|
88
|
+
{"a" => 0, "b" => 1},
|
89
|
+
{"c" => 0, "d" => 1}
|
90
|
+
],
|
91
|
+
array.collect {|value| value})
|
92
|
+
end
|
93
|
+
|
94
|
+
test("is_valids") do
|
95
|
+
@builder.append_values([
|
96
|
+
{"a" => 0, "b" => 1},
|
97
|
+
{"c" => 0, "d" => 1},
|
98
|
+
{"e" => 0, "f" => 1}
|
99
|
+
],
|
100
|
+
[true, false, true])
|
101
|
+
array = @builder.finish
|
102
|
+
assert_equal([
|
103
|
+
{"a" => 0, "b" => 1},
|
104
|
+
nil,
|
105
|
+
{"e" => 0, "f" => 1}
|
106
|
+
],
|
107
|
+
array.collect {|value| value})
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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 MapArrayTest < Test::Unit::TestCase
|
19
|
+
sub_test_case(".new") do
|
20
|
+
test("build") do
|
21
|
+
key_type = Arrow::StringDataType.new
|
22
|
+
item_type = Arrow::Int16DataType.new
|
23
|
+
data_type = Arrow::MapDataType.new(key_type, item_type)
|
24
|
+
values = [
|
25
|
+
{"a" => 0, "b" => 1},
|
26
|
+
nil,
|
27
|
+
{"c" => 0, "d" => 1}
|
28
|
+
]
|
29
|
+
array = Arrow::MapArray.new(data_type, values)
|
30
|
+
assert_equal(values, array.collect {|value| value})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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 MapDataTypeTest < Test::Unit::TestCase
|
19
|
+
sub_test_case(".new") do
|
20
|
+
def setup
|
21
|
+
@key = :int8
|
22
|
+
@item = :string
|
23
|
+
end
|
24
|
+
|
25
|
+
test("ordered arguments") do
|
26
|
+
assert_equal("map<int8, string>",
|
27
|
+
Arrow::MapDataType.new(@key, @item).to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
test("description") do
|
31
|
+
assert_equal("map<int8, string>",
|
32
|
+
Arrow::MapDataType.new(key: @key,
|
33
|
+
item: @item).to_s)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|