|
| 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 TestMakeStructOptions < Test::Unit::TestCase |
| 19 | + def test_make_struct_function |
| 20 | + a = Arrow::Int8Array.new([1, 2, 3]) |
| 21 | + b = Arrow::BooleanArray.new([true, false, nil]) |
| 22 | + metadata1 = {"a" => "b"} |
| 23 | + metadata2 = {"c" => "d"} |
| 24 | + options = { |
| 25 | + field_names: ["a", "b"], |
| 26 | + field_nullability: [false, true], |
| 27 | + field_metadata: [metadata1, metadata2] |
| 28 | + } |
| 29 | + args = [a, b] |
| 30 | + make_struct_function = Arrow::Function.find("make_struct") |
| 31 | + result = make_struct_function.execute(args, options).value |
| 32 | + |
| 33 | + expected = Arrow::StructArray.new( |
| 34 | + Arrow::StructDataType.new( |
| 35 | + [ |
| 36 | + Arrow::Field.new("a", Arrow::Int8DataType.new, false), |
| 37 | + Arrow::Field.new("b", Arrow::BooleanDataType.new, true), |
| 38 | + ] |
| 39 | + ), |
| 40 | + [ |
| 41 | + {"a" => 1, "b" => true}, |
| 42 | + {"a" => 2, "b" => false}, |
| 43 | + {"a" => 3, "b" => nil}, |
| 44 | + ] |
| 45 | + ) |
| 46 | + assert_equal(expected, result) |
| 47 | + fields = result.value_data_type.fields |
| 48 | + assert_equal(metadata1, fields[0].metadata) |
| 49 | + assert_equal(metadata2, fields[1].metadata) |
| 50 | + end |
| 51 | +end |
0 commit comments