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