]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/ruby/red-arrow/test/test-struct-array-builder.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 StructArrayBuilderTest
< Test
::Unit::TestCase
20 @data_type = Arrow
::StructDataType.new(visible
: {type
: :boolean},
21 count
: {type
: :uint64})
22 @builder = Arrow
::StructArrayBuilder.new(@data_type)
25 sub_test_case("#append_value") do
27 @builder.append_value(nil)
28 array
= @builder.finish
34 array
.find_field(0).to_a
,
35 array
.find_field(1).to_a
,
40 @builder.append_value([true, 1])
41 @builder.append_value([])
42 @builder.append_value([false])
43 array
= @builder.finish
49 array
.find_field(0).to_a
,
50 array
.find_field(1).to_a
,
54 test("Arrow::Struct") do
55 source_array
= Arrow
::StructArray.new(@data_type, [[true, 1]])
56 struct
= source_array
.get_value(0)
57 @builder.append_value(struct
)
58 array
= @builder.finish
64 array
.find_field(0).to_a
,
65 array
.find_field(1).to_a
,
70 @builder.append_value(count
: 1, visible
: true)
71 @builder.append_value(visible
: false)
72 @builder.append_value(count
: 2)
73 array
= @builder.finish
79 array
.find_field(0).to_a
,
80 array
.find_field(1).to_a
,
85 sub_test_case("#append_values") do
87 @builder.append_values([nil])
88 array
= @builder.finish
94 array
.find_field(0).to_a
,
95 array
.find_field(1).to_a
,
100 @builder.append_values([[true, 1]])
101 array
= @builder.finish
107 array
.find_field(0).to_a
,
108 array
.find_field(1).to_a
,
113 @builder.append_values([{count
: 1, visible
: true}])
114 array
= @builder.finish
120 array
.find_field(0).to_a
,
121 array
.find_field(1).to_a
,
125 test("[nil, Array, Hash]") do
126 @builder.append_values([
129 {count
: 2, visible
: false},
131 array
= @builder.finish
133 [false, true, false],
137 array
.find_field(0).to_a
,
138 array
.find_field(1).to_a
,
143 @builder.append_values([
153 array
= @builder.finish
159 array
.find_field(0).to_a
,
160 array
.find_field(1).to_a
,
165 sub_test_case("#append") do
166 test("backward compatibility") do
168 @builder.get_field_builder(0).append(true)
169 @builder.get_field_builder(1).append(1)
171 @builder.get_field_builder(0).append(false)
172 @builder.get_field_builder(1).append(2)
173 array
= @builder.finish
175 {"visible" => true, "count" => 1},
176 {"visible" => false, "count" => 2},