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 Haichao.chc
17 * \date Jun 2021
18 * \brief ColumnIndexer can streamly process column
19 * data, building index and dump to persist index.
20 */
21
22#pragma once
23
24#include "column_reader.h"
25
26namespace proxima {
27namespace be {
28namespace index {
29
30class ColumnIndexer;
31using ColumnIndexerPtr = std::shared_ptr<ColumnIndexer>;
32
33/*
34 * ColumnIndexer can process column data streamly. After
35 * accumulating to a certain amount, it will dump to
36 * a full index type.
37 */
38class ColumnIndexer : public ColumnReader {
39 public:
40 //! Destructor
41 virtual ~ColumnIndexer() = default;
42
43 //! Create instance and return a shared ptr
44 static ColumnIndexerPtr Create(const std::string &collection_name,
45 const std::string &collection_path,
46 SegmentID segment_id,
47 const std::string &column_name,
48 IndexTypes index_type);
49
50 public:
51 //! Flush snapshot
52 virtual int flush() = 0;
53
54 //! Dump to another kind of index
55 virtual int dump(IndexDumperPtr dumper) = 0;
56
57 //! Insert column data
58 virtual int insert(idx_t doc_id, const ColumnData &column_data) = 0;
59
60#if 0
61 //! Update column data by doc_id
62 virtual int update(idx_t doc_id, const ColumnData &column_data) = 0;
63#endif
64
65 //! Optimize index structure
66 virtual int optimize(ThreadPoolPtr /*pool */) {
67 return 0;
68 }
69
70 //! Remove column data by doc_id
71 virtual int remove(idx_t /*doc_id */) {
72 return 0;
73 }
74};
75
76
77} // end namespace index
78} // namespace be
79} // end namespace proxima
80