|
23 | 23 | #include <string> |
24 | 24 | #include <vector> |
25 | 25 |
|
26 | | -#include "paimon/global_index/row_range_global_index_scanner.h" |
| 26 | +#include "paimon/global_index/global_index_reader.h" |
| 27 | +#include "paimon/global_index/global_index_result.h" |
| 28 | +#include "paimon/predicate/predicate.h" |
27 | 29 | #include "paimon/utils/range.h" |
| 30 | +#include "paimon/utils/row_range_index.h" |
28 | 31 | #include "paimon/visibility.h" |
29 | | - |
30 | 32 | namespace paimon { |
31 | 33 | class MemoryPool; |
32 | 34 | class FileSystem; |
| 35 | + |
33 | 36 | /// Represents a logical scan over a global index for a table. |
34 | 37 | class PAIMON_EXPORT GlobalIndexScan { |
35 | 38 | public: |
36 | 39 | /// Creates a `GlobalIndexScan` instance for the specified table and context. |
37 | | - /// |
38 | 40 | /// @param table_path Root directory of the table. |
39 | 41 | /// @param snapshot_id Optional snapshot id to read from; if not provided, uses the latest. |
40 | 42 | /// @param partitions Optional list of specific partitions to restrict the scan scope. |
41 | 43 | /// Each map represents one partition (e.g., {"dt": "2024-06-01"}). |
42 | | - /// If omitted, scans all partitions. |
43 | | - /// @param options Index-specific configuration. |
| 44 | + /// If omitted (`std::nullopt`), scans all partitions of the table. |
| 45 | + /// @param options User defined configuration. |
44 | 46 | /// @param file_system File system for accessing index files. |
45 | 47 | /// If not provided (nullptr), it is inferred from the `FILE_SYSTEM` |
46 | 48 | /// key in the `options` parameter. |
| 49 | + /// @param executor The executor to be used for asynchronous operations during global |
| 50 | + /// index scan. |
47 | 51 | /// @param pool Memory pool for temporary allocations; if nullptr, uses default. |
48 | 52 | /// @return A `Result` containing a unique pointer to the created scanner, |
49 | | - /// or an error if initialization fails (e.g., I/O error). |
| 53 | + /// or an error if initialization fails (e.g., I/O error, invalid snapshot id, |
| 54 | + /// unknown partition). |
50 | 55 | static Result<std::unique_ptr<GlobalIndexScan>> Create( |
51 | 56 | const std::string& table_path, const std::optional<int64_t>& snapshot_id, |
52 | 57 | const std::optional<std::vector<std::map<std::string, std::string>>>& partitions, |
53 | 58 | const std::map<std::string, std::string>& options, |
54 | | - const std::shared_ptr<FileSystem>& file_system, const std::shared_ptr<MemoryPool>& pool); |
| 59 | + const std::shared_ptr<FileSystem>& file_system, const std::shared_ptr<Executor>& executor, |
| 60 | + const std::shared_ptr<MemoryPool>& pool); |
55 | 61 |
|
56 | | - /// Creates a `GlobalIndexScan` instance for the specified table and context. |
57 | | - /// |
58 | | - /// @param partition_filters Optional specific partition predicates. |
| 62 | + /// Creates a `GlobalIndexScan` instance for the specified table and context, with a |
| 63 | + /// predicate-based partition filter. |
| 64 | + /// @param root_path Root directory of the table. |
| 65 | + /// @param snapshot_id Optional snapshot id to read from; if not provided, uses the |
| 66 | + /// latest snapshot. |
| 67 | + /// @param partition_filters Optional partition-level predicate used for partition pruning. |
| 68 | + /// If nullptr, all partitions are scanned. |
| 69 | + /// @param options User defined configuration. |
| 70 | + /// @param file_system File system for accessing index files. If nullptr, it is |
| 71 | + /// inferred from the `FILE_SYSTEM` key in `options`. |
| 72 | + /// @param executor The executor to be used for asynchronous operations during global |
| 73 | + /// index scan. |
| 74 | + /// @param pool Memory pool for temporary allocations; if nullptr, uses default. |
| 75 | + /// @return A `Result` containing a unique pointer to the created scanner, |
| 76 | + /// or an error if initialization fails. |
59 | 77 | static Result<std::unique_ptr<GlobalIndexScan>> Create( |
60 | 78 | const std::string& root_path, const std::optional<int64_t>& snapshot_id, |
61 | 79 | const std::shared_ptr<Predicate>& partition_filters, |
62 | 80 | const std::map<std::string, std::string>& options, |
63 | | - const std::shared_ptr<FileSystem>& file_system, |
64 | | - const std::shared_ptr<MemoryPool>& memory_pool); |
| 81 | + const std::shared_ptr<FileSystem>& file_system, const std::shared_ptr<Executor>& executor, |
| 82 | + const std::shared_ptr<MemoryPool>& pool); |
65 | 83 |
|
66 | 84 | virtual ~GlobalIndexScan() = default; |
67 | 85 |
|
68 | | - /// Creates a scanner for the global index over the specified row id range. |
69 | | - /// |
70 | | - /// This method instantiates a low-level scanner that can evaluate predicates and |
71 | | - /// retrieve matching row ids from the global index data corresponding to the given |
72 | | - /// row id range. |
73 | | - /// |
74 | | - /// @param range The inclusive row id range [start, end] for which to create the scanner. |
75 | | - /// The range must be fully covered by existing global index data (from |
76 | | - /// `GetRowRangeList()`). |
77 | | - /// @return A `Result` containing a range-level scanner, or an error if parse index meta fails. |
78 | | - virtual Result<std::shared_ptr<RowRangeGlobalIndexScanner>> CreateRangeScan( |
79 | | - const Range& range) = 0; |
| 86 | + /// Creates several `GlobalIndexReader`s for a specific field. |
| 87 | + /// @param field_name Name of the indexed column. |
| 88 | + /// @param row_range_index Optional row range that limits the scan to a sub-range of row ids. |
| 89 | + /// If not provided, the entire row range is considered. |
| 90 | + /// @return A `Result` that is: |
| 91 | + /// - Successful with several readers(with global row id) if the indexes exist and load |
| 92 | + /// correctly; |
| 93 | + /// - Successful with an empty vector if no index was built for the given field; |
| 94 | + /// - Error returns when loading fails (e.g., file corruption, I/O error, |
| 95 | + /// unsupported format). |
| 96 | + virtual Result<std::vector<std::shared_ptr<GlobalIndexReader>>> CreateReaders( |
| 97 | + const std::string& field_name, |
| 98 | + const std::optional<RowRangeIndex>& row_range_index) const = 0; |
80 | 99 |
|
81 | | - /// Returns row id ranges covered by this global index (sorted and non-overlapping |
82 | | - /// ranges). |
83 | | - /// |
84 | | - /// Each `Range` represents a contiguous segment of row ids for which global index |
85 | | - /// data exists. This allows the query engine to parallelize scanning and be aware |
86 | | - /// of ranges that are not covered by any global index. |
87 | | - /// |
88 | | - /// @return A `Result` containing sorted and non-overlapping `Range` objects. |
89 | | - virtual Result<std::vector<Range>> GetRowRangeList() = 0; |
| 100 | + /// Creates several `GlobalIndexReader`s for a specific field (looked up by id), |
| 101 | + /// @param field_id Field id of the indexed column. |
| 102 | + /// @param row_range_index Optional row range that limits the scan to a sub-range of row ids. |
| 103 | + /// If not provided, the entire row range is considered. |
| 104 | + /// @return A `Result` that is: |
| 105 | + /// - Successful with several readers(with global row id) if the indexes exist and load |
| 106 | + /// correctly; |
| 107 | + /// - Successful with an empty vector if no index was built for the given field; |
| 108 | + /// - Error returns when loading fails (e.g., file corruption, I/O error, |
| 109 | + /// unsupported format). |
| 110 | + virtual Result<std::vector<std::shared_ptr<GlobalIndexReader>>> CreateReaders( |
| 111 | + int32_t field_id, const std::optional<RowRangeIndex>& row_range_index) const = 0; |
90 | 112 | }; |
91 | 113 |
|
92 | 114 | } // namespace paimon |
0 commit comments