c-thiel commented on code in PR #331:
URL: https://github.com/apache/iceberg-rust/pull/331#discussion_r1676795328


##########
crates/iceberg/src/spec/view_metadata.rs:
##########
@@ -0,0 +1,682 @@
+// 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.
+
+//! Defines the [view 
metadata](https://iceberg.apache.org/view-spec/#view-metadata).
+//! The main struct here is [ViewMetadata] which defines the data for a view.
+
+use serde::{Deserialize, Serialize};
+use serde_repr::{Deserialize_repr, Serialize_repr};
+use std::cmp::Ordering;
+use std::fmt::{Display, Formatter};
+use std::{collections::HashMap, sync::Arc};
+use uuid::Uuid;
+
+use super::{
+    view_version::{ViewVersion, ViewVersionRef},
+    SchemaId, SchemaRef,
+};
+use crate::catalog::ViewCreation;
+use crate::error::Result;
+
+use _serde::ViewMetadataEnum;
+
+use chrono::{DateTime, MappedLocalTime, TimeZone, Utc};
+
+/// Reference to [`ViewMetadata`].
+pub type ViewMetadataRef = Arc<ViewMetadata>;
+
+#[derive(Debug, PartialEq, Deserialize, Eq, Clone)]
+#[serde(try_from = "ViewMetadataEnum", into = "ViewMetadataEnum")]
+/// Fields for the version 1 of the view metadata.
+///
+/// We assume that this data structure is always valid, so we will panic when 
invalid error happens.
+/// We check the validity of this data structure when constructing.
+pub struct ViewMetadata {
+    /// Integer Version for the format.
+    pub(crate) format_version: ViewFormatVersion,
+    /// A UUID that identifies the view, generated when the view is created.
+    pub(crate) view_uuid: Uuid,
+    /// The view's base location; used to create metadata file locations
+    pub(crate) location: String,
+    /// ID of the current version of the view (version-id)
+    pub(crate) current_version_id: i64,
+    /// A list of known versions of the view
+    pub(crate) versions: HashMap<i64, ViewVersionRef>,
+    /// A list of version log entries with the timestamp and version-id for 
every
+    /// change to current-version-id
+    pub(crate) version_log: Vec<ViewVersionLog>,
+    /// A list of schemas, stored as objects with schema-id.
+    pub(crate) schemas: HashMap<i32, SchemaRef>,
+    /// A string to string map of view properties.
+    /// Properties are used for metadata such as comment and for settings that
+    /// affect view maintenance. This is not intended to be used for arbitrary 
metadata.
+    pub(crate) properties: HashMap<String, String>,
+}
+
+impl ViewMetadata {
+    /// Returns format version of this metadata.
+    #[inline]
+    pub fn format_version(&self) -> ViewFormatVersion {
+        self.format_version
+    }
+
+    /// Returns uuid of current view.
+    #[inline]
+    pub fn uuid(&self) -> Uuid {
+        self.view_uuid
+    }
+
+    /// Returns view location.
+    #[inline]
+    pub fn location(&self) -> &str {
+        self.location.as_str()
+    }
+
+    /// Returns the current version id.
+    #[inline]
+    pub fn current_version_id(&self) -> i64 {
+        self.current_version_id
+    }
+
+    /// Returns all view versions.
+    #[inline]
+    pub fn versions(&self) -> impl Iterator<Item = &ViewVersionRef> {
+        self.versions.values()
+    }
+
+    /// Lookup a view version by id.
+    #[inline]
+    pub fn version_by_id(&self, version_id: i64) -> Option<&ViewVersionRef> {
+        self.versions.get(&version_id)
+    }
+
+    /// Returns the current view version.
+    #[inline]
+    pub fn current_version(&self) -> &ViewVersionRef {
+        self.versions
+            .get(&self.current_version_id)
+            .expect("Current version id set, but not found in view versions")
+    }
+
+    /// Returns schemas
+    #[inline]
+    pub fn schemas_iter(&self) -> impl Iterator<Item = &SchemaRef> {
+        self.schemas.values()
+    }
+
+    /// Lookup schema by id.
+    #[inline]
+    pub fn schema_by_id(&self, schema_id: SchemaId) -> Option<&SchemaRef> {
+        self.schemas.get(&schema_id)
+    }
+
+    /// Get current schema
+    #[inline]
+    pub fn current_schema(&self) -> &SchemaRef {
+        let schema_id = self.current_version().schema_id();
+        self.schema_by_id(schema_id)
+            .expect("Current schema id set, but not found in view metadata")
+    }
+
+    /// Returns properties of the view.
+    #[inline]
+    pub fn properties(&self) -> &HashMap<String, String> {
+        &self.properties
+    }
+
+    /// Append view version to view
+    pub fn append_version(&mut self, view_version: ViewVersion) {
+        self.current_version_id = view_version.version_id();

Review Comment:
   Yes, you are right. Bad idea to implement this half-done.
   I am removing this function and handle it properly later in the full 
implementation of the builders.



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