/root/doris/be/src/olap/olap_tuple.h
Line | Count | Source (jump to first uncovered line) |
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 | | #pragma once |
19 | | |
20 | | #include <string> |
21 | | #include <vector> |
22 | | |
23 | | namespace doris { |
24 | | |
25 | | class OlapTuple { |
26 | | public: |
27 | 1 | OlapTuple() {} |
28 | | OlapTuple(const std::vector<std::string>& values) |
29 | 1 | : _values(values), _nulls(values.size(), false) {} |
30 | | |
31 | 0 | void add_null() { |
32 | 0 | _values.push_back(""); |
33 | 0 | _nulls.push_back(true); |
34 | 0 | } |
35 | | |
36 | 2 | void add_value(const std::string& value, bool is_null = false) { |
37 | 2 | _values.push_back(value); |
38 | 2 | _nulls.push_back(is_null); |
39 | 2 | } |
40 | | |
41 | 4 | size_t size() const { return _values.size(); } |
42 | | |
43 | 0 | void reserve(size_t size) { |
44 | 0 | _values.reserve(size); |
45 | 0 | _nulls.reserve(size); |
46 | 0 | } |
47 | | |
48 | 0 | void set_value(size_t i, const std::string& value, bool is_null = false) { |
49 | 0 | _values[i] = value; |
50 | 0 | _nulls[i] = is_null; |
51 | 0 | } |
52 | | |
53 | 2 | bool is_null(size_t i) const { return _nulls[i]; } |
54 | 4 | const std::string& get_value(size_t i) const { return _values[i]; } |
55 | 0 | const std::vector<std::string>& values() const { return _values; } |
56 | | |
57 | 0 | void reset() { |
58 | 0 | _values.clear(); |
59 | 0 | _nulls.clear(); |
60 | 0 | } |
61 | | |
62 | 0 | std::string operator[](size_t index) const { return _values[index]; } |
63 | | |
64 | | private: |
65 | | friend std::ostream& operator<<(std::ostream& os, const OlapTuple& tuple); |
66 | | |
67 | | std::vector<std::string> _values; |
68 | | std::vector<bool> _nulls; |
69 | | }; |
70 | | |
71 | 0 | inline std::ostream& operator<<(std::ostream& os, const OlapTuple& tuple) { |
72 | 0 | for (int i = 0; i < tuple._values.size(); ++i) { |
73 | 0 | if (i > 0) { |
74 | 0 | os << ","; |
75 | 0 | } |
76 | 0 | if (tuple._nulls[i]) { |
77 | 0 | os << "null("; |
78 | 0 | } |
79 | 0 | os << tuple._values[i]; |
80 | 0 | if (tuple._nulls[i]) { |
81 | 0 | os << ")"; |
82 | 0 | } |
83 | 0 | } |
84 | 0 | return os; |
85 | 0 | } |
86 | | |
87 | | } // namespace doris |