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 interface definition for proxima search engine
19 */
20
21#pragma once
22
23#include <map>
24#include <mutex>
25#include "meta/meta.h"
26
27namespace proxima {
28namespace be {
29namespace agent {
30
31class ColumnOrder;
32class ColumnOrderMap;
33
34using ColumnOrderPtr = std::shared_ptr<ColumnOrder>;
35using ColumnOrderMapPtr = std::shared_ptr<ColumnOrderMap>;
36
37/*! Columns order
38 */
39class ColumnOrder {
40 public:
41 //! Constructor
42 ColumnOrder() = default;
43
44 //! Destructor
45 ~ColumnOrder() = default;
46
47 //! Init columns order
48 void init_column_order(const meta::CollectionMeta &meta);
49
50 //! Get forward order
51 const std::map<std::string, size_t> &get_forward_order() const {
52 return forward_order_;
53 }
54
55 //! Get index order
56 const std::map<std::string, size_t> &get_index_order() const {
57 return index_order_;
58 }
59
60 protected:
61 //! Init columns order
62 void init_column_order_impl(const meta::CollectionMeta &meta);
63
64 private:
65 std::map<std::string, size_t> forward_order_;
66 std::map<std::string, size_t> index_order_;
67};
68
69/*! Columns order Map
70 */
71class ColumnOrderMap {
72 public:
73 //! Constructor
74 ColumnOrderMap() = default;
75
76 //! Destructor
77 ~ColumnOrderMap() = default;
78
79 //! Add columns order
80 void add_column_order(const meta::CollectionMeta &meta);
81
82 //! Update columns order
83 void update_column_order(const meta::CollectionMeta &meta);
84
85 //! Remove columns order
86 void remove_column_order(const std::string &name);
87
88 //! Get collection columns order
89 ColumnOrderPtr get_column_order(const std::string &name);
90
91 private:
92 //! Mutex
93 std::mutex mutex_{};
94 //! Columns order map
95 std::map<std::string, ColumnOrderPtr> column_order_map_{};
96};
97
98} // end namespace agent
99} // namespace be
100} // end namespace proxima
101