]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/c_glib/test/test-function.rb
import quincy 17.2.0
[ceph.git] / 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
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 TestFunction < Test::Unit::TestCase
19 include Helper::Buildable
20
21 sub_test_case("#execute") do
22 def test_array
23 or_function = Arrow::Function.find("or")
24 args = [
25 Arrow::ArrayDatum.new(build_boolean_array([true, false, false])),
26 Arrow::ArrayDatum.new(build_boolean_array([true, false, true])),
27 ]
28 assert_equal(build_boolean_array([true, false, true]),
29 or_function.execute(args).value)
30 end
31
32 def test_chunked_array
33 or_function = Arrow::Function.find("or")
34 chunked_arrays = [
35 Arrow::ChunkedArray.new([
36 build_boolean_array([true]),
37 build_boolean_array([false, false]),
38 ]),
39 Arrow::ChunkedArray.new([
40 build_boolean_array([true, false]),
41 build_boolean_array([true]),
42 ]),
43 ]
44 args = chunked_arrays.collect do |chunked_array|
45 Arrow::ChunkedArrayDatum.new(chunked_array)
46 end
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)
51 end
52
53 def test_input_scalar
54 add_function = Arrow::Function.find("add")
55 args = [
56 Arrow::ArrayDatum.new(build_int8_array([1, 2, 3])),
57 Arrow::ScalarDatum.new(Arrow::Int8Scalar.new(5)),
58 ]
59 assert_equal(build_int8_array([6, 7, 8]),
60 add_function.execute(args).value)
61 end
62
63 def test_output_scalar
64 sum_function = Arrow::Function.find("sum")
65 args = [
66 Arrow::ArrayDatum.new(build_int8_array([1, 2, 3])),
67 ]
68 assert_equal(Arrow::Int64Scalar.new(6),
69 sum_function.execute(args).value)
70 end
71
72 def test_options
73 cast_function = Arrow::Function.find("cast")
74 args = [
75 Arrow::ArrayDatum.new(build_string_array(["1", "2", "-3"])),
76 ]
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)
81 end
82 end
83 end