3434namespace iceberg {
3535
3636// implement FileScanTask
37- FileScanTask::FileScanTask (std::shared_ptr<DataFile> file )
38- : data_file_(std::move(file )) {}
37+ FileScanTask::FileScanTask (std::shared_ptr<DataFile> data_file )
38+ : data_file_(std::move(data_file )) {}
3939
4040const std::shared_ptr<DataFile>& FileScanTask::data_file () const { return data_file_; }
4141
@@ -94,32 +94,13 @@ Result<std::unique_ptr<TableScan>> TableScanBuilder::Build() {
9494 return InvalidArgument (" No snapshot ID specified for table {}" ,
9595 table_metadata->table_uuid );
9696 }
97- auto iter = std::ranges::find_if (
98- table_metadata->snapshots ,
99- [id = *snapshot_id](const auto & snapshot) { return snapshot->snapshot_id == id; });
100- if (iter == table_metadata->snapshots .end ()) {
101- return NotFound (" Snapshot with ID {} is not found" , *snapshot_id);
102- }
103- context_.snapshot = *iter;
97+ ICEBERG_ASSIGN_OR_RAISE (context_.snapshot , table_metadata->SnapshotById (*snapshot_id));
10498
10599 if (!context_.projected_schema ) {
106100 const auto & snapshot = context_.snapshot ;
107101 auto schema_id =
108102 snapshot->schema_id ? snapshot->schema_id : table_metadata->current_schema_id ;
109- if (!schema_id) {
110- return InvalidArgument (" No schema ID found in snapshot {} for table {}" ,
111- snapshot->snapshot_id , table_metadata->table_uuid );
112- }
113-
114- const auto & schemas = table_metadata->schemas ;
115- const auto it = std::ranges::find_if (schemas, [id = *schema_id](const auto & schema) {
116- return schema->schema_id () == id;
117- });
118- if (it == schemas.end ()) {
119- return InvalidArgument (" Schema {} in snapshot {} is not found" ,
120- *snapshot->schema_id , snapshot->snapshot_id );
121- }
122- const auto & schema = *it;
103+ ICEBERG_ASSIGN_OR_RAISE (auto schema, table_metadata->SchemaById (schema_id));
123104
124105 if (column_names_.empty ()) {
125106 context_.projected_schema = schema;
@@ -139,6 +120,9 @@ Result<std::unique_ptr<TableScan>> TableScanBuilder::Build() {
139120 context_.projected_schema =
140121 std::make_shared<Schema>(std::move (projected_fields), schema->schema_id ());
141122 }
123+ } else if (!column_names_.empty ()) {
124+ return InvalidArgument (
125+ " Cannot specify column names when a projected schema is provided" );
142126 }
143127
144128 return std::make_unique<DataTableScan>(std::move (context_), file_io_);
0 commit comments