Xuanwo commented on code in PR #129: URL: https://github.com/apache/iceberg-rust/pull/129#discussion_r1445548092
########## crates/iceberg/src/spec/snapshot.rs: ########## @@ -124,6 +150,70 @@ impl Snapshot { Utc.timestamp_millis_opt(self.timestamp_ms).unwrap() } + /// Get the schema id of this snapshot. + #[inline] + pub fn schema_id(&self) -> Option<SchemaId> { + self.schema_id + } + + /// Get the schema of this snapshot. + pub fn schema(&self, table_metadata: &TableMetadata) -> Result<SchemaRef> { + Ok(match self.schema_id() { + Some(schema_id) => table_metadata + .schema_by_id(schema_id) + .ok_or_else(|| { + Error::new( + ErrorKind::DataInvalid, + format!("Schema with id {} not found", schema_id), + ) + })? + .clone(), + None => table_metadata.current_schema().clone(), + }) + } + + /// Get parent snapshot. + #[cfg(test)] + pub(crate) fn parent_snapshot(&self, table_metadata: &TableMetadata) -> Option<SnapshotRef> { + match self.parent_snapshot_id { + Some(id) => table_metadata.snapshot_by_id(id).cloned(), + None => None, + } + } + + /// Load manifest list. + pub async fn load_manifest_list( + &self, + file_io: &FileIO, + table_metadata: &TableMetadata, + ) -> Result<ManifestList> { + match &self.manifest_list { + ManifestListLocation::ManifestListFile(file) => { + let mut manifest_list_content= Vec::new(); + file_io + .new_input(file)? + .reader().await? + .read_to_end(&mut manifest_list_content) + .await?; + + let schema = self.schema(table_metadata)?; + + let partition_type_provider = |partition_spec_id: i32| -> Result<Option<StructType>> { + table_metadata.partition_spec_by_id(partition_spec_id).map(|partition_spec| { + partition_spec.partition_type(&schema) + }).transpose() + }; + + ManifestList::parse_with_version(&manifest_list_content, table_metadata.format_version(), + partition_type_provider, ) + } + ManifestListLocation::ManifestFiles(_) => Err(Error::new( Review Comment: Do you think it's a good idea to check this first so we don't need to write in enum pattern matching? ########## crates/iceberg/src/spec/snapshot.rs: ########## @@ -124,6 +150,70 @@ impl Snapshot { Utc.timestamp_millis_opt(self.timestamp_ms).unwrap() } + /// Get the schema id of this snapshot. + #[inline] + pub fn schema_id(&self) -> Option<SchemaId> { + self.schema_id + } + + /// Get the schema of this snapshot. + pub fn schema(&self, table_metadata: &TableMetadata) -> Result<SchemaRef> { + Ok(match self.schema_id() { + Some(schema_id) => table_metadata + .schema_by_id(schema_id) + .ok_or_else(|| { + Error::new( + ErrorKind::DataInvalid, + format!("Schema with id {} not found", schema_id), + ) + })? + .clone(), + None => table_metadata.current_schema().clone(), + }) + } + + /// Get parent snapshot. + #[cfg(test)] + pub(crate) fn parent_snapshot(&self, table_metadata: &TableMetadata) -> Option<SnapshotRef> { + match self.parent_snapshot_id { + Some(id) => table_metadata.snapshot_by_id(id).cloned(), + None => None, + } + } + + /// Load manifest list. + pub async fn load_manifest_list( + &self, + file_io: &FileIO, + table_metadata: &TableMetadata, + ) -> Result<ManifestList> { + match &self.manifest_list { + ManifestListLocation::ManifestListFile(file) => { + let mut manifest_list_content= Vec::new(); Review Comment: Seems not formatted? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org