You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "a-agmon (via GitHub)" <gi...@apache.org> on 2024/03/13 04:26:45 UTC

[PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

a-agmon opened a new pull request, #259:
URL: https://github.com/apache/iceberg-rust/pull/259

   The PR adds a `StaticTable` struct that encapsulates `Table` and enables loading a table from meta-data, regardless of a catalog but provides only read-only access to meta-data and scan. 
   This aims to provide similar functionality to the StaticTable in pyIceberg and its main value is to make metadata accessible for various operations using only the metadata.json file


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon closed pull request #259: feat (static table): implement a read-only table struct loaded from metadata
URL: https://github.com/apache/iceberg-rust/pull/259


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1524304240


##########
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:
   @Xuanwo - Great idea. Thanks.
   Will remove the dependency



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "liurenjie1024 (via GitHub)" <gi...@apache.org>.
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "liurenjie1024 (via GitHub)" <gi...@apache.org>.
liurenjie1024 commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1522791407


##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail
+//! let metadata_file_location = "s3://bucket_name/path/to/metadata.json";
+//! let file_io = FileIO::from_path(&metadata_file_location).unwrap().build()?;
+//! let static_table = StaticTable::from_metadata_file(&metadata_file_location, file_io).await.unwrap();
+//! let snapshot_id = static_table
+//! .metadata()
+//! .current_snapshot()
+//! .unwrap()
+//! .snapshot_id();
+//! ```
+
+use crate::{
+    io::FileIO,
+    scan::TableScanBuilder,
+    spec::{TableMetadata, TableMetadataRef},
+    table::Table,
+    TableIdent,
+};
+use futures::AsyncReadExt;
+
+/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog.
+pub struct StaticTable(Table);
+
+impl StaticTable {
+    /// creates a static table from a given `TableMetadata` and `FileIO`
+    pub async fn from_metadata(metadata: TableMetadata, file_io: FileIO) -> anyhow::Result<Self> {
+        let static_identifier = TableIdent::from_strs(["static_ns", "static_table"])?;

Review Comment:
   I prefer not, user can choose their default name and it's not huge effort.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "liurenjie1024 (via GitHub)" <gi...@apache.org>.
liurenjie1024 commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1522763680


##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail
+//! let metadata_file_location = "s3://bucket_name/path/to/metadata.json";
+//! let file_io = FileIO::from_path(&metadata_file_location).unwrap().build()?;
+//! let static_table = StaticTable::from_metadata_file(&metadata_file_location, file_io).await.unwrap();
+//! let snapshot_id = static_table
+//! .metadata()
+//! .current_snapshot()
+//! .unwrap()
+//! .snapshot_id();
+//! ```
+
+use crate::{
+    io::FileIO,
+    scan::TableScanBuilder,
+    spec::{TableMetadata, TableMetadataRef},
+    table::Table,
+    TableIdent,
+};
+use futures::AsyncReadExt;
+
+/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog.
+pub struct StaticTable(Table);
+
+impl StaticTable {
+    /// creates a static table from a given `TableMetadata` and `FileIO`
+    pub async fn from_metadata(metadata: TableMetadata, file_io: FileIO) -> anyhow::Result<Self> {
+        let static_identifier = TableIdent::from_strs(["static_ns", "static_table"])?;

Review Comment:
   It's better to allow user to pass `table_identifier`?



##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail
+//! let metadata_file_location = "s3://bucket_name/path/to/metadata.json";
+//! let file_io = FileIO::from_path(&metadata_file_location).unwrap().build()?;
+//! let static_table = StaticTable::from_metadata_file(&metadata_file_location, file_io).await.unwrap();
+//! let snapshot_id = static_table
+//! .metadata()
+//! .current_snapshot()
+//! .unwrap()
+//! .snapshot_id();
+//! ```
+
+use crate::{
+    io::FileIO,
+    scan::TableScanBuilder,
+    spec::{TableMetadata, TableMetadataRef},
+    table::Table,
+    TableIdent,
+};
+use futures::AsyncReadExt;
+
+/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog.
+pub struct StaticTable(Table);
+
+impl StaticTable {
+    /// creates a static table from a given `TableMetadata` and `FileIO`
+    pub async fn from_metadata(metadata: TableMetadata, file_io: FileIO) -> anyhow::Result<Self> {
+        let static_identifier = TableIdent::from_strs(["static_ns", "static_table"])?;
+        let table = Table::builder()
+            .metadata(metadata)
+            .identifier(static_identifier)
+            .file_io(file_io)
+            .build();
+        Ok(Self(table))
+    }
+    /// creates a static table directly from metadata file and `FileIO`
+    pub async fn from_metadata_file(

Review Comment:
   Ditto.



##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail

Review Comment:
   Why this compile failed? I think the compilation can pass by adding some `using` statement?



##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail
+//! let metadata_file_location = "s3://bucket_name/path/to/metadata.json";
+//! let file_io = FileIO::from_path(&metadata_file_location).unwrap().build()?;
+//! let static_table = StaticTable::from_metadata_file(&metadata_file_location, file_io).await.unwrap();
+//! let snapshot_id = static_table
+//! .metadata()
+//! .current_snapshot()
+//! .unwrap()
+//! .snapshot_id();
+//! ```
+
+use crate::{
+    io::FileIO,
+    scan::TableScanBuilder,
+    spec::{TableMetadata, TableMetadataRef},
+    table::Table,
+    TableIdent,
+};
+use futures::AsyncReadExt;
+
+/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog.
+pub struct StaticTable(Table);

Review Comment:
   How about moving this to `table` module given they are closely related?



##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail
+//! let metadata_file_location = "s3://bucket_name/path/to/metadata.json";
+//! let file_io = FileIO::from_path(&metadata_file_location).unwrap().build()?;
+//! let static_table = StaticTable::from_metadata_file(&metadata_file_location, file_io).await.unwrap();
+//! let snapshot_id = static_table
+//! .metadata()
+//! .current_snapshot()
+//! .unwrap()
+//! .snapshot_id();
+//! ```
+
+use crate::{
+    io::FileIO,
+    scan::TableScanBuilder,
+    spec::{TableMetadata, TableMetadataRef},
+    table::Table,
+    TableIdent,
+};
+use futures::AsyncReadExt;
+
+/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog.
+pub struct StaticTable(Table);
+
+impl StaticTable {
+    /// creates a static table from a given `TableMetadata` and `FileIO`
+    pub async fn from_metadata(metadata: TableMetadata, file_io: FileIO) -> anyhow::Result<Self> {
+        let static_identifier = TableIdent::from_strs(["static_ns", "static_table"])?;
+        let table = Table::builder()
+            .metadata(metadata)
+            .identifier(static_identifier)
+            .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,
+        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, 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
+    pub fn metadata(&self) -> TableMetadataRef {
+        self.0.metadata_ref()
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::fs::{self, OpenOptions};
+    use std::io::Write;
+    use tempfile::TempDir;
+    use tera::{Context, Tera};
+
+    struct TableTestFixture {
+        table_metadata_location: String,
+    }
+
+    impl TableTestFixture {

Review Comment:
   We don't need this as we already have valid table metadata: crates/iceberg/testdata/table_metadata/TableMetadataV2Valid.json
   
   The reason we need the template metadata file because we need to test load manifest api, and it's not necessary 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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1524244075


##########
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:
   Thank @Xuanwo 
   I think the idea was to be consistent with the [Python API](https://py.iceberg.apache.org/reference/pyiceberg/table/#pyiceberg.table.StaticTable) that uses StaticTable for this functionality. I'm also OK with ReadOnlyTable



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#issuecomment-1997456731

   > > Besides one line break that I can't get the formatter to accept, I believe I have addressed all comments.
   > 
   > Looks fine to me. Waiting for @liurenjie1024's comment.
   
   Cool. Thanks.
   @liurenjie1024  @Fokko  - how would you like to proceed with this PR? 


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1525963167


##########
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:
   It is also called StaticTable in Java: https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/StaticTableOperations.java



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1522788180


##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail
+//! let metadata_file_location = "s3://bucket_name/path/to/metadata.json";
+//! let file_io = FileIO::from_path(&metadata_file_location).unwrap().build()?;
+//! let static_table = StaticTable::from_metadata_file(&metadata_file_location, file_io).await.unwrap();
+//! let snapshot_id = static_table
+//! .metadata()
+//! .current_snapshot()
+//! .unwrap()
+//! .snapshot_id();
+//! ```
+
+use crate::{
+    io::FileIO,
+    scan::TableScanBuilder,
+    spec::{TableMetadata, TableMetadataRef},
+    table::Table,
+    TableIdent,
+};
+use futures::AsyncReadExt;
+
+/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog.
+pub struct StaticTable(Table);

Review Comment:
   No problem. 



##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail
+//! let metadata_file_location = "s3://bucket_name/path/to/metadata.json";
+//! let file_io = FileIO::from_path(&metadata_file_location).unwrap().build()?;
+//! let static_table = StaticTable::from_metadata_file(&metadata_file_location, file_io).await.unwrap();
+//! let snapshot_id = static_table
+//! .metadata()
+//! .current_snapshot()
+//! .unwrap()
+//! .snapshot_id();
+//! ```
+
+use crate::{
+    io::FileIO,
+    scan::TableScanBuilder,
+    spec::{TableMetadata, TableMetadataRef},
+    table::Table,
+    TableIdent,
+};
+use futures::AsyncReadExt;
+
+/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog.
+pub struct StaticTable(Table);
+
+impl StaticTable {
+    /// creates a static table from a given `TableMetadata` and `FileIO`
+    pub async fn from_metadata(metadata: TableMetadata, file_io: FileIO) -> anyhow::Result<Self> {
+        let static_identifier = TableIdent::from_strs(["static_ns", "static_table"])?;
+        let table = Table::builder()
+            .metadata(metadata)
+            .identifier(static_identifier)
+            .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,
+        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, 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
+    pub fn metadata(&self) -> TableMetadataRef {
+        self.0.metadata_ref()
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::fs::{self, OpenOptions};
+    use std::io::Write;
+    use tempfile::TempDir;
+    use tera::{Context, Tera};
+
+    struct TableTestFixture {
+        table_metadata_location: String,
+    }
+
+    impl TableTestFixture {

Review Comment:
   Will fix this 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#issuecomment-1998906956

   Hi @liurenjie1024 and @Xuanwo 
   PR is now updated with comments from our discussion [here](https://github.com/apache/iceberg-rust/issues/246#issuecomment-1998709854)
   It adds a readonly flag to `Table`, and sets it to false by default. 
   On `StaticTable` The readonly flag is set to true, and can return a readonly `Table` using `into_table()`
   
   Thanks for the comments, this API will be very useful for my use case, in which I can safely pass along a StaticTable that will be treated as readonly.


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1522787615


##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail

Review Comment:
   I added the `compile_fail` flag because the example involves async code that requires runtime, and I didn't want to mess up the code example. I will add it. 



##########
crates/iceberg/src/static_table.rs:
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `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.
+//! For example:
+//! ```rust, compile_fail
+//! let metadata_file_location = "s3://bucket_name/path/to/metadata.json";
+//! let file_io = FileIO::from_path(&metadata_file_location).unwrap().build()?;
+//! let static_table = StaticTable::from_metadata_file(&metadata_file_location, file_io).await.unwrap();
+//! let snapshot_id = static_table
+//! .metadata()
+//! .current_snapshot()
+//! .unwrap()
+//! .snapshot_id();
+//! ```
+
+use crate::{
+    io::FileIO,
+    scan::TableScanBuilder,
+    spec::{TableMetadata, TableMetadataRef},
+    table::Table,
+    TableIdent,
+};
+use futures::AsyncReadExt;
+
+/// `StaticTable` is a read-only table struct that can be created from a metadata file or from `TableMetaData` without a catalog.
+pub struct StaticTable(Table);
+
+impl StaticTable {
+    /// creates a static table from a given `TableMetadata` and `FileIO`
+    pub async fn from_metadata(metadata: TableMetadata, file_io: FileIO) -> anyhow::Result<Self> {
+        let static_identifier = TableIdent::from_strs(["static_ns", "static_table"])?;

Review Comment:
   No problem, shall I wrap it in an Option to make it optional? 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#issuecomment-1996855461

   Thank you @liurenjie1024 and @Xuanwo for the comments!
   Besides one line break that I can't get the formatter to accept, I believe I have addressed all comments. 
   I can also add something like this to this PR if there is an agreement
   
   ```rust
       /// Consumes the `StaticTable` and return it as a `Table`
       /// Please use this method carefully as the Table it returns remains detached from a catalog
       /// and can't be used to perform modifications on the table. 
       pub fn into_table(self) -> Table {
           self.0
       }
   ```


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#issuecomment-1994980247

   Hi @liurenjie1024 ,
   Thanks much for the comments!
   I have addressed all issues. For the doctest, I added the tokio-test crate as a dev dependency in order to have an async runtime there for the async code. This seems like the right [approach](https://stackoverflow.com/a/64597248/22560711).
    It only test compile as I think its a good idea to show an example using S3 even though it can't run. At any rate this flow is unit tested. 
   
   Hope this is better


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1525759033


##########
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:
   Done. Thanks



##########
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:
   Done



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1524239432


##########
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?
   
   cc @Fokko @liurenjie1024 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#issuecomment-1996883720

   > Besides one line break that I can't get the formatter to accept, I believe I have addressed all comments.
   
   Looks fine to me. Waiting for @liurenjie1024's comment.


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko merged PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "a-agmon (via GitHub)" <gi...@apache.org>.
a-agmon commented on code in PR #259:
URL: https://github.com/apache/iceberg-rust/pull/259#discussion_r1524244075


##########
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:
   Thanks @Xuanwo 
   I think the idea was to be consistent with the [Python API](https://py.iceberg.apache.org/reference/pyiceberg/table/#pyiceberg.table.StaticTable) that uses StaticTable for this functionality. I'm also OK with ReadOnlyTable



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat (static table): implement a read-only table struct loaded from metadata [iceberg-rust]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org