]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/c_glib/test/test-function.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 TestFunction
< Test
::Unit::TestCase
19 include Helper
::Buildable
21 sub_test_case("#execute") do
23 or_function
= Arrow
::Function.find("or")
25 Arrow
::ArrayDatum.new(build_boolean_array([true, false, false])),
26 Arrow
::ArrayDatum.new(build_boolean_array([true, false, true])),
28 assert_equal(build_boolean_array([true, false, true]),
29 or_function
.execute(args
).value
)
32 def test_chunked_array
33 or_function
= Arrow
::Function.find("or")
35 Arrow
::ChunkedArray.new([
36 build_boolean_array([true]),
37 build_boolean_array([false, false]),
39 Arrow
::ChunkedArray.new([
40 build_boolean_array([true, false]),
41 build_boolean_array([true]),
44 args
= chunked_arrays
.collect
do |chunked_array
|
45 Arrow
::ChunkedArrayDatum.new(chunked_array
)
47 expected_array
= build_boolean_array([true, false, true])
48 expected
= Arrow
::ChunkedArray.new([expected_array
])
49 assert_equal(expected
,
50 or_function
.execute(args
).value
)
54 add_function
= Arrow
::Function.find("add")
56 Arrow
::ArrayDatum.new(build_int8_array([1, 2, 3])),
57 Arrow
::ScalarDatum.new(Arrow
::Int8Scalar.new(5)),
59 assert_equal(build_int8_array([6, 7, 8]),
60 add_function
.execute(args
).value
)
63 def test_output_scalar
64 sum_function
= Arrow
::Function.find("sum")
66 Arrow
::ArrayDatum.new(build_int8_array([1, 2, 3])),
68 assert_equal(Arrow
::Int64Scalar.new(6),
69 sum_function
.execute(args
).value
)
73 cast_function
= Arrow
::Function.find("cast")
75 Arrow
::ArrayDatum.new(build_string_array(["1", "2", "-3"])),
77 options
= Arrow
::CastOptions.new
78 options
.to_data_type
= Arrow
::Int8DataType.new
79 assert_equal(build_int8_array([1, 2, -3]),
80 cast_function
.execute(args
, options
).value
)