/Users/deen/code/yugabyte-db/src/yb/common/partial_row.cc
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 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #include "yb/common/partial_row.h" |
34 | | |
35 | | #include <algorithm> |
36 | | #include <string> |
37 | | |
38 | | #include "yb/common/common.pb.h" |
39 | | #include "yb/common/key_encoder.h" |
40 | | #include "yb/common/row.h" |
41 | | #include "yb/common/schema.h" |
42 | | #include "yb/gutil/strings/substitute.h" |
43 | | #include "yb/util/bitmap.h" |
44 | | #include "yb/util/decimal.h" |
45 | | #include "yb/util/result.h" |
46 | | #include "yb/util/status.h" |
47 | | #include "yb/util/status_log.h" |
48 | | |
49 | | using strings::Substitute; |
50 | | |
51 | | namespace yb { |
52 | | |
53 | | namespace { |
54 | | |
55 | 30 | inline Result<size_t> FindColumn(const Schema& schema, const Slice& col_name) { |
56 | 30 | GStringPiece sp(col_name.cdata(), col_name.size()); |
57 | 30 | auto result = schema.find_column(sp); |
58 | 30 | if (PREDICT_FALSE(result == Schema::kColumnNotFound)) { |
59 | 0 | return STATUS(NotFound, "No such column", col_name); |
60 | 0 | } |
61 | 30 | return result; |
62 | 30 | } |
63 | | |
64 | | } // anonymous namespace |
65 | | |
66 | | YBPartialRow::YBPartialRow(const Schema* schema) |
67 | 69 | : schema_(schema) { |
68 | 69 | DCHECK(schema_->initialized()); |
69 | 69 | size_t column_bitmap_size = BitmapSize(schema_->num_columns()); |
70 | 69 | size_t row_size = ContiguousRowHelper::row_size(*schema); |
71 | | |
72 | 69 | auto dst = new uint8_t[2 * column_bitmap_size + row_size]; |
73 | 69 | isset_bitmap_ = dst; |
74 | 69 | owned_strings_bitmap_ = isset_bitmap_ + column_bitmap_size; |
75 | | |
76 | 69 | memset(isset_bitmap_, 0, 2 * column_bitmap_size); |
77 | | |
78 | 69 | row_data_ = owned_strings_bitmap_ + column_bitmap_size; |
79 | 69 | #ifndef NDEBUG |
80 | 69 | OverwriteWithPattern(reinterpret_cast<char*>(row_data_), |
81 | 69 | row_size, "NEWNEWNEWNEWNEW"); |
82 | 69 | #endif |
83 | 69 | ContiguousRowHelper::InitNullsBitmap( |
84 | 69 | *schema_, row_data_, ContiguousRowHelper::null_bitmap_size(*schema_)); |
85 | 69 | } |
86 | | |
87 | 73 | YBPartialRow::~YBPartialRow() { |
88 | 73 | DeallocateOwnedStrings(); |
89 | | // Both the row data and bitmap came from the same allocation. |
90 | | // The bitmap is at the start of it. |
91 | 73 | delete [] isset_bitmap_; |
92 | 73 | } |
93 | | |
94 | | YBPartialRow::YBPartialRow(const YBPartialRow& other) |
95 | 4 | : schema_(other.schema_) { |
96 | 4 | size_t column_bitmap_size = BitmapSize(schema_->num_columns()); |
97 | 4 | size_t row_size = ContiguousRowHelper::row_size(*schema_); |
98 | | |
99 | 4 | size_t len = 2 * column_bitmap_size + row_size; |
100 | 4 | isset_bitmap_ = new uint8_t[len]; |
101 | 4 | owned_strings_bitmap_ = isset_bitmap_ + column_bitmap_size; |
102 | 4 | row_data_ = owned_strings_bitmap_ + column_bitmap_size; |
103 | | |
104 | | // Copy all bitmaps and row data. |
105 | 4 | memcpy(isset_bitmap_, other.isset_bitmap_, len); |
106 | | |
107 | | // Copy owned strings. |
108 | 20 | for (size_t col_idx = 0; col_idx < schema_->num_columns(); col_idx++16 ) { |
109 | 16 | if (BitmapTest(owned_strings_bitmap_, col_idx)) { |
110 | 1 | ContiguousRow row(schema_, row_data_); |
111 | 1 | Slice* slice = reinterpret_cast<Slice*>(row.mutable_cell_ptr(col_idx)); |
112 | 1 | auto data = new uint8_t[slice->size()]; |
113 | 1 | slice->relocate(data); |
114 | 1 | } |
115 | 16 | } |
116 | 4 | } |
117 | | |
118 | 3 | YBPartialRow& YBPartialRow::operator=(YBPartialRow other) { |
119 | 3 | std::swap(schema_, other.schema_); |
120 | 3 | std::swap(isset_bitmap_, other.isset_bitmap_); |
121 | 3 | std::swap(owned_strings_bitmap_, other.owned_strings_bitmap_); |
122 | 3 | std::swap(row_data_, other.row_data_); |
123 | 3 | return *this; |
124 | 3 | } |
125 | | |
126 | | template<typename T> |
127 | | Status YBPartialRow::Set(const Slice& col_name, |
128 | | const typename T::cpp_type& val, |
129 | 19 | bool owned) { |
130 | 19 | return Set<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val, owned); |
131 | 19 | } Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)1> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)1>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)2> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)2>::cpp_type const&, bool) yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)3> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)3>::cpp_type const&, bool) Line | Count | Source | 129 | 2 | bool owned) { | 130 | 2 | return Set<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val, owned); | 131 | 2 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)4> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)4>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)10> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)10>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)7> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)7>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)8> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)8>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)6> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)6>::cpp_type const&, bool) yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)5> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)5>::cpp_type const&, bool) Line | Count | Source | 129 | 15 | bool owned) { | 130 | 15 | return Set<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val, owned); | 131 | 15 | } |
yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)9> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)9>::cpp_type const&, bool) Line | Count | Source | 129 | 2 | bool owned) { | 130 | 2 | return Set<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val, owned); | 131 | 2 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)22> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)22>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)17> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)17>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)18> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)18>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)11> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)11>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)13> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)13>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)25> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)25>::cpp_type const&, bool) |
132 | | |
133 | | template<typename T> |
134 | | Status YBPartialRow::Set(size_t col_idx, |
135 | | const typename T::cpp_type& val, |
136 | 25 | bool owned) { |
137 | 25 | const ColumnSchema& col = schema_->column(col_idx); |
138 | 25 | if (PREDICT_FALSE(col.type_info()->type != T::type)) { |
139 | | // TODO: at some point we could allow type coercion here. |
140 | 3 | return STATUS(InvalidArgument, |
141 | 3 | Substitute("invalid type $0 provided for column '$1' (expected $2)", |
142 | 3 | T::name(), |
143 | 3 | col.name(), col.type_info()->name)); |
144 | 3 | } |
145 | | |
146 | 22 | ContiguousRow row(schema_, row_data_); |
147 | | |
148 | | // If we're replacing an existing STRING/BINARY/INET value, deallocate the old value. |
149 | 22 | if (col.type_info()->var_length()) { |
150 | 17 | DeallocateStringIfSet(col_idx, col); |
151 | 17 | } |
152 | | |
153 | | // Mark the column as set. |
154 | 22 | BitmapSet(isset_bitmap_, col_idx); |
155 | | |
156 | 22 | if (col.is_nullable()) { |
157 | 6 | row.set_null(col_idx, false); |
158 | 6 | } |
159 | | |
160 | 22 | ContiguousRowCell<ContiguousRow> dst(&row, col_idx); |
161 | 22 | memcpy(dst.mutable_ptr(), &val, sizeof(val)); |
162 | 22 | if (owned) { |
163 | 15 | BitmapSet(owned_strings_bitmap_, col_idx); |
164 | 15 | } |
165 | 22 | return Status::OK(); |
166 | 25 | } Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)1> >(unsigned long, yb::TypeTraits<(yb::DataType)1>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)2> >(unsigned long, yb::TypeTraits<(yb::DataType)2>::cpp_type const&, bool) yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)3> >(unsigned long, yb::TypeTraits<(yb::DataType)3>::cpp_type const&, bool) Line | Count | Source | 136 | 5 | bool owned) { | 137 | 5 | const ColumnSchema& col = schema_->column(col_idx); | 138 | 5 | if (PREDICT_FALSE(col.type_info()->type != T::type)) { | 139 | | // TODO: at some point we could allow type coercion here. | 140 | 0 | return STATUS(InvalidArgument, | 141 | 0 | Substitute("invalid type $0 provided for column '$1' (expected $2)", | 142 | 0 | T::name(), | 143 | 0 | col.name(), col.type_info()->name)); | 144 | 0 | } | 145 | | | 146 | 5 | ContiguousRow row(schema_, row_data_); | 147 | | | 148 | | // If we're replacing an existing STRING/BINARY/INET value, deallocate the old value. | 149 | 5 | if (col.type_info()->var_length()) { | 150 | 0 | DeallocateStringIfSet(col_idx, col); | 151 | 0 | } | 152 | | | 153 | | // Mark the column as set. | 154 | 5 | BitmapSet(isset_bitmap_, col_idx); | 155 | | | 156 | 5 | if (col.is_nullable()) { | 157 | 0 | row.set_null(col_idx, false); | 158 | 0 | } | 159 | | | 160 | 5 | ContiguousRowCell<ContiguousRow> dst(&row, col_idx); | 161 | 5 | memcpy(dst.mutable_ptr(), &val, sizeof(val)); | 162 | 5 | if (owned) { | 163 | 0 | BitmapSet(owned_strings_bitmap_, col_idx); | 164 | 0 | } | 165 | 5 | return Status::OK(); | 166 | 5 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)4> >(unsigned long, yb::TypeTraits<(yb::DataType)4>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)10> >(unsigned long, yb::TypeTraits<(yb::DataType)10>::cpp_type const&, bool) yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)5> >(unsigned long, yb::TypeTraits<(yb::DataType)5>::cpp_type const&, bool) Line | Count | Source | 136 | 17 | bool owned) { | 137 | 17 | const ColumnSchema& col = schema_->column(col_idx); | 138 | 17 | if (PREDICT_FALSE(col.type_info()->type != T::type)) { | 139 | | // TODO: at some point we could allow type coercion here. | 140 | 2 | return STATUS(InvalidArgument, | 141 | 2 | Substitute("invalid type $0 provided for column '$1' (expected $2)", | 142 | 2 | T::name(), | 143 | 2 | col.name(), col.type_info()->name)); | 144 | 2 | } | 145 | | | 146 | 15 | ContiguousRow row(schema_, row_data_); | 147 | | | 148 | | // If we're replacing an existing STRING/BINARY/INET value, deallocate the old value. | 149 | 15 | if (col.type_info()->var_length()) { | 150 | 15 | DeallocateStringIfSet(col_idx, col); | 151 | 15 | } | 152 | | | 153 | | // Mark the column as set. | 154 | 15 | BitmapSet(isset_bitmap_, col_idx); | 155 | | | 156 | 15 | if (col.is_nullable()) { | 157 | 4 | row.set_null(col_idx, false); | 158 | 4 | } | 159 | | | 160 | 15 | ContiguousRowCell<ContiguousRow> dst(&row, col_idx); | 161 | 15 | memcpy(dst.mutable_ptr(), &val, sizeof(val)); | 162 | 15 | if (owned) { | 163 | 14 | BitmapSet(owned_strings_bitmap_, col_idx); | 164 | 14 | } | 165 | 15 | return Status::OK(); | 166 | 17 | } |
yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)9> >(unsigned long, yb::TypeTraits<(yb::DataType)9>::cpp_type const&, bool) Line | Count | Source | 136 | 3 | bool owned) { | 137 | 3 | const ColumnSchema& col = schema_->column(col_idx); | 138 | 3 | if (PREDICT_FALSE(col.type_info()->type != T::type)) { | 139 | | // TODO: at some point we could allow type coercion here. | 140 | 1 | return STATUS(InvalidArgument, | 141 | 1 | Substitute("invalid type $0 provided for column '$1' (expected $2)", | 142 | 1 | T::name(), | 143 | 1 | col.name(), col.type_info()->name)); | 144 | 1 | } | 145 | | | 146 | 2 | ContiguousRow row(schema_, row_data_); | 147 | | | 148 | | // If we're replacing an existing STRING/BINARY/INET value, deallocate the old value. | 149 | 2 | if (col.type_info()->var_length()) { | 150 | 2 | DeallocateStringIfSet(col_idx, col); | 151 | 2 | } | 152 | | | 153 | | // Mark the column as set. | 154 | 2 | BitmapSet(isset_bitmap_, col_idx); | 155 | | | 156 | 2 | if (col.is_nullable()) { | 157 | 2 | row.set_null(col_idx, false); | 158 | 2 | } | 159 | | | 160 | 2 | ContiguousRowCell<ContiguousRow> dst(&row, col_idx); | 161 | 2 | memcpy(dst.mutable_ptr(), &val, sizeof(val)); | 162 | 2 | if (owned) { | 163 | 1 | BitmapSet(owned_strings_bitmap_, col_idx); | 164 | 1 | } | 165 | 2 | return Status::OK(); | 166 | 3 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)7> >(unsigned long, yb::TypeTraits<(yb::DataType)7>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)8> >(unsigned long, yb::TypeTraits<(yb::DataType)8>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)6> >(unsigned long, yb::TypeTraits<(yb::DataType)6>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)22> >(unsigned long, yb::TypeTraits<(yb::DataType)22>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)17> >(unsigned long, yb::TypeTraits<(yb::DataType)17>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)18> >(unsigned long, yb::TypeTraits<(yb::DataType)18>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)11> >(unsigned long, yb::TypeTraits<(yb::DataType)11>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)13> >(unsigned long, yb::TypeTraits<(yb::DataType)13>::cpp_type const&, bool) Unexecuted instantiation: yb::Status yb::YBPartialRow::Set<yb::TypeTraits<(yb::DataType)25> >(unsigned long, yb::TypeTraits<(yb::DataType)25>::cpp_type const&, bool) |
167 | | |
168 | 0 | Status YBPartialRow::Set(size_t column_idx, const uint8_t* val) { |
169 | 0 | const ColumnSchema& column_schema = schema()->column(column_idx); |
170 | |
|
171 | 0 | switch (column_schema.type_info()->type) { |
172 | 0 | case BOOL: { |
173 | 0 | RETURN_NOT_OK(SetBool(column_idx, *reinterpret_cast<const bool*>(val))); |
174 | 0 | break; |
175 | 0 | }; |
176 | 0 | case INT8: { |
177 | 0 | RETURN_NOT_OK(SetInt8(column_idx, *reinterpret_cast<const int8_t*>(val))); |
178 | 0 | break; |
179 | 0 | }; |
180 | 0 | case INT16: { |
181 | 0 | RETURN_NOT_OK(SetInt16(column_idx, *reinterpret_cast<const int16_t*>(val))); |
182 | 0 | break; |
183 | 0 | }; |
184 | 0 | case INT32: { |
185 | 0 | RETURN_NOT_OK(SetInt32(column_idx, *reinterpret_cast<const int32_t*>(val))); |
186 | 0 | break; |
187 | 0 | }; |
188 | 0 | case INT64: { |
189 | 0 | RETURN_NOT_OK(SetInt64(column_idx, *reinterpret_cast<const int64_t*>(val))); |
190 | 0 | break; |
191 | 0 | }; |
192 | 0 | case FLOAT: { |
193 | 0 | RETURN_NOT_OK(SetFloat(column_idx, *reinterpret_cast<const float*>(val))); |
194 | 0 | break; |
195 | 0 | }; |
196 | 0 | case DOUBLE: { |
197 | 0 | RETURN_NOT_OK(SetDouble(column_idx, *reinterpret_cast<const double*>(val))); |
198 | 0 | break; |
199 | 0 | }; |
200 | 0 | case STRING: { |
201 | 0 | RETURN_NOT_OK(SetStringCopy(column_idx, *reinterpret_cast<const Slice*>(val))); |
202 | 0 | break; |
203 | 0 | }; |
204 | 0 | case BINARY: { |
205 | 0 | RETURN_NOT_OK(SetBinaryCopy(column_idx, *reinterpret_cast<const Slice*>(val))); |
206 | 0 | break; |
207 | 0 | }; |
208 | 0 | case TIMESTAMP: { |
209 | 0 | RETURN_NOT_OK(SetTimestamp(column_idx, *reinterpret_cast<const int64_t*>(val))); |
210 | 0 | break; |
211 | 0 | }; |
212 | 0 | case INET: { |
213 | 0 | RETURN_NOT_OK(SetInet(column_idx, *reinterpret_cast<const Slice*>(val))); |
214 | 0 | break; |
215 | 0 | }; |
216 | 0 | case JSONB: { |
217 | 0 | RETURN_NOT_OK(SetJsonb(column_idx, *reinterpret_cast<const Slice*>(val))); |
218 | 0 | break; |
219 | 0 | }; |
220 | 0 | case UUID: { |
221 | 0 | RETURN_NOT_OK(SetUuidCopy(column_idx, *reinterpret_cast<const Slice*>(val))); |
222 | 0 | break; |
223 | 0 | }; |
224 | 0 | case TIMEUUID: { |
225 | 0 | RETURN_NOT_OK(SetTimeUuidCopy(column_idx, *reinterpret_cast<const Slice*>(val))); |
226 | 0 | break; |
227 | 0 | } |
228 | 0 | case FROZEN: { |
229 | 0 | RETURN_NOT_OK(SetFrozenCopy(column_idx, *reinterpret_cast<const Slice*>(val))); |
230 | 0 | break; |
231 | 0 | }; |
232 | 0 | case DECIMAL: FALLTHROUGH_INTENDED; |
233 | 0 | default: { |
234 | 0 | return STATUS(InvalidArgument, "Unknown column type in schema", |
235 | 0 | column_schema.ToString()); |
236 | 0 | }; |
237 | 0 | } |
238 | 0 | return Status::OK(); |
239 | 0 | } |
240 | | |
241 | 858 | void YBPartialRow::DeallocateStringIfSet(size_t col_idx, const ColumnSchema& col) { |
242 | 858 | if (BitmapTest(owned_strings_bitmap_, col_idx)) { |
243 | 16 | ContiguousRow row(schema_, row_data_); |
244 | 16 | CHECK(col.type_info()->var_length()); |
245 | 16 | auto dst = row.CellSlice(col_idx); |
246 | 16 | delete [] dst.data(); |
247 | 16 | BitmapClear(owned_strings_bitmap_, col_idx); |
248 | 16 | } |
249 | 858 | } |
250 | | |
251 | 73 | void YBPartialRow::DeallocateOwnedStrings() { |
252 | 910 | for (size_t i = 0; i < schema_->num_columns(); i++837 ) { |
253 | 837 | DeallocateStringIfSet(i, schema_->column(i)); |
254 | 837 | } |
255 | 73 | } |
256 | | |
257 | | //------------------------------------------------------------ |
258 | | // Setters |
259 | | //------------------------------------------------------------ |
260 | | |
261 | 0 | Status YBPartialRow::SetBool(const Slice& col_name, bool val) { |
262 | 0 | return Set<TypeTraits<BOOL> >(col_name, val); |
263 | 0 | } |
264 | 0 | Status YBPartialRow::SetInt8(const Slice& col_name, int8_t val) { |
265 | 0 | return Set<TypeTraits<INT8> >(col_name, val); |
266 | 0 | } |
267 | 0 | Status YBPartialRow::SetInt16(const Slice& col_name, int16_t val) { |
268 | 0 | return Set<TypeTraits<INT16> >(col_name, val); |
269 | 0 | } |
270 | 2 | Status YBPartialRow::SetInt32(const Slice& col_name, int32_t val) { |
271 | 2 | return Set<TypeTraits<INT32> >(col_name, val); |
272 | 2 | } |
273 | 0 | Status YBPartialRow::SetInt64(const Slice& col_name, int64_t val) { |
274 | 0 | return Set<TypeTraits<INT64> >(col_name, val); |
275 | 0 | } |
276 | 0 | Status YBPartialRow::SetTimestamp(const Slice& col_name, int64_t val) { |
277 | 0 | return Set<TypeTraits<TIMESTAMP> >(col_name, val); |
278 | 0 | } |
279 | 0 | Status YBPartialRow::SetFloat(const Slice& col_name, float val) { |
280 | 0 | return Set<TypeTraits<FLOAT> >(col_name, val); |
281 | 0 | } |
282 | 0 | Status YBPartialRow::SetDouble(const Slice& col_name, double val) { |
283 | 0 | return Set<TypeTraits<DOUBLE> >(col_name, val); |
284 | 0 | } |
285 | 0 | Status YBPartialRow::SetString(const Slice& col_name, const Slice& val) { |
286 | 0 | return Set<TypeTraits<STRING> >(col_name, val, false); |
287 | 0 | } |
288 | 0 | Status YBPartialRow::SetBinary(const Slice& col_name, const Slice& val) { |
289 | 0 | return Set<TypeTraits<BINARY> >(col_name, val, false); |
290 | 0 | } |
291 | 0 | Status YBPartialRow::SetFrozen(const Slice& col_name, const Slice& val) { |
292 | 0 | return Set<TypeTraits<FROZEN> >(col_name, val, false); |
293 | 0 | } |
294 | 0 | Status YBPartialRow::SetInet(const Slice& col_name, const Slice& val) { |
295 | 0 | return SetSliceCopy<TypeTraits<INET> >(col_name, val); |
296 | 0 | } |
297 | 0 | Status YBPartialRow::SetUuid(const Slice& col_name, const Slice& val) { |
298 | 0 | return Set<TypeTraits<UUID> >(col_name, val, false); |
299 | 0 | } |
300 | 0 | Status YBPartialRow::SetTimeUuid(const Slice& col_name, const Slice& val) { |
301 | 0 | return Set<TypeTraits<TIMEUUID> >(col_name, val, false); |
302 | 0 | } |
303 | 0 | Status YBPartialRow::SetDecimal(const Slice& col_name, const Slice& val) { |
304 | 0 | return Set<TypeTraits<DECIMAL> >(col_name, val, false); |
305 | 0 | } |
306 | 0 | Status YBPartialRow::SetBool(size_t col_idx, bool val) { |
307 | 0 | return Set<TypeTraits<BOOL> >(col_idx, val); |
308 | 0 | } |
309 | 0 | Status YBPartialRow::SetInt8(size_t col_idx, int8_t val) { |
310 | 0 | return Set<TypeTraits<INT8> >(col_idx, val); |
311 | 0 | } |
312 | 0 | Status YBPartialRow::SetInt16(size_t col_idx, int16_t val) { |
313 | 0 | return Set<TypeTraits<INT16> >(col_idx, val); |
314 | 0 | } |
315 | 3 | Status YBPartialRow::SetInt32(size_t col_idx, int32_t val) { |
316 | 3 | return Set<TypeTraits<INT32> >(col_idx, val); |
317 | 3 | } |
318 | 0 | Status YBPartialRow::SetInt64(size_t col_idx, int64_t val) { |
319 | 0 | return Set<TypeTraits<INT64> >(col_idx, val); |
320 | 0 | } |
321 | 0 | Status YBPartialRow::SetTimestamp(size_t col_idx, int64_t val) { |
322 | 0 | return Set<TypeTraits<TIMESTAMP> >(col_idx, val); |
323 | 0 | } |
324 | 1 | Status YBPartialRow::SetString(size_t col_idx, const Slice& val) { |
325 | 1 | return Set<TypeTraits<STRING> >(col_idx, val, false); |
326 | 1 | } |
327 | 1 | Status YBPartialRow::SetBinary(size_t col_idx, const Slice& val) { |
328 | 1 | return Set<TypeTraits<BINARY> >(col_idx, val, false); |
329 | 1 | } |
330 | 0 | Status YBPartialRow::SetFrozen(size_t col_idx, const Slice& val) { |
331 | 0 | return Set<TypeTraits<FROZEN> >(col_idx, val, false); |
332 | 0 | } |
333 | 0 | Status YBPartialRow::SetInet(size_t col_idx, const Slice& val) { |
334 | 0 | return SetSliceCopy<TypeTraits<INET> >(col_idx, val); |
335 | 0 | } |
336 | 0 | Status YBPartialRow::SetJsonb(size_t col_idx, const Slice& val) { |
337 | 0 | return SetSliceCopy<TypeTraits<JSONB> >(col_idx, val); |
338 | 0 | } |
339 | 0 | Status YBPartialRow::SetUuid(size_t col_idx, const Slice& val) { |
340 | 0 | return Set<TypeTraits<UUID> >(col_idx, val, false); |
341 | 0 | } |
342 | 0 | Status YBPartialRow::SetTimeUuid(size_t col_idx, const Slice& val) { |
343 | 0 | return Set<TypeTraits<TIMEUUID> >(col_idx, val, false); |
344 | 0 | } |
345 | 0 | Status YBPartialRow::SetDecimal(size_t col_idx, const Slice& val) { |
346 | 0 | return Set<TypeTraits<DECIMAL> >(col_idx, val, false); |
347 | 0 | } |
348 | 0 | Status YBPartialRow::SetFloat(size_t col_idx, float val) { |
349 | 0 | return Set<TypeTraits<FLOAT> >(col_idx, util::CanonicalizeFloat(val)); |
350 | 0 | } |
351 | 0 | Status YBPartialRow::SetDouble(size_t col_idx, double val) { |
352 | 0 | return Set<TypeTraits<DOUBLE> >(col_idx, util::CanonicalizeDouble(val)); |
353 | 0 | } |
354 | | |
355 | 2 | Status YBPartialRow::SetBinaryCopy(const Slice& col_name, const Slice& val) { |
356 | 2 | return SetSliceCopy<TypeTraits<BINARY> >(col_name, val); |
357 | 2 | } |
358 | 0 | Status YBPartialRow::SetBinaryCopy(size_t col_idx, const Slice& val) { |
359 | 0 | return SetSliceCopy<TypeTraits<BINARY> >(col_idx, val); |
360 | 0 | } |
361 | 15 | Status YBPartialRow::SetStringCopy(const Slice& col_name, const Slice& val) { |
362 | 15 | return SetSliceCopy<TypeTraits<STRING> >(col_name, val); |
363 | 15 | } |
364 | 1 | Status YBPartialRow::SetStringCopy(size_t col_idx, const Slice& val) { |
365 | 1 | return SetSliceCopy<TypeTraits<STRING> >(col_idx, val); |
366 | 1 | } |
367 | 0 | Status YBPartialRow::SetUuidCopy(const Slice& col_name, const Slice& val) { |
368 | 0 | return SetSliceCopy<TypeTraits<UUID> >(col_name, val); |
369 | 0 | } |
370 | 0 | Status YBPartialRow::SetUuidCopy(size_t col_idx, const Slice& val) { |
371 | 0 | return SetSliceCopy<TypeTraits<UUID> >(col_idx, val); |
372 | 0 | } |
373 | 0 | Status YBPartialRow::SetTimeUuidCopy(const Slice& col_name, const Slice& val) { |
374 | 0 | return SetSliceCopy<TypeTraits<TIMEUUID> >(col_name, val); |
375 | 0 | } |
376 | 0 | Status YBPartialRow::SetTimeUuidCopy(size_t col_idx, const Slice& val) { |
377 | 0 | return SetSliceCopy<TypeTraits<TIMEUUID> >(col_idx, val); |
378 | 0 | } |
379 | 0 | Status YBPartialRow::SetFrozenCopy(const Slice& col_name, const Slice& val) { |
380 | 0 | return SetSliceCopy<TypeTraits<FROZEN> >(col_name, val); |
381 | 0 | } |
382 | 0 | Status YBPartialRow::SetFrozenCopy(size_t col_idx, const Slice& val) { |
383 | 0 | return SetSliceCopy<TypeTraits<FROZEN> >(col_idx, val); |
384 | 0 | } |
385 | | |
386 | | template<typename T> |
387 | 17 | Status YBPartialRow::SetSliceCopy(const Slice& col_name, const Slice& val) { |
388 | 17 | auto relocated = new uint8_t[val.size()]; |
389 | 17 | memcpy(relocated, val.data(), val.size()); |
390 | 17 | Slice relocated_val(relocated, val.size()); |
391 | 17 | Status s = Set<T>(col_name, relocated_val, true); |
392 | 17 | if (!s.ok()) { |
393 | 3 | delete [] relocated; |
394 | 3 | } |
395 | 17 | return s; |
396 | 17 | } yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)5> >(yb::Slice const&, yb::Slice const&) Line | Count | Source | 387 | 15 | Status YBPartialRow::SetSliceCopy(const Slice& col_name, const Slice& val) { | 388 | 15 | auto relocated = new uint8_t[val.size()]; | 389 | 15 | memcpy(relocated, val.data(), val.size()); | 390 | 15 | Slice relocated_val(relocated, val.size()); | 391 | 15 | Status s = Set<T>(col_name, relocated_val, true); | 392 | 15 | if (!s.ok()) { | 393 | 2 | delete [] relocated; | 394 | 2 | } | 395 | 15 | return s; | 396 | 15 | } |
yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)9> >(yb::Slice const&, yb::Slice const&) Line | Count | Source | 387 | 2 | Status YBPartialRow::SetSliceCopy(const Slice& col_name, const Slice& val) { | 388 | 2 | auto relocated = new uint8_t[val.size()]; | 389 | 2 | memcpy(relocated, val.data(), val.size()); | 390 | 2 | Slice relocated_val(relocated, val.size()); | 391 | 2 | Status s = Set<T>(col_name, relocated_val, true); | 392 | 2 | if (!s.ok()) { | 393 | 1 | delete [] relocated; | 394 | 1 | } | 395 | 2 | return s; | 396 | 2 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)13> >(yb::Slice const&, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)25> >(yb::Slice const&, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)17> >(yb::Slice const&, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)18> >(yb::Slice const&, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)22> >(yb::Slice const&, yb::Slice const&) |
397 | | |
398 | | template<typename T> |
399 | 1 | Status YBPartialRow::SetSliceCopy(size_t col_idx, const Slice& val) { |
400 | 1 | auto relocated = new uint8_t[val.size()]; |
401 | 1 | memcpy(relocated, val.data(), val.size()); |
402 | 1 | Slice relocated_val(relocated, val.size()); |
403 | 1 | Status s = Set<T>(col_idx, relocated_val, true); |
404 | 1 | if (!s.ok()) { |
405 | 0 | delete [] relocated; |
406 | 0 | } |
407 | 1 | return s; |
408 | 1 | } yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)5> >(unsigned long, yb::Slice const&) Line | Count | Source | 399 | 1 | Status YBPartialRow::SetSliceCopy(size_t col_idx, const Slice& val) { | 400 | 1 | auto relocated = new uint8_t[val.size()]; | 401 | 1 | memcpy(relocated, val.data(), val.size()); | 402 | 1 | Slice relocated_val(relocated, val.size()); | 403 | 1 | Status s = Set<T>(col_idx, relocated_val, true); | 404 | 1 | if (!s.ok()) { | 405 | 0 | delete [] relocated; | 406 | 0 | } | 407 | 1 | return s; | 408 | 1 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)9> >(unsigned long, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)13> >(unsigned long, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)25> >(unsigned long, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)17> >(unsigned long, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)18> >(unsigned long, yb::Slice const&) Unexecuted instantiation: yb::Status yb::YBPartialRow::SetSliceCopy<yb::TypeTraits<(yb::DataType)22> >(unsigned long, yb::Slice const&) |
409 | | |
410 | 2 | Status YBPartialRow::SetNull(const Slice& col_name) { |
411 | 2 | return SetNull(VERIFY_RESULT(FindColumn(*schema_, col_name))); |
412 | 2 | } |
413 | | |
414 | 3 | Status YBPartialRow::SetNull(size_t col_idx) { |
415 | 3 | const ColumnSchema& col = schema_->column(col_idx); |
416 | 3 | if (PREDICT_FALSE(!col.is_nullable())) { |
417 | 1 | return STATUS(InvalidArgument, "column not nullable", col.ToString()); |
418 | 1 | } |
419 | | |
420 | 2 | if (col.type_info()->physical_type == BINARY) DeallocateStringIfSet(col_idx, col); |
421 | | |
422 | 2 | ContiguousRow row(schema_, row_data_); |
423 | 2 | row.set_null(col_idx, true); |
424 | | |
425 | | // Mark the column as set. |
426 | 2 | BitmapSet(isset_bitmap_, col_idx); |
427 | 2 | return Status::OK(); |
428 | 3 | } |
429 | | |
430 | 3 | Status YBPartialRow::Unset(const Slice& col_name) { |
431 | 3 | return Unset(VERIFY_RESULT(FindColumn(*schema_, col_name))); |
432 | 3 | } |
433 | | |
434 | 3 | Status YBPartialRow::Unset(size_t col_idx) { |
435 | 3 | const ColumnSchema& col = schema_->column(col_idx); |
436 | 3 | if (col.type_info()->physical_type == BINARY) DeallocateStringIfSet(col_idx, col)2 ; |
437 | 3 | BitmapClear(isset_bitmap_, col_idx); |
438 | 3 | return Status::OK(); |
439 | 3 | } |
440 | | |
441 | | //------------------------------------------------------------ |
442 | | // Template instantiations: We instantiate all possible templates to avoid linker issues. |
443 | | // see: https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl |
444 | | // TODO We can probably remove this when we move to c++11 and can use "extern template" |
445 | | //------------------------------------------------------------ |
446 | | |
447 | | template |
448 | | Status YBPartialRow::SetSliceCopy<TypeTraits<STRING> >(size_t col_idx, const Slice& val); |
449 | | |
450 | | template |
451 | | Status YBPartialRow::SetSliceCopy<TypeTraits<BINARY> >(size_t col_idx, const Slice& val); |
452 | | |
453 | | template |
454 | | Status YBPartialRow::SetSliceCopy<TypeTraits<INET> >(size_t col_idx, const Slice& val); |
455 | | |
456 | | template |
457 | | Status YBPartialRow::SetSliceCopy<TypeTraits<JSONB> >(size_t col_idx, const Slice& val); |
458 | | |
459 | | template |
460 | | Status YBPartialRow::SetSliceCopy<TypeTraits<UUID> >(size_t col_idx, const Slice& val); |
461 | | |
462 | | template |
463 | | Status YBPartialRow::SetSliceCopy<TypeTraits<TIMEUUID> >(size_t col_idx, const Slice& val); |
464 | | |
465 | | template |
466 | | Status YBPartialRow::SetSliceCopy<TypeTraits<STRING> >(const Slice& col_name, const Slice& val); |
467 | | |
468 | | template |
469 | | Status YBPartialRow::SetSliceCopy<TypeTraits<BINARY> >(const Slice& col_name, const Slice& val); |
470 | | |
471 | | template |
472 | | Status YBPartialRow::SetSliceCopy<TypeTraits<INET> >(const Slice& col_name, const Slice& val); |
473 | | |
474 | | template |
475 | | Status YBPartialRow::SetSliceCopy<TypeTraits<JSONB> >(const Slice& col_name, const Slice& val); |
476 | | |
477 | | template |
478 | | Status YBPartialRow::SetSliceCopy<TypeTraits<UUID> >(const Slice& col_name, const Slice& val); |
479 | | |
480 | | template |
481 | | Status YBPartialRow::SetSliceCopy<TypeTraits<TIMEUUID> >(const Slice& col_name, const Slice& val); |
482 | | |
483 | | template |
484 | | Status YBPartialRow::Set<TypeTraits<INT8> >(size_t col_idx, |
485 | | const TypeTraits<INT8>::cpp_type& val, |
486 | | bool owned); |
487 | | |
488 | | template |
489 | | Status YBPartialRow::Set<TypeTraits<INT16> >(size_t col_idx, |
490 | | const TypeTraits<INT16>::cpp_type& val, |
491 | | bool owned); |
492 | | |
493 | | template |
494 | | Status YBPartialRow::Set<TypeTraits<INT32> >(size_t col_idx, |
495 | | const TypeTraits<INT32>::cpp_type& val, |
496 | | bool owned); |
497 | | |
498 | | template |
499 | | Status YBPartialRow::Set<TypeTraits<INT64> >(size_t col_idx, |
500 | | const TypeTraits<INT64>::cpp_type& val, |
501 | | bool owned); |
502 | | |
503 | | template |
504 | | Status YBPartialRow::Set<TypeTraits<TIMESTAMP> >( |
505 | | size_t col_idx, |
506 | | const TypeTraits<TIMESTAMP>::cpp_type& val, |
507 | | bool owned); |
508 | | |
509 | | template |
510 | | Status YBPartialRow::Set<TypeTraits<STRING> >(size_t col_idx, |
511 | | const TypeTraits<STRING>::cpp_type& val, |
512 | | bool owned); |
513 | | |
514 | | template |
515 | | Status YBPartialRow::Set<TypeTraits<BINARY> >(size_t col_idx, |
516 | | const TypeTraits<BINARY>::cpp_type& val, |
517 | | bool owned); |
518 | | |
519 | | template |
520 | | Status YBPartialRow::Set<TypeTraits<FLOAT> >(size_t col_idx, |
521 | | const TypeTraits<FLOAT>::cpp_type& val, |
522 | | bool owned); |
523 | | |
524 | | template |
525 | | Status YBPartialRow::Set<TypeTraits<DOUBLE> >(size_t col_idx, |
526 | | const TypeTraits<DOUBLE>::cpp_type& val, |
527 | | bool owned); |
528 | | |
529 | | template |
530 | | Status YBPartialRow::Set<TypeTraits<BOOL> >(size_t col_idx, |
531 | | const TypeTraits<BOOL>::cpp_type& val, |
532 | | bool owned); |
533 | | |
534 | | template |
535 | | Status YBPartialRow::Set<TypeTraits<INT8> >(const Slice& col_name, |
536 | | const TypeTraits<INT8>::cpp_type& val, |
537 | | bool owned); |
538 | | |
539 | | template |
540 | | Status YBPartialRow::Set<TypeTraits<INT16> >(const Slice& col_name, |
541 | | const TypeTraits<INT16>::cpp_type& val, |
542 | | bool owned); |
543 | | |
544 | | template |
545 | | Status YBPartialRow::Set<TypeTraits<INT32> >(const Slice& col_name, |
546 | | const TypeTraits<INT32>::cpp_type& val, |
547 | | bool owned); |
548 | | |
549 | | template |
550 | | Status YBPartialRow::Set<TypeTraits<INT64> >(const Slice& col_name, |
551 | | const TypeTraits<INT64>::cpp_type& val, |
552 | | bool owned); |
553 | | |
554 | | template |
555 | | Status YBPartialRow::Set<TypeTraits<TIMESTAMP> >( |
556 | | const Slice& col_name, |
557 | | const TypeTraits<TIMESTAMP>::cpp_type& val, |
558 | | bool owned); |
559 | | |
560 | | template |
561 | | Status YBPartialRow::Set<TypeTraits<FLOAT> >(const Slice& col_name, |
562 | | const TypeTraits<FLOAT>::cpp_type& val, |
563 | | bool owned); |
564 | | |
565 | | template |
566 | | Status YBPartialRow::Set<TypeTraits<DOUBLE> >(const Slice& col_name, |
567 | | const TypeTraits<DOUBLE>::cpp_type& val, |
568 | | bool owned); |
569 | | |
570 | | template |
571 | | Status YBPartialRow::Set<TypeTraits<BOOL> >(const Slice& col_name, |
572 | | const TypeTraits<BOOL>::cpp_type& val, |
573 | | bool owned); |
574 | | |
575 | | template |
576 | | Status YBPartialRow::Set<TypeTraits<STRING> >(const Slice& col_name, |
577 | | const TypeTraits<STRING>::cpp_type& val, |
578 | | bool owned); |
579 | | |
580 | | template |
581 | | Status YBPartialRow::Set<TypeTraits<BINARY> >(const Slice& col_name, |
582 | | const TypeTraits<BINARY>::cpp_type& val, |
583 | | bool owned); |
584 | | |
585 | | //------------------------------------------------------------ |
586 | | // Getters |
587 | | //------------------------------------------------------------ |
588 | 132 | bool YBPartialRow::IsColumnSet(size_t col_idx) const { |
589 | 132 | DCHECK_GE(col_idx, 0); |
590 | 132 | DCHECK_LT(col_idx, schema_->num_columns()); |
591 | 132 | return BitmapTest(isset_bitmap_, col_idx); |
592 | 132 | } |
593 | | |
594 | 0 | bool YBPartialRow::IsColumnSet(const Slice& col_name) const { |
595 | 0 | return IsColumnSet(CHECK_RESULT(FindColumn(*schema_, col_name))); |
596 | 0 | } |
597 | | |
598 | 10 | bool YBPartialRow::IsNull(size_t col_idx) const { |
599 | 10 | const ColumnSchema& col = schema_->column(col_idx); |
600 | 10 | if (!col.is_nullable()) { |
601 | 2 | return false; |
602 | 2 | } |
603 | | |
604 | 8 | if (!IsColumnSet(col_idx)) return false0 ; |
605 | | |
606 | 8 | ContiguousRow row(schema_, row_data_); |
607 | 8 | return row.is_null(col_idx); |
608 | 8 | } |
609 | | |
610 | 3 | bool YBPartialRow::IsNull(const Slice& col_name) const { |
611 | 3 | return IsNull(CHECK_RESULT(FindColumn(*schema_, col_name))); |
612 | 3 | } |
613 | | |
614 | 0 | Status YBPartialRow::GetBool(const Slice& col_name, bool* val) const { |
615 | 0 | return Get<TypeTraits<BOOL> >(col_name, val); |
616 | 0 | } |
617 | 0 | Status YBPartialRow::GetInt8(const Slice& col_name, int8_t* val) const { |
618 | 0 | return Get<TypeTraits<INT8> >(col_name, val); |
619 | 0 | } |
620 | 0 | Status YBPartialRow::GetInt16(const Slice& col_name, int16_t* val) const { |
621 | 0 | return Get<TypeTraits<INT16> >(col_name, val); |
622 | 0 | } |
623 | 1 | Status YBPartialRow::GetInt32(const Slice& col_name, int32_t* val) const { |
624 | 1 | return Get<TypeTraits<INT32> >(col_name, val); |
625 | 1 | } |
626 | 0 | Status YBPartialRow::GetInt64(const Slice& col_name, int64_t* val) const { |
627 | 0 | return Get<TypeTraits<INT64> >(col_name, val); |
628 | 0 | } |
629 | 0 | Status YBPartialRow::GetTimestamp(const Slice& col_name, int64_t* micros_since_utc_epoch) const { |
630 | 0 | return Get<TypeTraits<TIMESTAMP> >(col_name, micros_since_utc_epoch); |
631 | 0 | } |
632 | 0 | Status YBPartialRow::GetFloat(const Slice& col_name, float* val) const { |
633 | 0 | return Get<TypeTraits<FLOAT> >(col_name, val); |
634 | 0 | } |
635 | 0 | Status YBPartialRow::GetDouble(const Slice& col_name, double* val) const { |
636 | 0 | return Get<TypeTraits<DOUBLE> >(col_name, val); |
637 | 0 | } |
638 | 2 | Status YBPartialRow::GetString(const Slice& col_name, Slice* val) const { |
639 | 2 | return Get<TypeTraits<STRING> >(col_name, val); |
640 | 2 | } |
641 | 0 | Status YBPartialRow::GetBinary(const Slice& col_name, Slice* val) const { |
642 | 0 | return Get<TypeTraits<BINARY> >(col_name, val); |
643 | 0 | } |
644 | 0 | Status YBPartialRow::GetInet(const Slice& col_name, Slice* val) const { |
645 | 0 | return Get<TypeTraits<INET> >(col_name, val); |
646 | 0 | } |
647 | 0 | Status YBPartialRow::GetJsonb(const Slice& col_name, Slice* val) const { |
648 | 0 | return Get<TypeTraits<JSONB> >(col_name, val); |
649 | 0 | } |
650 | 0 | Status YBPartialRow::GetUuid(const Slice& col_name, Slice* val) const { |
651 | 0 | return Get<TypeTraits<UUID> >(col_name, val); |
652 | 0 | } |
653 | 0 | Status YBPartialRow::GetTimeUuid(const Slice& col_name, Slice* val) const { |
654 | 0 | return Get<TypeTraits<TIMEUUID> >(col_name, val); |
655 | 0 | } |
656 | 0 | Status YBPartialRow::GetBool(size_t col_idx, bool* val) const { |
657 | 0 | return Get<TypeTraits<BOOL> >(col_idx, val); |
658 | 0 | } |
659 | 0 | Status YBPartialRow::GetInt8(size_t col_idx, int8_t* val) const { |
660 | 0 | return Get<TypeTraits<INT8> >(col_idx, val); |
661 | 0 | } |
662 | 0 | Status YBPartialRow::GetInt16(size_t col_idx, int16_t* val) const { |
663 | 0 | return Get<TypeTraits<INT16> >(col_idx, val); |
664 | 0 | } |
665 | 2 | Status YBPartialRow::GetInt32(size_t col_idx, int32_t* val) const { |
666 | 2 | return Get<TypeTraits<INT32> >(col_idx, val); |
667 | 2 | } |
668 | 0 | Status YBPartialRow::GetInt64(size_t col_idx, int64_t* val) const { |
669 | 0 | return Get<TypeTraits<INT64> >(col_idx, val); |
670 | 0 | } |
671 | 0 | Status YBPartialRow::GetTimestamp(size_t col_idx, int64_t* micros_since_utc_epoch) const { |
672 | 0 | return Get<TypeTraits<TIMESTAMP> >(col_idx, micros_since_utc_epoch); |
673 | 0 | } |
674 | 0 | Status YBPartialRow::GetFloat(size_t col_idx, float* val) const { |
675 | 0 | return Get<TypeTraits<FLOAT> >(col_idx, val); |
676 | 0 | } |
677 | 0 | Status YBPartialRow::GetDouble(size_t col_idx, double* val) const { |
678 | 0 | return Get<TypeTraits<DOUBLE> >(col_idx, val); |
679 | 0 | } |
680 | 3 | Status YBPartialRow::GetString(size_t col_idx, Slice* val) const { |
681 | 3 | return Get<TypeTraits<STRING> >(col_idx, val); |
682 | 3 | } |
683 | 2 | Status YBPartialRow::GetBinary(size_t col_idx, Slice* val) const { |
684 | 2 | return Get<TypeTraits<BINARY> >(col_idx, val); |
685 | 2 | } |
686 | 0 | Status YBPartialRow::GetInet(size_t col_idx, Slice* val) const { |
687 | 0 | return Get<TypeTraits<INET> >(col_idx, val); |
688 | 0 | } |
689 | 0 | Status YBPartialRow::GetJsonb(size_t col_idx, Slice* val) const { |
690 | 0 | return Get<TypeTraits<JSONB> >(col_idx, val); |
691 | 0 | } |
692 | 0 | Status YBPartialRow::GetUuid(size_t col_idx, Slice* val) const { |
693 | 0 | return Get<TypeTraits<UUID> >(col_idx, val); |
694 | 0 | } |
695 | 0 | Status YBPartialRow::GetTimeUuid(size_t col_idx, Slice* val) const { |
696 | 0 | return Get<TypeTraits<TIMEUUID> >(col_idx, val); |
697 | 0 | } |
698 | | |
699 | | template<typename T> |
700 | | Status YBPartialRow::Get(const Slice& col_name, |
701 | 3 | typename T::cpp_type* val) const { |
702 | 3 | return Get<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val); |
703 | 3 | } Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)6> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)6>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)1> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)1>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)2> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)2>::cpp_type*) const yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)3> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)3>::cpp_type*) const Line | Count | Source | 701 | 1 | typename T::cpp_type* val) const { | 702 | 1 | return Get<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val); | 703 | 1 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)4> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)4>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)10> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)10>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)7> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)7>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)8> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)8>::cpp_type*) const yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)5> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)5>::cpp_type*) const Line | Count | Source | 701 | 2 | typename T::cpp_type* val) const { | 702 | 2 | return Get<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val); | 703 | 2 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)9> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)9>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)13> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)13>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)25> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)25>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)17> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)17>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)18> >(yb::Slice const&, yb::TypeTraits<(yb::DataType)18>::cpp_type*) const |
704 | | |
705 | | template<typename T> |
706 | 10 | Status YBPartialRow::Get(size_t col_idx, typename T::cpp_type* val) const { |
707 | 10 | const ColumnSchema& col = schema_->column(col_idx); |
708 | 10 | if (PREDICT_FALSE(col.type_info()->type != T::type)) { |
709 | | // TODO: at some point we could allow type coercion here. |
710 | 1 | return STATUS(InvalidArgument, |
711 | 1 | Substitute("invalid type $0 provided for column '$1' (expected $2)", |
712 | 1 | T::name(), |
713 | 1 | col.name(), col.type_info()->name)); |
714 | 1 | } |
715 | | |
716 | 9 | if (PREDICT_FALSE(!IsColumnSet(col_idx))) { |
717 | 0 | return STATUS(NotFound, "column not set"); |
718 | 0 | } |
719 | 9 | if (col.is_nullable() && IsNull(col_idx)6 ) { |
720 | 0 | return STATUS(NotFound, "column is NULL"); |
721 | 0 | } |
722 | | |
723 | 9 | ContiguousRow row(schema_, row_data_); |
724 | 9 | memcpy(val, row.cell_ptr(col_idx), sizeof(*val)); |
725 | 9 | return Status::OK(); |
726 | 9 | } Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)6> >(unsigned long, yb::TypeTraits<(yb::DataType)6>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)1> >(unsigned long, yb::TypeTraits<(yb::DataType)1>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)2> >(unsigned long, yb::TypeTraits<(yb::DataType)2>::cpp_type*) const yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)3> >(unsigned long, yb::TypeTraits<(yb::DataType)3>::cpp_type*) const Line | Count | Source | 706 | 3 | Status YBPartialRow::Get(size_t col_idx, typename T::cpp_type* val) const { | 707 | 3 | const ColumnSchema& col = schema_->column(col_idx); | 708 | 3 | if (PREDICT_FALSE(col.type_info()->type != T::type)) { | 709 | | // TODO: at some point we could allow type coercion here. | 710 | 0 | return STATUS(InvalidArgument, | 711 | 0 | Substitute("invalid type $0 provided for column '$1' (expected $2)", | 712 | 0 | T::name(), | 713 | 0 | col.name(), col.type_info()->name)); | 714 | 0 | } | 715 | | | 716 | 3 | if (PREDICT_FALSE(!IsColumnSet(col_idx))) { | 717 | 0 | return STATUS(NotFound, "column not set"); | 718 | 0 | } | 719 | 3 | if (col.is_nullable() && IsNull(col_idx)0 ) { | 720 | 0 | return STATUS(NotFound, "column is NULL"); | 721 | 0 | } | 722 | | | 723 | 3 | ContiguousRow row(schema_, row_data_); | 724 | 3 | memcpy(val, row.cell_ptr(col_idx), sizeof(*val)); | 725 | 3 | return Status::OK(); | 726 | 3 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)4> >(unsigned long, yb::TypeTraits<(yb::DataType)4>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)10> >(unsigned long, yb::TypeTraits<(yb::DataType)10>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)7> >(unsigned long, yb::TypeTraits<(yb::DataType)7>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)8> >(unsigned long, yb::TypeTraits<(yb::DataType)8>::cpp_type*) const yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)5> >(unsigned long, yb::TypeTraits<(yb::DataType)5>::cpp_type*) const Line | Count | Source | 706 | 5 | Status YBPartialRow::Get(size_t col_idx, typename T::cpp_type* val) const { | 707 | 5 | const ColumnSchema& col = schema_->column(col_idx); | 708 | 5 | if (PREDICT_FALSE(col.type_info()->type != T::type)) { | 709 | | // TODO: at some point we could allow type coercion here. | 710 | 1 | return STATUS(InvalidArgument, | 711 | 1 | Substitute("invalid type $0 provided for column '$1' (expected $2)", | 712 | 1 | T::name(), | 713 | 1 | col.name(), col.type_info()->name)); | 714 | 1 | } | 715 | | | 716 | 4 | if (PREDICT_FALSE(!IsColumnSet(col_idx))) { | 717 | 0 | return STATUS(NotFound, "column not set"); | 718 | 0 | } | 719 | 4 | if (col.is_nullable() && IsNull(col_idx)) { | 720 | 0 | return STATUS(NotFound, "column is NULL"); | 721 | 0 | } | 722 | | | 723 | 4 | ContiguousRow row(schema_, row_data_); | 724 | 4 | memcpy(val, row.cell_ptr(col_idx), sizeof(*val)); | 725 | 4 | return Status::OK(); | 726 | 4 | } |
yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)9> >(unsigned long, yb::TypeTraits<(yb::DataType)9>::cpp_type*) const Line | Count | Source | 706 | 2 | Status YBPartialRow::Get(size_t col_idx, typename T::cpp_type* val) const { | 707 | 2 | const ColumnSchema& col = schema_->column(col_idx); | 708 | 2 | if (PREDICT_FALSE(col.type_info()->type != T::type)) { | 709 | | // TODO: at some point we could allow type coercion here. | 710 | 0 | return STATUS(InvalidArgument, | 711 | 0 | Substitute("invalid type $0 provided for column '$1' (expected $2)", | 712 | 0 | T::name(), | 713 | 0 | col.name(), col.type_info()->name)); | 714 | 0 | } | 715 | | | 716 | 2 | if (PREDICT_FALSE(!IsColumnSet(col_idx))) { | 717 | 0 | return STATUS(NotFound, "column not set"); | 718 | 0 | } | 719 | 2 | if (col.is_nullable() && IsNull(col_idx)) { | 720 | 0 | return STATUS(NotFound, "column is NULL"); | 721 | 0 | } | 722 | | | 723 | 2 | ContiguousRow row(schema_, row_data_); | 724 | 2 | memcpy(val, row.cell_ptr(col_idx), sizeof(*val)); | 725 | 2 | return Status::OK(); | 726 | 2 | } |
Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)13> >(unsigned long, yb::TypeTraits<(yb::DataType)13>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)25> >(unsigned long, yb::TypeTraits<(yb::DataType)25>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)17> >(unsigned long, yb::TypeTraits<(yb::DataType)17>::cpp_type*) const Unexecuted instantiation: yb::Status yb::YBPartialRow::Get<yb::TypeTraits<(yb::DataType)18> >(unsigned long, yb::TypeTraits<(yb::DataType)18>::cpp_type*) const |
727 | | |
728 | | //------------------------------------------------------------ |
729 | | // Utility code |
730 | | //------------------------------------------------------------ |
731 | | |
732 | 0 | bool YBPartialRow::IsHashKeySet() const { |
733 | 0 | return schema_->num_hash_key_columns() > 0 && |
734 | 0 | BitMapIsAllSet(isset_bitmap_, 0, schema_->num_hash_key_columns()); |
735 | 0 | } |
736 | | |
737 | 2 | bool YBPartialRow::IsKeySet() const { |
738 | 2 | return schema_->num_key_columns() > 0 && |
739 | 2 | BitMapIsAllSet(isset_bitmap_, 0, schema_->num_key_columns()); |
740 | 2 | } |
741 | | |
742 | 0 | bool YBPartialRow::IsHashOrPrimaryKeySet() const { |
743 | 0 | return IsHashKeySet() || IsKeySet(); |
744 | 0 | } |
745 | | |
746 | 0 | bool YBPartialRow::AllColumnsSet() const { |
747 | 0 | return schema_->num_columns() > 0 && |
748 | 0 | BitMapIsAllSet(isset_bitmap_, 0, schema_->num_columns()); |
749 | 0 | } |
750 | | |
751 | 10 | std::string YBPartialRow::ToString() const { |
752 | 10 | ContiguousRow row(schema_, row_data_); |
753 | 10 | std::string ret; |
754 | 10 | bool first = true; |
755 | 50 | for (size_t i = 0; i < schema_->num_columns(); i++40 ) { |
756 | 40 | if (IsColumnSet(i)) { |
757 | 17 | if (!first) { |
758 | 8 | ret.append(", "); |
759 | 8 | } |
760 | 17 | schema_->column(i).DebugCellAppend(row.cell(i), &ret); |
761 | 17 | first = false; |
762 | 17 | } |
763 | 40 | } |
764 | 10 | return ret; |
765 | 10 | } |
766 | | |
767 | | //------------------------------------------------------------ |
768 | | // Serialization/deserialization |
769 | | //------------------------------------------------------------ |
770 | | |
771 | | } // namespace yb |