]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/ruby/red-arrow/test/test-chunked-array.rb
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
18 class ChunkedArrayTest
< Test
::Unit::TestCase
21 Arrow
::BooleanArray.new([true, false]),
22 Arrow
::BooleanArray.new([nil, true]),
24 chunked_array
= Arrow
::ChunkedArray.new(arrays
)
25 assert_equal([true, false, nil, true],
29 sub_test_case("#pack") do
30 test("basic array") do
32 Arrow
::BooleanArray.new([true, false]),
33 Arrow
::BooleanArray.new([nil, true]),
35 chunked_array
= Arrow
::ChunkedArray.new(arrays
)
36 packed_chunked_array
= chunked_array
.pack
39 [true, false, nil, true],
42 packed_chunked_array
.class,
43 packed_chunked_array
.to_a
,
47 test("TimestampArray") do
48 type
= Arrow
::TimestampDataType.new(:nano)
50 Arrow
::TimestampArrayBuilder.new(type
).build([Time
.at(0)]),
51 Arrow
::TimestampArrayBuilder.new(type
).build([Time
.at(1)]),
53 chunked_array
= Arrow
::ChunkedArray.new(arrays
)
54 packed_chunked_array
= chunked_array
.pack
56 Arrow
::TimestampArray,
57 [Time
.at(0), Time
.at(1)],
60 packed_chunked_array
.class,
61 packed_chunked_array
.to_a
,
66 sub_test_case("#==") do
69 Arrow
::BooleanArray.new([true]),
70 Arrow
::BooleanArray.new([false, true]),
72 @chunked_array = Arrow
::ChunkedArray.new(arrays
)
75 test("Arrow::ChunkedArray") do
77 @chunked_array == @chunked_array
81 test("not Arrow::ChunkedArray") do
83 not (@chunked_array == 29)
88 sub_test_case("#filter") do
91 Arrow
::BooleanArray.new([false, true]),
92 Arrow
::BooleanArray.new([false, true, false]),
94 @chunked_array = Arrow
::ChunkedArray.new(arrays
)
95 @options = Arrow
::FilterOptions.new
96 @options.null_selection_behavior
= :emit_null
99 test("Array: boolean") do
100 filter
= [nil, true, true, false, true]
102 Arrow
::BooleanArray.new([nil, true]),
103 Arrow
::BooleanArray.new([false, false]),
105 filtered_chunked_array
= Arrow
::ChunkedArray.new(chunks
)
106 assert_equal(filtered_chunked_array
,
107 @chunked_array.filter(filter
, @options))
110 test("Arrow::BooleanArray") do
111 filter
= Arrow
::BooleanArray.new([nil, true, true, false, true])
113 Arrow
::BooleanArray.new([nil, true]),
114 Arrow
::BooleanArray.new([false, false]),
116 filtered_chunked_array
= Arrow
::ChunkedArray.new(chunks
)
117 assert_equal(filtered_chunked_array
,
118 @chunked_array.filter(filter
, @options))
121 test("Arrow::ChunkedArray") do
123 Arrow
::BooleanArray.new([nil, true]),
124 Arrow
::BooleanArray.new([true, false, true]),
126 filter
= Arrow
::ChunkedArray.new(chunks
)
128 Arrow
::BooleanArray.new([nil, true]),
129 Arrow
::BooleanArray.new([false, false]),
131 filtered_chunked_array
= Arrow
::ChunkedArray.new(filtered_chunks
)
132 assert_equal(filtered_chunked_array
,
133 @chunked_array.filter(filter
, @options))
137 sub_test_case("#take") do
140 Arrow
::Int16Array.new([1, 0]),
141 Arrow
::Int16Array.new([2]),
143 @chunked_array = Arrow
::ChunkedArray.new(chunks
)
146 test("Arrow: boolean") do
148 Arrow
::Int16Array.new([0, 1]),
149 Arrow
::Int16Array.new([2])
151 taken_chunked_array
= Arrow
::ChunkedArray.new(chunks
)
153 assert_equal(taken_chunked_array
,
154 @chunked_array.take(indices
))
157 test("Arrow::Array") do
159 Arrow
::Int16Array.new([0, 1]),
160 Arrow
::Int16Array.new([2])
162 taken_chunked_array
= Arrow
::ChunkedArray.new(chunks
)
163 indices
= Arrow
::Int16Array.new([1, 0, 2])
164 assert_equal(taken_chunked_array
,
165 @chunked_array.take(indices
))
168 test("Arrow::ChunkedArray") do
170 Arrow
::Int16Array.new([0, 1]),
171 Arrow
::Int16Array.new([2])
173 taken_chunked_array
= Arrow
::ChunkedArray.new(taken_chunks
)
175 Arrow
::Int16Array.new([1, 0]),
176 Arrow
::Int16Array.new([2])
178 indices
= Arrow
::ChunkedArray.new(indices_chunks
)
179 assert_equal(taken_chunked_array
,
180 @chunked_array.take(indices
))