@@ -50,23 +50,25 @@ TableScanBuilder& TableScanBuilder::WithFilter(
5050}
5151
5252Result<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
9093Result<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;
0 commit comments