]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/ruby/red-arrow/test/test-schema.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 SchemaTest
< Test
::Unit::TestCase
19 include Helper
::Omittable
22 @count_field = Arrow
::Field.new("count", :uint32)
23 @visible_field = Arrow
::Field.new("visible", :boolean)
26 sub_test_case(".new") do
27 test("[Arrow::Field]") do
32 assert_equal("count: uint32\n" +
34 Arrow
::Schema.new(fields
).to_s
)
37 test("[Arrow::Field, Hash]") do
40 {name
: "visible", type
: :boolean},
42 assert_equal("count: uint32\n" +
44 Arrow
::Schema.new(fields
).to_s
)
47 test("{String, Symbol => Arrow::DataType}") do
49 "count" => Arrow
::UInt32DataType.new
,
52 assert_equal("count: uint32\n" +
54 Arrow
::Schema.new(fields
).to_s
)
57 test("{String, Symbol => Hash}") do
59 "count" => {type
: :uint32},
68 assert_equal("count: uint32\n" +
69 "tags: list<tag: string>",
70 Arrow
::Schema.new(fields
).to_s
)
74 sub_test_case("instance methods") do
77 @schema = Arrow
::Schema.new([@count_field, @visible_field])
80 sub_test_case("#[]") do
82 assert_equal([@count_field, @visible_field],
83 [@schema["count"], @schema["visible"]])
87 assert_equal([@count_field, @visible_field],
88 [@schema[:count], @schema[:visible]])
92 assert_equal([@count_field, @visible_field],
93 [@schema[0], @schema[1]])
98 message
= "field name or index must be String, Symbol or Integer"
99 message
<< ": <#{invalid.inspect}>"
100 assert_raise(ArgumentError
.new(message
)) do
106 sub_test_case("#==") do
107 test("Arrow::Schema") do
113 test("not Arrow::Schema") do
120 sub_test_case("#to_s") do
121 test("show_metadata") do
122 require_gi_bindings(3, 4, 2)
124 schema
= @schema.with_metadata("key" => "value")
125 assert_equal(<<-SCHEMA.chomp, schema.to_s(show_metadata: true))