]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/arrow/dbi/hiveserver2/columnar_row_set.cc
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / arrow / dbi / hiveserver2 / columnar_row_set.cc
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 "arrow/dbi/hiveserver2/columnar_row_set.h"
19
20 #include <string>
21 #include <vector>
22
23 #include "arrow/dbi/hiveserver2/TCLIService.h"
24 #include "arrow/dbi/hiveserver2/thrift_internal.h"
25
26 #include "arrow/util/logging.h"
27
28 namespace hs2 = apache::hive::service::cli::thrift;
29
30 namespace arrow {
31 namespace hiveserver2 {
32
33 Column::Column(const std::string* nulls) {
34 DCHECK(nulls);
35 nulls_ = reinterpret_cast<const uint8_t*>(nulls->c_str());
36 nulls_size_ = static_cast<int64_t>(nulls->size());
37 }
38
39 ColumnarRowSet::ColumnarRowSet(ColumnarRowSetImpl* impl) : impl_(impl) {}
40
41 ColumnarRowSet::~ColumnarRowSet() = default;
42
43 template <typename T>
44 struct type_helpers {};
45
46 #define VALUE_GETTER(COLUMN_TYPE, VALUE_TYPE, ATTR_NAME) \
47 template <> \
48 struct type_helpers<COLUMN_TYPE> { \
49 static const std::vector<VALUE_TYPE>* GetValues(const hs2::TColumn& col) { \
50 return &col.ATTR_NAME.values; \
51 } \
52 \
53 static const std::string* GetNulls(const hs2::TColumn& col) { \
54 return &col.ATTR_NAME.nulls; \
55 } \
56 };
57
58 VALUE_GETTER(BoolColumn, bool, boolVal);
59 VALUE_GETTER(ByteColumn, int8_t, byteVal);
60 VALUE_GETTER(Int16Column, int16_t, i16Val);
61 VALUE_GETTER(Int32Column, int32_t, i32Val);
62 VALUE_GETTER(Int64Column, int64_t, i64Val);
63 VALUE_GETTER(DoubleColumn, double, doubleVal);
64 VALUE_GETTER(StringColumn, std::string, stringVal);
65
66 #undef VALUE_GETTER
67
68 template <typename T>
69 std::unique_ptr<T> ColumnarRowSet::GetCol(int i) const {
70 using helper = type_helpers<T>;
71
72 DCHECK_LT(i, static_cast<int>(impl_->resp.results.columns.size()));
73
74 const hs2::TColumn& col = impl_->resp.results.columns[i];
75 return std::unique_ptr<T>(new T(helper::GetNulls(col), helper::GetValues(col)));
76 }
77
78 #define TYPED_GETTER(FUNC_NAME, TYPE) \
79 std::unique_ptr<TYPE> ColumnarRowSet::FUNC_NAME(int i) const { \
80 return GetCol<TYPE>(i); \
81 } \
82 template std::unique_ptr<TYPE> ColumnarRowSet::GetCol<TYPE>(int i) const;
83
84 TYPED_GETTER(GetBoolCol, BoolColumn);
85 TYPED_GETTER(GetByteCol, ByteColumn);
86 TYPED_GETTER(GetInt16Col, Int16Column);
87 TYPED_GETTER(GetInt32Col, Int32Column);
88 TYPED_GETTER(GetInt64Col, Int64Column);
89 TYPED_GETTER(GetDoubleCol, DoubleColumn);
90 TYPED_GETTER(GetStringCol, StringColumn);
91
92 #undef TYPED_GETTER
93
94 // BinaryColumn is an alias for StringColumn
95 std::unique_ptr<BinaryColumn> ColumnarRowSet::GetBinaryCol(int i) const {
96 return GetCol<BinaryColumn>(i);
97 }
98
99 } // namespace hiveserver2
100 } // namespace arrow