]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
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 TestGandivaNativeFunction < Test::Unit::TestCase | |
19 | include Helper::DataType | |
20 | ||
21 | def setup | |
22 | omit("Gandiva is required") unless defined?(::Gandiva) | |
23 | @registry = Gandiva::FunctionRegistry.new | |
24 | @not = lookup("not", [boolean_data_type], boolean_data_type) | |
25 | @isnull = lookup("isnull", [int8_data_type], boolean_data_type) | |
26 | end | |
27 | ||
28 | def lookup(name, param_types, return_type) | |
29 | signature = Gandiva::FunctionSignature.new(name, | |
30 | param_types, | |
31 | return_type) | |
32 | @registry.lookup(signature) | |
33 | end | |
34 | ||
35 | def test_signatures | |
36 | assert_equal([Gandiva::FunctionSignature], | |
37 | @not.signatures.collect(&:class).uniq) | |
38 | end | |
39 | ||
40 | sub_test_case("equal") do | |
41 | def test_true | |
42 | assert do | |
43 | @not == @registry.lookup(@not.signatures[0]) | |
44 | end | |
45 | end | |
46 | ||
47 | def test_false | |
48 | assert do | |
49 | @not != @isnull | |
50 | end | |
51 | end | |
52 | end | |
53 | ||
54 | def test_to_string | |
55 | modulo = lookup("modulo", | |
56 | [int64_data_type, int64_data_type], | |
57 | int64_data_type) | |
58 | assert_equal(modulo.signatures.collect(&:to_s).join(", "), | |
59 | modulo.to_s) | |
60 | end | |
61 | ||
62 | sub_test_case("get_result_nullbale_type") do | |
63 | def test_if_null | |
64 | assert_equal(Gandiva::ResultNullableType::IF_NULL, | |
65 | @not.result_nullable_type) | |
66 | end | |
67 | ||
68 | def test_never | |
69 | assert_equal(Gandiva::ResultNullableType::NEVER, | |
70 | @isnull.result_nullable_type) | |
71 | end | |
72 | ||
73 | def test_internal | |
74 | to_date = lookup("to_date", | |
75 | [string_data_type, string_data_type, int32_data_type], | |
76 | date64_data_type) | |
77 | assert_equal(Gandiva::ResultNullableType::INTERNAL, | |
78 | to_date.result_nullable_type) | |
79 | end | |
80 | end | |
81 | ||
82 | sub_test_case("need_context") do | |
83 | def test_need | |
84 | assert do | |
85 | not @not.need_context | |
86 | end | |
87 | end | |
88 | ||
89 | def test_not_need | |
90 | upper = lookup("upper", | |
91 | [string_data_type], | |
92 | string_data_type) | |
93 | assert do | |
94 | upper.need_context | |
95 | end | |
96 | end | |
97 | end | |
98 | ||
99 | sub_test_case("need_function_holder") do | |
100 | def test_need | |
101 | like = lookup("like", | |
102 | [string_data_type, string_data_type], | |
103 | boolean_data_type) | |
104 | assert do | |
105 | like.need_function_holder | |
106 | end | |
107 | end | |
108 | ||
109 | def test_not_need | |
110 | assert do | |
111 | not @not.need_function_holder | |
112 | end | |
113 | end | |
114 | end | |
115 | ||
116 | sub_test_case("can_return_errors") do | |
117 | def test_can | |
118 | divide = lookup("divide", | |
119 | [int8_data_type, int8_data_type], | |
120 | int8_data_type) | |
121 | assert do | |
122 | divide.can_return_errors? | |
123 | end | |
124 | end | |
125 | ||
126 | def test_not_can | |
127 | assert do | |
128 | not @not.can_return_errors? | |
129 | end | |
130 | end | |
131 | end | |
132 | end |