]>
git.proxmox.com Git - ceph.git/blob - 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
9 // http://www.apache.org/licenses/LICENSE-2.0
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
18 #include "arrow/dbi/hiveserver2/columnar_row_set.h"
23 #include "arrow/dbi/hiveserver2/TCLIService.h"
24 #include "arrow/dbi/hiveserver2/thrift_internal.h"
26 #include "arrow/util/logging.h"
28 namespace hs2
= apache::hive::service::cli::thrift
;
31 namespace hiveserver2
{
33 Column::Column(const std::string
* nulls
) {
35 nulls_
= reinterpret_cast<const uint8_t*>(nulls
->c_str());
36 nulls_size_
= static_cast<int64_t>(nulls
->size());
39 ColumnarRowSet::ColumnarRowSet(ColumnarRowSetImpl
* impl
) : impl_(impl
) {}
41 ColumnarRowSet::~ColumnarRowSet() = default;
44 struct type_helpers
{};
46 #define VALUE_GETTER(COLUMN_TYPE, VALUE_TYPE, ATTR_NAME) \
48 struct type_helpers<COLUMN_TYPE> { \
49 static const std::vector<VALUE_TYPE>* GetValues(const hs2::TColumn& col) { \
50 return &col.ATTR_NAME.values; \
53 static const std::string* GetNulls(const hs2::TColumn& col) { \
54 return &col.ATTR_NAME.nulls; \
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
);
69 std::unique_ptr
<T
> ColumnarRowSet::GetCol(int i
) const {
70 using helper
= type_helpers
<T
>;
72 DCHECK_LT(i
, static_cast<int>(impl_
->resp
.results
.columns
.size()));
74 const hs2::TColumn
& col
= impl_
->resp
.results
.columns
[i
];
75 return std::unique_ptr
<T
>(new T(helper::GetNulls(col
), helper::GetValues(col
)));
78 #define TYPED_GETTER(FUNC_NAME, TYPE) \
79 std::unique_ptr<TYPE> ColumnarRowSet::FUNC_NAME(int i) const { \
80 return GetCol<TYPE>(i); \
82 template std::unique_ptr<TYPE> ColumnarRowSet::GetCol<TYPE>(int i) const;
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
);
94 // BinaryColumn is an alias for StringColumn
95 std::unique_ptr
<BinaryColumn
> ColumnarRowSet::GetBinaryCol(int i
) const {
96 return GetCol
<BinaryColumn
>(i
);
99 } // namespace hiveserver2