Skip to content

Commit b7becc2

Browse files
committed
fix some comments
1 parent cd07a0c commit b7becc2

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

src/iceberg/table_scan.cc

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,25 @@ TableScanBuilder& TableScanBuilder::WithFilter(
5050
}
5151

5252
Result<std::unique_ptr<TableScan>> TableScanBuilder::Build() {
53-
ICEBERG_ASSIGN_OR_RAISE(auto snapshot, snapshot_id_ ? table_.snapshot(*snapshot_id_)
54-
: Result<std::shared_ptr<Snapshot>>(
55-
table_.current_snapshot()));
56-
57-
auto ResolveSchema = [&]() -> Result<std::shared_ptr<Schema>> {
58-
if (snapshot->schema_id) {
59-
const auto& schemas = table_.schemas();
60-
if (auto it = schemas.find(*snapshot->schema_id); it != schemas.end()) {
61-
return it->second;
62-
}
53+
std::shared_ptr<Snapshot> snapshot;
54+
if (snapshot_id_) {
55+
ICEBERG_ASSIGN_OR_RAISE(snapshot, table_.snapshot(*snapshot_id_));
56+
} else {
57+
snapshot = table_.current_snapshot();
58+
}
59+
60+
std::shared_ptr<Schema> schema;
61+
if (snapshot->schema_id) {
62+
const auto& schemas = table_.schemas();
63+
if (auto it = schemas.find(*snapshot->schema_id); it != schemas.end()) {
64+
schema = it->second;
65+
} else {
6366
return InvalidData("Schema {} in snapshot {} is not found", *snapshot->schema_id,
6467
snapshot->snapshot_id);
6568
}
66-
return table_.schema();
67-
};
68-
69-
ICEBERG_ASSIGN_OR_RAISE(auto schema, ResolveSchema());
69+
} else {
70+
schema = table_.schema();
71+
}
7072

7173
std::vector<int32_t> field_ids;
7274
field_ids.reserve(column_names_.size());
@@ -78,18 +80,19 @@ Result<std::unique_ptr<TableScan>> TableScanBuilder::Build() {
7880
field_ids.emplace_back(field_opt.value().get().field_id());
7981
}
8082

81-
auto context = std::make_unique<TableScan::ScanContext>(
82-
std::move(snapshot), std::move(schema), std::move(field_ids), std::move(filter_));
83+
TableScan::ScanContext context{.snapshot = std::move(snapshot),
84+
.schema = std::move(schema),
85+
.field_ids = std::move(field_ids),
86+
.filter = std::move(filter_)};
8387
return std::make_unique<TableScan>(std::move(context), table_.io());
8488
}
8589

86-
TableScan::TableScan(std::unique_ptr<ScanContext> context,
87-
std::shared_ptr<FileIO> file_io)
90+
TableScan::TableScan(ScanContext context, std::shared_ptr<FileIO> file_io)
8891
: context_(std::move(context)), file_io_(std::move(file_io)) {}
8992

9093
Result<std::vector<std::shared_ptr<FileScanTask>>> TableScan::PlanFiles() const {
9194
ICEBERG_ASSIGN_OR_RAISE(auto manifest_list_reader,
92-
CreateManifestListReader(context_->snapshot_->manifest_list));
95+
CreateManifestListReader(context_.snapshot->manifest_list));
9396
ICEBERG_ASSIGN_OR_RAISE(auto manifest_files, manifest_list_reader->Files());
9497

9598
std::vector<std::shared_ptr<FileScanTask>> tasks;
@@ -102,8 +105,8 @@ Result<std::vector<std::shared_ptr<FileScanTask>>> TableScan::PlanFiles() const
102105
const auto& data_file = manifest->data_file;
103106
tasks.emplace_back(std::make_shared<FileScanTask>(
104107
data_file.file_path, 0, data_file.file_size_in_bytes, data_file.record_count,
105-
data_file.content, data_file.file_format, context_->schema_,
106-
context_->field_ids_, context_->filter_));
108+
data_file.content, data_file.file_format, context_.schema, context_.field_ids,
109+
context_.filter));
107110
}
108111
}
109112
return tasks;

