Xuanwo commented on code in PR #863:
URL: https://github.com/apache/iceberg-rust/pull/863#discussion_r1900592922


##########
crates/iceberg/src/metadata_table.rs:
##########
@@ -0,0 +1,1031 @@
+// 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.
+
+//! Metadata table api.
+
+use std::collections::HashMap;
+use std::sync::Arc;
+
+use arrow_array::builder::{
+    make_builder, ArrayBuilder, BinaryBuilder, BooleanBuilder, Date32Builder, 
Decimal128Builder,
+    FixedSizeBinaryBuilder, Float32Builder, Float64Builder, 
GenericBinaryBuilder, Int32Builder,
+    Int64Builder, Int8Builder, LargeBinaryBuilder, ListBuilder, MapBuilder, 
PrimitiveBuilder,
+    StringBuilder, Time64MicrosecondBuilder, TimestampMicrosecondBuilder,
+    TimestampNanosecondBuilder,
+};
+use arrow_array::cast::AsArray;
+use arrow_array::types::{
+    Date32Type, Decimal128Type, Float32Type, Float64Type, Int32Type, Int64Type,
+    Time64MicrosecondType, TimestampMicrosecondType, TimestampMillisecondType,
+    TimestampNanosecondType, UInt64Type,
+};
+use arrow_array::{
+    ArrayRef, ArrowPrimitiveType, Datum as ArrowDatum, OffsetSizeTrait, 
RecordBatch, StructArray,
+};
+use arrow_schema::{DataType, Field, FieldRef, Fields, Schema, TimeUnit};
+use itertools::Itertools;
+use ordered_float::OrderedFloat;
+
+use crate::arrow::{get_arrow_datum, schema_to_arrow_schema, 
type_to_arrow_type};
+use crate::io::FileIO;
+use crate::spec::{
+    DataFile, Datum, Literal, ManifestFile, PartitionField, PartitionSpec, 
PrimitiveLiteral,
+    SchemaRef, Struct, TableMetadata,
+};
+use crate::table::Table;
+use crate::{Error, ErrorKind, Result};
+
+/// Metadata table is used to inspect a table's history, snapshots, and other 
metadata as a table.
+///
+/// References:
+/// - 
<https://github.com/apache/iceberg/blob/ac865e334e143dfd9e33011d8cf710b46d91f1e5/core/src/main/java/org/apache/iceberg/MetadataTableType.java#L23-L39>
+/// - <https://iceberg.apache.org/docs/latest/spark-queries/#querying-with-sql>
+/// - <https://py.iceberg.apache.org/api/#inspecting-tables>
+#[derive(Debug)]
+pub struct MetadataTable<'a>(&'a Table);
+
+impl<'a> MetadataTable<'a> {
+    /// Creates a new metadata scan.
+    pub(super) fn new(table: &'a Table) -> Self {
+        Self(table)
+    }
+
+    /// Get the snapshots table.
+    pub fn snapshots(&self) -> SnapshotsTable {
+        SnapshotsTable {
+            metadata_table: self,
+        }
+    }
+
+    /// Returns the current manifest file's entries.
+    pub fn entries(&self) -> EntriesTable {
+        EntriesTable {
+            metadata_table: self,
+        }
+    }
+
+    fn metadata(&self) -> &TableMetadata {
+        self.0.metadata()
+    }
+
+    fn file_io(&self) -> &FileIO {
+        self.0.file_io()
+    }
+}
+
+/// Snapshots table.
+pub struct SnapshotsTable<'a> {

Review Comment:
   Hi, I think we can simply hold a `Table` here, allowing us to remove the 
duplicate APIs exposed at the `MetadataTable` level and make it a 
straightforward wrapper instead.



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