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 | #include <cstdint> |
19 | #include <cstdio> |
20 | #include <functional> |
21 | #include <locale> |
22 | #include <memory> |
23 | #include <stdexcept> |
24 | #include <string> |
25 | #include <vector> |
26 | |
27 | #include <gtest/gtest.h> |
28 | |
29 | #include "arrow/array.h" |
30 | #include "arrow/buffer.h" |
31 | #include "arrow/memory_pool.h" |
32 | #include "arrow/status.h" |
33 | #include "arrow/table.h" |
34 | #include "arrow/test-common.h" |
35 | #include "arrow/test-util.h" |
36 | #include "arrow/type.h" |
37 | #include "arrow/type_traits.h" |
38 | #include "arrow/util/decimal.h" |
39 | |
40 | #include "arrow/compute/context.h" |
41 | #include "arrow/compute/kernel.h" |
42 | #include "arrow/compute/kernels/util-internal.h" |
43 | #include "arrow/compute/test-util.h" |
44 | |
45 | using std::shared_ptr; |
46 | using std::vector; |
47 | |
48 | namespace arrow { |
49 | namespace compute { |
50 | |
51 | // ---------------------------------------------------------------------- |
52 | // Datum |
53 | |
54 | template <typename T> |
55 | void CheckImplicitConstructor(enum Datum::type expected_kind) { |
56 | std::shared_ptr<T> value; |
57 | Datum datum = value; |
58 | ASSERT_EQ(expected_kind, datum.kind()); |
59 | } |
60 | |
61 | TEST(TestDatum, ImplicitConstructors) { |
62 | CheckImplicitConstructor<Array>(Datum::ARRAY); |
63 | |
64 | // Instantiate from array subclass |
65 | CheckImplicitConstructor<BinaryArray>(Datum::ARRAY); |
66 | |
67 | CheckImplicitConstructor<ChunkedArray>(Datum::CHUNKED_ARRAY); |
68 | CheckImplicitConstructor<RecordBatch>(Datum::RECORD_BATCH); |
69 | CheckImplicitConstructor<Table>(Datum::TABLE); |
70 | } |
71 | |
72 | class TestInvokeBinaryKernel : public ComputeFixture, public TestBase {}; |
73 | |
74 | class DummyBinaryKernel : public BinaryKernel { |
75 | Status Call(FunctionContext* ctx, const Datum& left, const Datum& right, |
76 | Datum* out) override { |
77 | return Status::OK(); |
78 | } |
79 | }; |
80 | |
81 | TEST_F(TestInvokeBinaryKernel, Exceptions) { |
82 | DummyBinaryKernel kernel; |
83 | std::vector<Datum> outputs; |
84 | std::shared_ptr<Table> table; |
85 | vector<bool> values1 = {true, false, true}; |
86 | vector<bool> values2 = {false, true, false}; |
87 | |
88 | auto type = boolean(); |
89 | auto a1 = _MakeArray<BooleanType, bool>(type, values1, {}); |
90 | auto a2 = _MakeArray<BooleanType, bool>(type, values2, {}); |
91 | |
92 | // Left is not an array-like |
93 | ASSERT_RAISES(Invalid, detail::InvokeBinaryArrayKernel(&this->ctx_, &kernel, table, a2, |
94 | &outputs)); |
95 | // Right is not an array-like |
96 | ASSERT_RAISES(Invalid, detail::InvokeBinaryArrayKernel(&this->ctx_, &kernel, a1, table, |
97 | &outputs)); |
98 | // Different sized inputs |
99 | ASSERT_RAISES(Invalid, detail::InvokeBinaryArrayKernel(&this->ctx_, &kernel, a1, |
100 | a1->Slice(1), &outputs)); |
101 | } |
102 | |
103 | } // namespace compute |
104 | } // namespace arrow |
105 | |