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 Dianzhang.Chen |
17 | * \date Feb 2021 |
18 | * \brief Columns order implements for proxima search engine |
19 | */ |
20 | |
21 | #include "column_order.h" |
22 | |
23 | namespace proxima { |
24 | namespace be { |
25 | namespace agent { |
26 | |
27 | void ColumnOrder::init_column_order(const meta::CollectionMeta &meta) { |
28 | auto &forward_columns = meta.forward_columns(); |
29 | for (size_t i = 0; i < forward_columns.size(); i++) { |
30 | forward_order_[forward_columns[i]] = i; |
31 | } |
32 | |
33 | auto index_columns = meta.index_columns(); |
34 | for (size_t i = 0; i < index_columns.size(); i++) { |
35 | index_order_[index_columns[i]->name()] = i; |
36 | } |
37 | } |
38 | |
39 | void ColumnOrderMap::add_column_order(const meta::CollectionMeta &meta) { |
40 | ColumnOrderPtr column_order = std::make_shared<ColumnOrder>(); |
41 | column_order->init_column_order(meta); |
42 | |
43 | auto &name = meta.name(); |
44 | std::lock_guard<std::mutex> lock(mutex_); |
45 | column_order_map_[name] = column_order; |
46 | } |
47 | |
48 | void ColumnOrderMap::update_column_order(const meta::CollectionMeta &meta) { |
49 | ColumnOrderPtr column_order = std::make_shared<ColumnOrder>(); |
50 | column_order->init_column_order(meta); |
51 | |
52 | auto &name = meta.name(); |
53 | std::lock_guard<std::mutex> lock(mutex_); |
54 | column_order_map_[name] = column_order; |
55 | } |
56 | |
57 | void ColumnOrderMap::remove_column_order(const std::string &name) { |
58 | std::lock_guard<std::mutex> lock(mutex_); |
59 | column_order_map_.erase(name); |
60 | } |
61 | |
62 | ColumnOrderPtr ColumnOrderMap::get_column_order(const std::string &name) { |
63 | std::lock_guard<std::mutex> lock(mutex_); |
64 | auto it = column_order_map_.find(name); |
65 | if (it != column_order_map_.end()) { |
66 | return it->second; |
67 | } |
68 | return nullptr; |
69 | } |
70 | |
71 | } // end namespace agent |
72 | } // namespace be |
73 | } // end namespace proxima |
74 |