Skip to content

Commit b7d9417

Browse files
committed
fallback to main branch of source table
1 parent cf68f27 commit b7d9417

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

datafusion_iceberg/src/materialized_view.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,26 @@ pub async fn refresh_materialized_view(
9292
Tabular::Table(table) => Ok(*table
9393
.metadata()
9494
.current_snapshot(branch.as_deref())?
95-
.unwrap()
96-
.snapshot_id()),
97-
Tabular::MaterializedView(mv) => Ok(*mv
98-
.storage_table()
99-
.await?
100-
.table_metadata
101-
.current_snapshot(branch.as_deref())?
102-
.unwrap()
95+
// Fallback to main branch
96+
.or(table.metadata().current_snapshot(None)?)
97+
.ok_or(Error::NotFound(
98+
"Snapshot in source table".to_owned(),
99+
format!("{}", &identifier.table_name()),
100+
))?
103101
.snapshot_id()),
102+
Tabular::MaterializedView(mv) => {
103+
let storage_table = mv.storage_table().await?;
104+
Ok(*storage_table
105+
.table_metadata
106+
.current_snapshot(branch.as_deref())?
107+
// Fallback to main branch
108+
.or(storage_table.table_metadata.current_snapshot(None)?)
109+
.ok_or(Error::NotFound(
110+
"Snapshot in source table".to_owned(),
111+
format!("{}", &identifier.table_name()),
112+
))?
113+
.snapshot_id())
114+
}
104115
_ => Err(Error::InvalidFormat("storage table".to_string())),
105116
}?;
106117

0 commit comments

Comments
 (0)