]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/c_glib/test/test-take.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 TestTake
< Test
::Unit::TestCase
19 include Helper
::Buildable
20 include Helper
::Omittable
22 sub_test_case("Array") do
24 indices
= build_int16_array([1, 0, 2])
25 assert_equal(build_int16_array([0, 1, 2]),
26 build_int16_array([1, 0 ,2]).take(indices
))
30 indices
= build_int16_array([2, nil, 0])
31 assert_equal(build_int16_array([2, nil, 1]),
32 build_int16_array([1, 0, 2]).take(indices
))
36 indices
= build_int16_array([1, 2, 3])
37 assert_raise(Arrow
::Error::Index) do
38 build_int16_array([0, 1, 2]).take(indices
)
42 def test_chunked_array
44 build_int16_array([0, 1]),
45 build_int16_array([2])
47 taken_chunked_array
= Arrow
::ChunkedArray.new(taken_chunks
)
49 build_int16_array([1, 0]),
50 build_int16_array([2])
52 indices
= Arrow
::ChunkedArray.new(indices_chunks
)
53 assert_equal(taken_chunked_array
,
54 build_int16_array([1, 0, 2]).take_chunked_array(indices
))
58 sub_test_case("Table") do
61 Arrow
::Field.new("field1", Arrow
::Int16DataType.new
),
62 Arrow
::Field.new("field2", Arrow
::Int16DataType.new
)
64 @schema = Arrow
::Schema.new(fields
)
66 build_int16_array([0, 1, 2]),
67 build_int16_array([3, 5, 4])
69 @table = Arrow
::Table.new(@schema, arrays
)
74 build_int16_array([1, 0, 2]),
75 build_int16_array([5, 3, 4])
77 taken_table
= Arrow
::Table.new(@schema, arrays
)
78 indices
= build_int16_array([1, 0, 2])
79 assert_equal(taken_table
,
85 build_int16_array([2, nil, 0]),
86 build_int16_array([4, nil, 3])
88 taken_table
= Arrow
::Table.new(@schema, arrays
)
89 indices
= build_int16_array([2, nil, 0])
90 assert_equal(taken_table
,
95 indices
= build_int16_array([1, 2, 3])
96 assert_raise(Arrow
::Error::Index) do
101 def test_chunked_array
103 build_int16_array([1, 0, 2]),
104 build_int16_array([5, 3, 4])
106 taken_table
= Arrow
::Table.new(@schema, arrays
)
108 build_int16_array([1, 0]),
109 build_int16_array([2])
111 indices
= Arrow
::ChunkedArray.new(chunks
)
112 assert_equal(taken_table
,
113 @table.take_chunked_array(indices
))
117 sub_test_case("ChunkedArray") do
120 build_int16_array([1, 0]),
121 build_int16_array([2]),
123 @chunked_array = Arrow
::ChunkedArray.new(chunks
)
128 build_int16_array([0, 1]),
129 build_int16_array([2])
131 taken_chunked_array
= Arrow
::ChunkedArray.new(chunks
)
132 indices
= build_int16_array([1, 0, 2])
133 assert_equal(taken_chunked_array
,
134 @chunked_array.take(indices
))
139 build_int16_array([2, nil]),
140 build_int16_array([1])
142 taken_chunked_array
= Arrow
::ChunkedArray.new(chunks
)
143 indices
= build_int16_array([2, nil, 0])
144 assert_equal(taken_chunked_array
,
145 @chunked_array.take(indices
))
148 def test_out_of_index
149 indices
= build_int16_array([1, 2, 3])
150 assert_raise(Arrow
::Error::Index) do
151 @chunked_array.take(indices
)
155 def test_chunked_array
157 build_int16_array([0, 1]),
158 build_int16_array([2])
160 taken_chunked_array
= Arrow
::ChunkedArray.new(taken_chunks
)
162 build_int16_array([1, 0]),
163 build_int16_array([2])
165 indices
= Arrow
::ChunkedArray.new(indices_chunks
)
166 assert_equal(taken_chunked_array
,
167 @chunked_array.take_chunked_array(indices
))
171 sub_test_case("RecordBatch") do
174 Arrow
::Field.new("field1", Arrow
::Int16DataType.new
),
175 Arrow
::Field.new("field2", Arrow
::Int16DataType.new
)
177 @schema = Arrow
::Schema.new(fields
)
179 build_int16_array([1, 0, 2]),
180 build_int16_array([3, 5, 4])
182 @record_batch = Arrow
::RecordBatch.new(@schema, 3, columns
)
187 build_int16_array([0, 1, 2]),
188 build_int16_array([5, 3, 4])
190 taken_record_batch
= Arrow
::RecordBatch.new(@schema, 3, columns
)
191 indices
= build_int16_array([1, 0, 2])
192 assert_equal(taken_record_batch
,
193 @record_batch.take(indices
))
198 build_int16_array([2, nil, 1]),
199 build_int16_array([4, nil, 3])
201 taken_record_batch
= Arrow
::RecordBatch.new(@schema, 3, columns
)
202 indices
= build_int16_array([2, nil, 0])
203 assert_equal(taken_record_batch
,
204 @record_batch.take(indices
))
207 def test_out_of_index
208 indices
= build_int16_array([1, 2, 3])
209 assert_raise(Arrow
::Error::Index) do
210 @record_batch.take(indices
)