1 | /** |
2 | * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | * |
16 | * \author guonix |
17 | * \date Nov 2020 |
18 | * \brief |
19 | */ |
20 | |
21 | #include "forward_serializer.h" |
22 | #include "common/error_code.h" |
23 | #include "common/logger.h" |
24 | |
25 | namespace proxima { |
26 | namespace be { |
27 | namespace query { |
28 | |
29 | bool ForwardSerializer::Deserialize(const std::string &buf, |
30 | proto::GenericValueList *values) { |
31 | return values->ParseFromString(buf); |
32 | } |
33 | |
34 | int ForwardSerializer::FillForward(const index::QueryResult &forward, |
35 | const ColumnNameList &columns, |
36 | proto::Document *doc) { |
37 | proto::GenericValueList values; |
38 | ForwardSerializer::Deserialize(forward.forward_data, &values); |
39 | |
40 | if (static_cast<size_t>(values.values_size()) != columns.size()) { |
41 | LOG_DEBUG("Mismatch forwards. buf_size[%lu], values[%d], forwards[%lu]" , |
42 | forward.forward_data.size(), values.values_size(), |
43 | columns.size()); |
44 | return PROXIMA_BE_ERROR_CODE(MismatchedForward); |
45 | } |
46 | |
47 | for (size_t pos = 0; pos < columns.size(); pos++) { |
48 | proto::GenericKeyValue *kv = doc->add_forward_column_values(); |
49 | kv->set_key(columns[pos]); |
50 | kv->mutable_value()->Swap(values.mutable_values(pos)); |
51 | } |
52 | |
53 | return 0; |
54 | } |
55 | |
56 | } // namespace query |
57 | } // namespace be |
58 | } // namespace proxima |
59 | |