@@ -258,7 +258,7 @@ void NameToIdVisitor::Finish() {
258258 }
259259}
260260
261- // / \brief Visitor class for pruning schema columns based on selected field IDs.
261+ // / \brief Visitor for pruning columns based on selected field IDs.
262262// /
263263// / This visitor traverses a schema and creates a projected version containing only
264264// / the specified fields. When `select_full_types` is true, a field with all its
@@ -311,7 +311,7 @@ class PruneColumnVisitor {
311311
312312 if (selected_fields.empty ()) {
313313 return nullptr ;
314- } else if (same_types and selected_fields.size () == type->fields ().size ()) {
314+ } else if (same_types && selected_fields.size () == type->fields ().size ()) {
315315 return type;
316316 }
317317 return std::make_shared<StructType>(std::move (selected_fields));
@@ -369,38 +369,36 @@ Result<std::unique_ptr<Schema>> Schema::Select(std::span<const std::string> name
369369
370370 PruneColumnVisitor visitor (selected_ids, /* select_full_types=*/ true );
371371 ICEBERG_ASSIGN_OR_RAISE (
372- auto result , visitor.Visit (std::shared_ptr<StructType>(ToStructType (*this ))));
372+ auto pruned_type , visitor.Visit (std::shared_ptr<StructType>(ToStructType (*this ))));
373373
374- if (!result ) {
375- return std::make_unique<Schema>(std::vector<SchemaField>{}, schema_id_ );
374+ if (!pruned_type ) {
375+ return std::make_unique<Schema>(std::vector<SchemaField>{}, std:: nullopt );
376376 }
377377
378- if (result ->type_id () != TypeId::kStruct ) {
378+ if (pruned_type ->type_id () != TypeId::kStruct ) {
379379 return InvalidSchema (" Projected type must be a struct type" );
380380 }
381381
382- return FromStructType (std::move (const_cast <StructType&>(
383- internal::checked_cast<const StructType&>(*result))),
384- schema_id_);
382+ return FromStructType (std::move (internal::checked_cast<StructType&>(*pruned_type)),
383+ std::nullopt );
385384}
386385
387386Result<std::unique_ptr<Schema>> Schema::Project (
388387 const std::unordered_set<int32_t >& field_ids) const {
389388 PruneColumnVisitor visitor (field_ids, /* select_full_types=*/ false );
390389 ICEBERG_ASSIGN_OR_RAISE (
391- auto result , visitor.Visit (std::shared_ptr<StructType>(ToStructType (*this ))));
390+ auto project_type , visitor.Visit (std::shared_ptr<StructType>(ToStructType (*this ))));
392391
393- if (!result ) {
394- return std::make_unique<Schema>(std::vector<SchemaField>{}, schema_id_ );
392+ if (!project_type ) {
393+ return std::make_unique<Schema>(std::vector<SchemaField>{}, std:: nullopt );
395394 }
396395
397- if (result ->type_id () != TypeId::kStruct ) {
396+ if (project_type ->type_id () != TypeId::kStruct ) {
398397 return InvalidSchema (" Projected type must be a struct type" );
399398 }
400399
401- return FromStructType (std::move (const_cast <StructType&>(
402- internal::checked_cast<const StructType&>(*result))),
403- schema_id_);
400+ return FromStructType (std::move (internal::checked_cast<StructType&>(*project_type)),
401+ std::nullopt );
404402}
405403
406404} // namespace iceberg
0 commit comments