Xuanwo commented on code in PR #259: URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1524241367
########## crates/iceberg/src/table.rs: ########## @@ -63,3 +64,99 @@ impl Table { TableScanBuilder::new(self) } } + +/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog. +/// It can only be used to read metadata and for table scan. +/// # Examples +/// +/// ```rust, no_run +/// # use iceberg::io::FileIO; +/// # use iceberg::table::StaticTable; +/// # use iceberg::TableIdent; +/// # tokio_test::block_on(async { Review Comment: We can avoid introducing `tokio_test` by writing an async function: ```rust #async fn test() { let metadata_file_location = "s3://bucket_name/path/to/metadata.json"; ... #} ``` ########## crates/iceberg/src/table.rs: ########## @@ -63,3 +64,99 @@ impl Table { TableScanBuilder::new(self) } } + +/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog. +/// It can only be used to read metadata and for table scan. +/// # Examples +/// +/// ```rust, no_run +/// # use iceberg::io::FileIO; +/// # use iceberg::table::StaticTable; +/// # use iceberg::TableIdent; +/// # tokio_test::block_on(async { +/// let metadata_file_location = "s3://bucket_name/path/to/metadata.json"; +/// let file_io = FileIO::from_path(&metadata_file_location).unwrap().build().unwrap(); +/// let static_identifier = TableIdent::from_strs(["static_ns", "static_table"]).unwrap(); +/// let static_table = StaticTable::from_metadata_file(&metadata_file_location, static_identifier, file_io).await.unwrap(); +/// let snapshot_id = static_table +/// .metadata() +/// .current_snapshot() +/// .unwrap() +/// .snapshot_id(); +/// # }); +/// ``` +pub struct StaticTable(Table); + +impl StaticTable { + /// Creates a static table from a given `TableMetadata` and `FileIO` + pub async fn from_metadata( + metadata: TableMetadata, + table_ident: TableIdent, + file_io: FileIO, + ) -> anyhow::Result<Self> { + let table = Table::builder() + .metadata(metadata) + .identifier(table_ident) + .file_io(file_io) + .build(); + Ok(Self(table)) + } + + /// Creates a static table directly from metadata file and `FileIO` + pub async fn from_metadata_file( + metadata_file_path: &str, + table_ident: TableIdent, + file_io: FileIO, + ) -> anyhow::Result<Self> { Review Comment: The same. ########## crates/iceberg/src/table.rs: ########## @@ -63,3 +64,99 @@ impl Table { TableScanBuilder::new(self) } } + +/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog. +/// It can only be used to read metadata and for table scan. +/// # Examples +/// +/// ```rust, no_run +/// # use iceberg::io::FileIO; +/// # use iceberg::table::StaticTable; +/// # use iceberg::TableIdent; +/// # tokio_test::block_on(async { +/// let metadata_file_location = "s3://bucket_name/path/to/metadata.json"; +/// let file_io = FileIO::from_path(&metadata_file_location).unwrap().build().unwrap(); +/// let static_identifier = TableIdent::from_strs(["static_ns", "static_table"]).unwrap(); +/// let static_table = StaticTable::from_metadata_file(&metadata_file_location, static_identifier, file_io).await.unwrap(); +/// let snapshot_id = static_table +/// .metadata() +/// .current_snapshot() +/// .unwrap() +/// .snapshot_id(); +/// # }); +/// ``` +pub struct StaticTable(Table); Review Comment: `static` has special meanings in Rust. Have we considered using `ReadOnlyTable` for greater expressiveness? ########## crates/iceberg/src/table.rs: ########## @@ -63,3 +64,99 @@ impl Table { TableScanBuilder::new(self) } } + +/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog. +/// It can only be used to read metadata and for table scan. +/// # Examples +/// +/// ```rust, no_run +/// # use iceberg::io::FileIO; +/// # use iceberg::table::StaticTable; +/// # use iceberg::TableIdent; +/// # tokio_test::block_on(async { +/// let metadata_file_location = "s3://bucket_name/path/to/metadata.json"; +/// let file_io = FileIO::from_path(&metadata_file_location).unwrap().build().unwrap(); +/// let static_identifier = TableIdent::from_strs(["static_ns", "static_table"]).unwrap(); +/// let static_table = StaticTable::from_metadata_file(&metadata_file_location, static_identifier, file_io).await.unwrap(); +/// let snapshot_id = static_table +/// .metadata() +/// .current_snapshot() +/// .unwrap() +/// .snapshot_id(); +/// # }); +/// ``` +pub struct StaticTable(Table); + +impl StaticTable { + /// Creates a static table from a given `TableMetadata` and `FileIO` + pub async fn from_metadata( + metadata: TableMetadata, + table_ident: TableIdent, + file_io: FileIO, + ) -> anyhow::Result<Self> { Review Comment: How about using `iceberg::Result` here? -- 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