From 9dcbe2c0b1a80da12c2a0e4f23650c9e831db135 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Tue, 4 Nov 2025 12:04:26 +0100 Subject: [PATCH] Add Scanner::projection_from_schema --- rust/lance/src/dataset/scanner.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rust/lance/src/dataset/scanner.rs b/rust/lance/src/dataset/scanner.rs index 760e41ef4e5..100bcdeebd8 100644 --- a/rust/lance/src/dataset/scanner.rs +++ b/rust/lance/src/dataset/scanner.rs @@ -713,6 +713,25 @@ impl Scanner { Ok(self) } + /// Set the projection from a schema. + /// + /// This projection will have no complex expressions, the schema must be a subset of the dataset schema. + /// + /// With this approach it is possible to refer to portions of nested fields. + /// + /// See [`ProjectionPlan::from_schema`] for more information. + pub fn project_from_schema(&mut self, projection: &Schema) -> Result<&mut Self> { + self.explicit_projection = true; + self.projection_plan = ProjectionPlan::from_schema(self.dataset.clone(), projection)?; + if self.legacy_with_row_id { + self.projection_plan.include_row_id(); + } + if self.legacy_with_row_addr { + self.projection_plan.include_row_addr(); + } + Ok(self) + } + /// Should the filter run before the vector index is applied /// /// If true then the filter will be applied before the vector index. This