Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions crates/datafusion/src/read/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ pub struct IcebergDataSource {
table: Table,
/// Snapshot of the table to scan.
snapshot_id: Option<i64>,
/// Schema returned by this data source after projection.
/// Schema returned by this data source after projection. Its columns are
/// read from Iceberg by name.
schema: ArrowSchemaRef,
/// Projection column names in the output schema.
projection: Vec<String>,
/// Filter to apply to the table scan
predicate: Option<Predicate>,
/// Optional limit on the number of rows to return
Expand Down Expand Up @@ -82,17 +81,22 @@ impl IcebergDataSource {
self.schema.clone()
}

pub fn projection(&self) -> &[String] {
&self.projection
}

pub fn predicate(&self) -> Option<&Predicate> {
self.predicate.as_ref()
}

pub fn fetch(&self) -> Option<usize> {
self.fetch
}

/// The names of the columns this source reads, in output order.
fn column_names(&self) -> Vec<String> {
self.schema
.fields()
.iter()
.map(|field| field.name().clone())
.collect()
}
}

/// Builds an [`IcebergDataSource`]. Created by [`IcebergDataSource::builder`].
Expand Down Expand Up @@ -155,16 +159,10 @@ impl IcebergDataSourceBuilder {
None => self.schema,
Some(projection) => Arc::new(self.schema.project(projection)?),
};
let projection = schema
.fields()
.iter()
.map(|field| field.name().clone())
.collect();
Ok(IcebergDataSource {
table: self.table,
snapshot_id: self.snapshot_id,
schema,
projection,
predicate: self.predicate,
fetch: self.fetch,
})
Expand All @@ -187,7 +185,7 @@ impl DataSource for IcebergDataSource {
let fut = get_batch_stream(
self.table.clone(),
self.snapshot_id,
Some(self.projection.clone()),
Some(self.column_names()),
self.predicate.clone(),
context
.session_config()
Expand Down Expand Up @@ -231,7 +229,7 @@ impl DataSource for IcebergDataSource {
f: &mut std::fmt::Formatter,
) -> std::fmt::Result {
write!(f, "format=iceberg",)?;
write!(f, ", projection=[{}]", self.projection.join(", "))?;
write!(f, ", projection=[{}]", self.column_names().join(", "))?;
if let Some(predicate) = &self.predicate {
write!(f, ", predicate={predicate}")?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ mod tests {
.with_projection(Some(&vec![1, 0]))
.build()
.unwrap();
insta::assert_debug_snapshot!(source.projection(), @r#"
let projected = source.schema();
let names: Vec<_> = projected.fields().iter().map(|f| f.name()).collect();
insta::assert_debug_snapshot!(names, @r#"
[
"name",
"id",
Expand Down
3 changes: 1 addition & 2 deletions crates/datafusion/tests/integration_datafusion_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,6 @@ async fn test_plan_nodes_are_inspectable() -> Result<(), Box<dyn Error>> {
);
let rebuilt = rebuild_scan(scan);
assert_eq!(rebuilt.schema(), scan.schema());
assert_eq!(rebuilt.projection(), scan.projection());
let expected = run_source(scan, &ctx).await?;
insta::assert_snapshot!(&expected, @r#"
+------+------+
Expand All @@ -1061,7 +1060,7 @@ async fn test_plan_nodes_are_inspectable() -> Result<(), Box<dyn Error>> {
.data_source()
.downcast_ref::<IcebergDataSource>()
.expect("an Iceberg data source");
assert_eq!(scan.projection(), ["foo1".to_string(), "foo2".to_string()]);
assert_eq!(scan.schema(), pinned.schema());
let rebuilt = rebuild_scan(scan);
assert_eq!(rebuilt.fetch(), Some(1));
let expected = run_source(scan, &ctx).await?;
Expand Down
Loading