liurenjie1024 commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1524075802


##########
crates/iceberg/src/table.rs:
##########
@@ -63,3 +64,98 @@ 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`

Review Comment:
   ```suggestion
       /// Creates a static table directly from metadata file and `FileIO`
   ```



##########
crates/iceberg/src/table.rs:
##########
@@ -63,3 +64,98 @@ 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))
+    }

Review Comment:
   Add a newline here?



##########
crates/iceberg/src/table.rs:
##########
@@ -63,3 +64,98 @@ 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`

Review Comment:
   ```suggestion
       /// Creates a static table from a given `TableMetadata` and `FileIO`
   ```



##########
crates/iceberg/src/table.rs:
##########
@@ -63,3 +64,98 @@ 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> {
+        let metadata_file = file_io.new_input(metadata_file_path)?;
+        let mut metadata_file_reader = metadata_file.reader().await?;
+        let mut metadata_file_content = String::new();
+        metadata_file_reader
+            .read_to_string(&mut metadata_file_content)
+            .await?;
+        let table_metadata = 
serde_json::from_str::<TableMetadata>(&metadata_file_content)?;
+        Self::from_metadata(table_metadata, table_ident, file_io).await
+    }
+
+    /// create a TableScanBuilder for the static table
+    pub fn scan(&self) -> TableScanBuilder<'_> {
+        self.0.scan()
+    }
+
+    /// get a TableMetadataRef for the static table

Review Comment:
   ```suggestion
       /// Get  TableMetadataRef for the static table
   ```



##########
crates/iceberg/src/table.rs:
##########
@@ -63,3 +64,98 @@ 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> {
+        let metadata_file = file_io.new_input(metadata_file_path)?;
+        let mut metadata_file_reader = metadata_file.reader().await?;
+        let mut metadata_file_content = String::new();
+        metadata_file_reader
+            .read_to_string(&mut metadata_file_content)
+            .await?;
+        let table_metadata = 
serde_json::from_str::<TableMetadata>(&metadata_file_content)?;
+        Self::from_metadata(table_metadata, table_ident, file_io).await
+    }
+
+    /// create a TableScanBuilder for the static table

Review Comment:
   ```suggestion
       /// Create a TableScanBuilder for the static table.
   ```



-- 
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

Reply via email to