src/iceberg/table_scan.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <string>
2323
#include <vector>
2424

25-
#include "iceberg/expression/expression.h"
26-
#include "iceberg/file_io.h"
2725
#include "iceberg/manifest_entry.h"
2826
#include "iceberg/type_fwd.h"
2927

@@ -42,6 +40,7 @@ class ICEBERG_EXPORT TableScanBuilder {
4240
TableScanBuilder& WithSnapshotId(int64_t snapshot_id);
4341

4442
/// \brief Selects columns to include in the scan.
43+
/// Defaults to none which means select all columns
4544
/// \param column_names A list of column names.
4645
/// \return Reference to the builder.
4746
TableScanBuilder& WithColumnNames(const std::vector<std::string>& column_names);
@@ -67,16 +66,16 @@ class ICEBERG_EXPORT TableScan {
6766
public:
6867
/// \brief Scan context holding snapshot and scan-specific metadata.
6968
struct ScanContext {
70-
std::shared_ptr<Snapshot> snapshot_; ///< Snapshot to scan.
71-
std::shared_ptr<Schema> schema_; ///< Projected schema.
72-
std::vector<int32_t> field_ids_; ///< Field IDs of selected columns.
73-
std::shared_ptr<Expression> filter_; ///< Filter expression to apply.
69+
std::shared_ptr<Snapshot> snapshot; ///< Snapshot to scan.
70+
std::shared_ptr<Schema> schema; ///< Table schema.
71+
std::vector<int32_t> field_ids; ///< Field IDs of selected columns.
72+
std::shared_ptr<Expression> filter; ///< Filter expression to apply.
7473
};
7574

7675
/// \brief Constructs a TableScan with the given context and file I/O.
7776
/// \param context Scan context including snapshot, schema, and filter.
7877
/// \param file_io File I/O instance for reading manifests and data files.
79-
TableScan(std::unique_ptr<ScanContext> context, std::shared_ptr<FileIO> file_io);
78+
TableScan(ScanContext context, std::shared_ptr<FileIO> file_io);
8079

8180
/// \brief Plans the scan tasks by resolving manifests and data files.
8281
///
@@ -97,7 +96,7 @@ class ICEBERG_EXPORT TableScan {
9796
Result<std::unique_ptr<ManifestReader>> CreateManifestReader(
9897
const std::string& file_path) const;
9998

100-
std::unique_ptr<ScanContext> context_;
99+
ScanContext context_;
101100
std::shared_ptr<FileIO> file_io_;
102101
};
103102

@@ -109,7 +108,7 @@ struct ICEBERG_EXPORT FileScanTask {
109108
std::optional<uint64_t> record_count; ///< Optional number of records.
110109
DataFile::Content file_content; ///< Type of file content.
111110
FileFormatType file_format; ///< Format of the data file.
112-
std::shared_ptr<Schema> schema; ///< Projected schema.
111+
std::shared_ptr<Schema> schema; ///< Table schema.
113112
std::vector<int32_t> field_ids; ///< Field IDs to project.
114113
std::shared_ptr<Expression> filter; ///< Filter expression to apply.
115114
};

src/iceberg/type_fwd.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ class LocationProvider;
9191
class SortField;
9292
class SortOrder;
9393
class Table;
94-
class TableScan;
95-
struct FileScanTask;
9694
class FileIO;
97-
class TableScanBuilder;
9895
class Transaction;
9996
class Transform;
10097
class TransformFunction;
@@ -112,6 +109,12 @@ class NameMapping;
112109
enum class SnapshotRefType;
113110
enum class TransformType;
114111

112+
class Expression;
113+
114+
struct FileScanTask;
115+
class TableScan;
116+
class TableScanBuilder;
117+
115118
/// ----------------------------------------------------------------------------
116119
/// TODO: Forward declarations below are not added yet.
117120
/// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)