26#include <unordered_map>
27#include <unordered_set>
30#include "iceberg/iceberg_export.h"
31#include "iceberg/result.h"
35#include "iceberg/util/executor.h"
42 enum class Kind : uint8_t {
48 virtual Kind
kind()
const = 0;
70 explicit FileScanTask(std::shared_ptr<DataFile> data_file,
71 std::vector<std::shared_ptr<DataFile>> delete_files = {},
72 std::shared_ptr<Expression> filter =
nullptr);
75 const std::shared_ptr<DataFile>&
data_file()
const {
return data_file_; }
78 const std::vector<std::shared_ptr<DataFile>>&
delete_files()
const {
83 const std::shared_ptr<Expression>&
residual_filter()
const {
return residual_filter_; }
85 Kind
kind()
const override {
return Kind::kFileScanTask; }
86 int64_t size_bytes()
const override;
87 int32_t files_count()
const override;
88 int64_t estimated_row_count()
const override;
91 std::shared_ptr<DataFile> data_file_;
92 std::vector<std::shared_ptr<DataFile>> delete_files_;
93 std::shared_ptr<Expression> residual_filter_;
96enum class ChangelogOperation : uint8_t {
114 std::shared_ptr<DataFile> data_file,
115 std::vector<std::shared_ptr<DataFile>> delete_files = {},
116 std::shared_ptr<Expression> residual_filter =
nullptr)
117 : change_ordinal_(change_ordinal),
118 commit_snapshot_id_(commit_snapshot_id),
119 data_file_(
std::move(data_file)),
120 delete_files_(
std::move(delete_files)),
121 residual_filter_(
std::move(residual_filter)) {}
123 Kind
kind()
const override {
return Kind::kChangelogScanTask; }
125 int64_t size_bytes()
const override;
126 int32_t files_count()
const override;
127 int64_t estimated_row_count()
const override;
129 virtual ChangelogOperation operation()
const = 0;
138 const std::shared_ptr<Expression>&
residual_filter()
const {
return residual_filter_; }
141 int32_t change_ordinal_;
142 int64_t commit_snapshot_id_;
143 std::shared_ptr<DataFile> data_file_;
144 std::vector<std::shared_ptr<DataFile>> delete_files_;
145 std::shared_ptr<Expression> residual_filter_;
168 using ChangelogScanTask::ChangelogScanTask;
170 ChangelogOperation operation()
const override {
return ChangelogOperation::kInsert; }
173 const std::shared_ptr<DataFile>&
data_file()
const {
return data_file_; }
179 return delete_files_;
198 using ChangelogScanTask::ChangelogScanTask;
200 ChangelogOperation operation()
const override {
return ChangelogOperation::kDelete; }
203 const std::shared_ptr<DataFile>&
data_file()
const {
return data_file_; }
210 return delete_files_;
218 std::optional<int64_t> snapshot_id;
219 std::shared_ptr<Expression> filter;
220 bool ignore_residuals{
false};
221 bool case_sensitive{
true};
222 bool return_column_stats{
false};
223 std::unordered_set<int32_t> columns_to_keep_stats;
224 std::vector<std::string> selected_columns;
225 std::shared_ptr<Schema> projected_schema;
226 std::unordered_map<std::string, std::string> options;
227 bool from_snapshot_id_inclusive{
false};
228 std::optional<int64_t> from_snapshot_id;
229 std::optional<int64_t> to_snapshot_id;
230 std::string branch{};
231 std::optional<int64_t> min_rows_requested;
232 OptionalExecutor plan_executor;
235 [[nodiscard]] Status Validate()
const;
243 std::is_base_of_v<IncrementalScan<ChangelogScanTask>, T>;
246template <
typename ScanType = DataTableScan>
252 static Result<std::unique_ptr<TableScanBuilder<ScanType>>> Make(
253 std::shared_ptr<TableMetadata> metadata, std::shared_ptr<FileIO> io);
281 TableScanBuilder& IncludeColumnStats(
const std::vector<std::string>& requested_columns);
341 TableScanBuilder& FromSnapshot(int64_t from_snapshot_id,
bool inclusive =
false)
354 TableScanBuilder& FromSnapshot(
const std::string& ref,
bool inclusive =
false)
388 Result<std::unique_ptr<ScanType>> Build();
391 TableScanBuilder(std::shared_ptr<TableMetadata> metadata, std::shared_ptr<FileIO> io);
394 Result<std::reference_wrapper<const std::shared_ptr<Schema>>> ResolveSnapshotSchema();
395 Status ResolveColumnStatsSelection();
397 std::shared_ptr<TableMetadata> metadata_;
398 std::shared_ptr<FileIO> io_;
400 std::shared_ptr<Schema> snapshot_schema_;
401 std::optional<std::vector<std::string>> requested_column_stats_;
410 const std::shared_ptr<TableMetadata>& metadata()
const;
413 Result<std::shared_ptr<Snapshot>> snapshot()
const;
416 Result<std::shared_ptr<Schema>> schema()
const;
422 const std::shared_ptr<FileIO>& io()
const;
425 const std::shared_ptr<Expression>& filter()
const;
428 bool is_case_sensitive()
const;
431 TableScan(std::shared_ptr<TableMetadata> metadata, std::shared_ptr<Schema> schema,
434 Result<std::reference_wrapper<const std::shared_ptr<Schema>>> ResolveProjectedSchema()
437 virtual const std::vector<std::string>& ScanColumns()
const;
439 const std::shared_ptr<TableMetadata> metadata_;
440 const std::shared_ptr<Schema> schema_;
441 const std::shared_ptr<FileIO> io_;
443 mutable std::shared_ptr<Schema> projected_schema_;
452 static Result<std::unique_ptr<DataTableScan>> Make(
453 std::shared_ptr<TableMetadata> metadata, std::shared_ptr<Schema> schema,
458 Result<std::vector<std::shared_ptr<FileScanTask>>> PlanFiles()
const;
461 using TableScan::TableScan;
466template <
typename ScanTaskType>
471 virtual Result<std::vector<std::shared_ptr<ScanTaskType>>> PlanFiles()
const = 0;
474 virtual Result<std::vector<std::shared_ptr<ScanTaskType>>> PlanFiles(
475 std::optional<int64_t> from_snapshot_id_exclusive,
476 int64_t to_snapshot_id_inclusive)
const = 0;
478 using TableScan::TableScan;
481 template <
typename T>
482 friend Result<std::vector<std::shared_ptr<T>>> ResolvePlanFiles(
483 const IncrementalScan<T>& scan);
490 static Result<std::unique_ptr<IncrementalAppendScan>> Make(
491 std::shared_ptr<TableMetadata> metadata, std::shared_ptr<Schema> schema,
496 Result<std::vector<std::shared_ptr<FileScanTask>>> PlanFiles()
const override;
499 Result<std::vector<std::shared_ptr<FileScanTask>>> PlanFiles(
500 std::optional<int64_t> from_snapshot_id_exclusive,
501 int64_t to_snapshot_id_inclusive)
const override;
503 using IncrementalScan::IncrementalScan;
511 static Result<std::unique_ptr<IncrementalChangelogScan>> Make(
512 std::shared_ptr<TableMetadata> metadata, std::shared_ptr<Schema> schema,
517 Result<std::vector<std::shared_ptr<ChangelogScanTask>>> PlanFiles()
const override;
520 Result<std::vector<std::shared_ptr<ChangelogScanTask>>> PlanFiles(
521 std::optional<int64_t> from_snapshot_id_exclusive,
522 int64_t to_snapshot_id_inclusive)
const override;
524 using IncrementalScan::IncrementalScan;
527extern template class ICEBERG_EXTERN_TEMPLATE_CLASS_EXPORT
528 TableScanBuilder<DataTableScan>;
529extern template class ICEBERG_EXTERN_TEMPLATE_CLASS_EXPORT
530 TableScanBuilder<IncrementalAppendScan>;
531extern template class ICEBERG_EXTERN_TEMPLATE_CLASS_EXPORT
532 TableScanBuilder<IncrementalChangelogScan>;
A scan task for inserts generated by adding a data file to the table.
Definition table_scan.h:166
const std::shared_ptr< DataFile > & data_file() const
The data file containing the added rows.
Definition table_scan.h:173
const std::vector< std::shared_ptr< DataFile > > & delete_files() const
A list of delete files to apply when reading the data file in this task.
Definition table_scan.h:178
A scan task for reading changelog entries between snapshots.
Definition table_scan.h:104
int32_t change_ordinal() const
The position of this change in the changelog order (0-based).
Definition table_scan.h:132
int64_t commit_snapshot_id() const
The snapshot ID that committed this change.
Definition table_scan.h:135
ChangelogScanTask(int32_t change_ordinal, int64_t commit_snapshot_id, std::shared_ptr< DataFile > data_file, std::vector< std::shared_ptr< DataFile > > delete_files={}, std::shared_ptr< Expression > residual_filter=nullptr)
Construct an AddedRowsScanTask.
Definition table_scan.h:113
Kind kind() const override
The kind of scan task.
Definition table_scan.h:123
const std::shared_ptr< Expression > & residual_filter() const
Residual filter to apply after reading.
Definition table_scan.h:138
A scan that reads data files and applies delete files to filter rows.
Definition table_scan.h:447
A scan task for deletes generated by removing a data file from the table.
Definition table_scan.h:196
const std::vector< std::shared_ptr< DataFile > > & existing_deletes() const
A list of previously added delete files to apply when reading the data file in this task.
Definition table_scan.h:209
const std::shared_ptr< DataFile > & data_file() const
The data file that was deleted.
Definition table_scan.h:203
Base class for collecting errors in the builder pattern.
Definition error_collector.h:93
Schedules iceberg-cpp internal planning tasks.
Definition executor.h:43
Task representing a data file and its corresponding delete files.
Definition table_scan.h:63
Kind kind() const override
The kind of scan task.
Definition table_scan.h:85
const std::shared_ptr< DataFile > & data_file() const
The data file that should be read by this scan task.
Definition table_scan.h:75
const std::shared_ptr< Expression > & residual_filter() const
Residual filter to apply after reading.
Definition table_scan.h:83
const std::vector< std::shared_ptr< DataFile > > & delete_files() const
Delete files that apply to this data file.
Definition table_scan.h:78
A scan that reads data files added between snapshots (incremental appends).
Definition table_scan.h:487
A scan that reads changelog entries between snapshots.
Definition table_scan.h:508
A base template class for incremental scans that read changes between snapshots, and return scan task...
Definition table_scan.h:467
An abstract scan task.
Definition table_scan.h:40
virtual int32_t files_count() const =0
The number of files that should be read by this scan task.
virtual int64_t estimated_row_count() const =0
The number of rows that should be read by this scan task.
virtual int64_t size_bytes() const =0
The number of bytes that should be read by this scan task.
virtual Kind kind() const =0
The kind of scan task.
Builder class for creating TableScan instances.
Definition table_scan.h:247
Represents a configured scan operation on a table.
Definition table_scan.h:405
Definition table_scan.h:242
Definition table_scan.h:217