Line | Count | Source |
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 | | #pragma once |
19 | | |
20 | | #include <memory> |
21 | | #include <utility> |
22 | | |
23 | | #include "common/status.h" // for Status |
24 | | #include "core/column/column.h" |
25 | | |
26 | | namespace doris { |
27 | | namespace segment_v2 { |
28 | | |
29 | | // PageDecoder is used to decode page. |
30 | | class PageDecoder { |
31 | | public: |
32 | 21.0k | PageDecoder() {} |
33 | | |
34 | 21.0k | virtual ~PageDecoder() {} |
35 | | |
36 | | // Call this to do some preparation for decoder. |
37 | | // eg: parse data page header |
38 | | virtual Status init() = 0; |
39 | | |
40 | | // Seek the decoder to the given positional index of the page. |
41 | | // For example, seek_to_position_in_page(0) seeks to the first |
42 | | // stored entry. |
43 | | // |
44 | | // It is an error to call this with a value larger than Count(). |
45 | | // Doing so has undefined results. |
46 | | virtual Status seek_to_position_in_page(size_t pos) = 0; |
47 | | |
48 | | // Seek the decoder to the given value in the page, or the |
49 | | // lowest value which is greater than the given value. |
50 | | // |
51 | | // If the decoder was able to locate an exact match, then |
52 | | // sets *exact_match to true. Otherwise sets *exact_match to |
53 | | // false, to indicate that the seeked value is _after_ the |
54 | | // requested value. |
55 | | // |
56 | | // If the given value is less than the lowest value in the page, |
57 | | // seeks to the start of the page. If it is higher than the highest |
58 | | // value in the page, then returns Status::Error<ENTRY_NOT_FOUND> |
59 | | // |
60 | | // This will only return valid results when the data page |
61 | | // consists of values in sorted order. |
62 | 0 | virtual Status seek_at_or_after_value(const void* value, bool* exact_match) { |
63 | 0 | return Status::NotSupported("seek_at_or_after_value"); // FIXME |
64 | 0 | } |
65 | | |
66 | | virtual Status next_batch(size_t* n, MutableColumnPtr& dst) = 0; |
67 | | |
68 | | virtual Status read_by_rowids(const rowid_t* rowids, ordinal_t page_first_ordinal, size_t* n, |
69 | 0 | MutableColumnPtr& dst) { |
70 | 0 | return Status::NotSupported("not implement vec op now"); |
71 | 0 | } |
72 | | |
73 | | // Same as `next_batch` except for not moving forward the cursor. |
74 | | // When read array's ordinals in `ArrayFileColumnIterator`, we want to read one extra ordinal |
75 | | // but do not want to move forward the cursor. |
76 | 0 | virtual Status peek_next_batch(size_t* n, MutableColumnPtr& dst) { |
77 | 0 | return Status::NotSupported("not implement vec op now"); |
78 | 0 | } |
79 | | |
80 | | // Return the number of elements in this page. |
81 | | virtual size_t count() const = 0; |
82 | | |
83 | | // Return the position within the page of the currently seeked |
84 | | // entry (ie the entry that will next be returned by next_vector()) |
85 | | virtual size_t current_index() const = 0; |
86 | | |
87 | 0 | bool has_remaining() const { return current_index() < count(); } |
88 | | |
89 | 0 | virtual Status get_dict_word_info(StringRef* dict_word_info) { |
90 | 0 | return Status::NotSupported("get_dict_word_info not implement"); |
91 | 0 | } |
92 | | |
93 | | // Fixed-width decoders can hand out pointers into their decoded page buffer. The owner keeps |
94 | | // that page alive after next_batch() returns if the destination column chooses a zero-copy |
95 | | // immutable view; destinations that cannot use it still copy through the default column API. |
96 | 12.3k | void set_page_data_owner(std::shared_ptr<void> page_data_owner) { |
97 | 12.3k | _page_data_owner = std::move(page_data_owner); |
98 | 12.3k | } |
99 | | |
100 | | private: |
101 | | DISALLOW_COPY_AND_ASSIGN(PageDecoder); |
102 | | |
103 | | protected: |
104 | | std::shared_ptr<void> _page_data_owner; |
105 | | }; |
106 | | |
107 | | } // namespace segment_v2 |
108 | | } // namespace doris |