]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/gandiva/tests/test_util.h
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / gandiva / tests / test_util.h
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 <chrono>
19 #include <memory>
20 #include <utility>
21 #include <vector>
22
23 #include "arrow/testing/gtest_util.h"
24 #include "gandiva/arrow.h"
25 #include "gandiva/configuration.h"
26
27 #pragma once
28
29 namespace gandiva {
30
31 // Helper function to create an arrow-array of type ARROWTYPE
32 // from primitive vectors of data & validity.
33 //
34 // arrow/testing/gtest_util.h has good utility classes for this purpose.
35 // Using those
36 template <typename TYPE, typename C_TYPE>
37 static inline ArrayPtr MakeArrowArray(std::vector<C_TYPE> values,
38 std::vector<bool> validity) {
39 ArrayPtr out;
40 arrow::ArrayFromVector<TYPE, C_TYPE>(validity, values, &out);
41 return out;
42 }
43
44 template <typename TYPE, typename C_TYPE>
45 static inline ArrayPtr MakeArrowArray(std::vector<C_TYPE> values) {
46 ArrayPtr out;
47 arrow::ArrayFromVector<TYPE, C_TYPE>(values, &out);
48 return out;
49 }
50
51 template <typename TYPE, typename C_TYPE>
52 static inline ArrayPtr MakeArrowArray(const std::shared_ptr<arrow::DataType>& type,
53 std::vector<C_TYPE> values,
54 std::vector<bool> validity) {
55 ArrayPtr out;
56 arrow::ArrayFromVector<TYPE, C_TYPE>(type, validity, values, &out);
57 return out;
58 }
59
60 template <typename TYPE, typename C_TYPE>
61 static inline ArrayPtr MakeArrowTypeArray(const std::shared_ptr<arrow::DataType>& type,
62 const std::vector<C_TYPE>& values,
63 const std::vector<bool>& validity) {
64 ArrayPtr out;
65 arrow::ArrayFromVector<TYPE, C_TYPE>(type, validity, values, &out);
66 return out;
67 }
68
69 #define MakeArrowArrayBool MakeArrowArray<arrow::BooleanType, bool>
70 #define MakeArrowArrayInt8 MakeArrowArray<arrow::Int8Type, int8_t>
71 #define MakeArrowArrayInt16 MakeArrowArray<arrow::Int16Type, int16_t>
72 #define MakeArrowArrayInt32 MakeArrowArray<arrow::Int32Type, int32_t>
73 #define MakeArrowArrayInt64 MakeArrowArray<arrow::Int64Type, int64_t>
74 #define MakeArrowArrayUint8 MakeArrowArray<arrow::UInt8Type, uint8_t>
75 #define MakeArrowArrayUint16 MakeArrowArray<arrow::UInt16Type, uint16_t>
76 #define MakeArrowArrayUint32 MakeArrowArray<arrow::UInt32Type, uint32_t>
77 #define MakeArrowArrayUint64 MakeArrowArray<arrow::UInt64Type, uint64_t>
78 #define MakeArrowArrayFloat32 MakeArrowArray<arrow::FloatType, float>
79 #define MakeArrowArrayFloat64 MakeArrowArray<arrow::DoubleType, double>
80 #define MakeArrowArrayDate64 MakeArrowArray<arrow::Date64Type, int64_t>
81 #define MakeArrowArrayUtf8 MakeArrowArray<arrow::StringType, std::string>
82 #define MakeArrowArrayBinary MakeArrowArray<arrow::BinaryType, std::string>
83 #define MakeArrowArrayDecimal MakeArrowArray<arrow::Decimal128Type, arrow::Decimal128>
84
85 #define EXPECT_ARROW_ARRAY_EQUALS(a, b) \
86 EXPECT_TRUE((a)->Equals(b, arrow::EqualOptions().nans_equal(true))) \
87 << "expected array: " << (a)->ToString() << " actual array: " << (b)->ToString()
88
89 #define EXPECT_ARROW_ARRAY_APPROX_EQUALS(a, b, epsilon) \
90 EXPECT_TRUE( \
91 (a)->ApproxEquals(b, arrow::EqualOptions().atol(epsilon).nans_equal(true))) \
92 << "expected array: " << (a)->ToString() << " actual array: " << (b)->ToString()
93
94 #define EXPECT_ARROW_TYPE_EQUALS(a, b) \
95 EXPECT_TRUE((a)->Equals(b)) << "expected type: " << (a)->ToString() \
96 << " actual type: " << (b)->ToString()
97
98 static inline std::shared_ptr<Configuration> TestConfiguration() {
99 auto builder = ConfigurationBuilder();
100 return builder.DefaultConfiguration();
101 }
102
103 } // namespace gandiva