You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by lz...@apache.org on 2024/07/09 03:26:04 UTC

(paimon-rust) branch main updated: feat(spec): Add Snapshot (#11)

This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 975b1aa  feat(spec): Add Snapshot (#11)
975b1aa is described below

commit 975b1aa4e8b99e9f443e054364659cbfc06acb7f
Author: ErXi <45...@users.noreply.github.com>
AuthorDate: Tue Jul 9 11:26:00 2024 +0800

    feat(spec): Add Snapshot (#11)
---
 .gitignore                         |   4 ++
 crates/paimon/Cargo.toml           |   1 +
 crates/paimon/src/spec/mod.rs      |   1 +
 crates/paimon/src/spec/snapshot.rs | 137 +++++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+)

diff --git a/.gitignore b/.gitignore
index 68549d4..25b8032 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,7 @@
 
 /target
 /Cargo.lock
+.idea
+.vscode
+**/.DS_Store
+dist/*
diff --git a/crates/paimon/Cargo.toml b/crates/paimon/Cargo.toml
index 0d48b77..aae592d 100644
--- a/crates/paimon/Cargo.toml
+++ b/crates/paimon/Cargo.toml
@@ -30,3 +30,4 @@ version.workspace = true
 serde = { version = "1", features = ["derive"] }
 serde_with = "3.8.3"
 snafu = "0.8.3"
+typed-builder = "^0.18"
diff --git a/crates/paimon/src/spec/mod.rs b/crates/paimon/src/spec/mod.rs
index d38d407..c626af4 100644
--- a/crates/paimon/src/spec/mod.rs
+++ b/crates/paimon/src/spec/mod.rs
@@ -20,3 +20,4 @@
 //! All paimon specs types are defined here.
 
 mod schema;
+mod snapshot;
diff --git a/crates/paimon/src/spec/snapshot.rs b/crates/paimon/src/spec/snapshot.rs
new file mode 100644
index 0000000..53b9583
--- /dev/null
+++ b/crates/paimon/src/spec/snapshot.rs
@@ -0,0 +1,137 @@
+// 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.
+
+use serde::{Deserialize, Serialize};
+use typed_builder::TypedBuilder;
+
+/// Snapshot for paimon.
+///
+/// Impl Reference: <https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-core/src/main/java/org/apache/paimon/Snapshot.java#L68>.
+#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, TypedBuilder)]
+#[serde(rename_all = "camelCase")]
+pub struct Snapshot {
+    /// version of snapshot
+    version: i32,
+    id: i64,
+    schema_id: i64,
+    /// a manifest list recording all changes from the previous snapshots
+    base_manifest_list: String,
+    /// a manifest list recording all new changes occurred in this snapshot
+    delta_manifest_list: String,
+    /// a manifest list recording all changelog produced in this snapshot
+    #[builder(default = None)]
+    changelog_manifest_list: Option<String>,
+    /// a manifest recording all index files of this table
+    #[builder(default = None)]
+    index_manifest: Option<String>,
+    commit_user: String,
+    /// record count of all changes occurred in this snapshot
+    #[builder(default = None)]
+    total_record_count: Option<i64>,
+    /// record count of all new changes occurred in this snapshot
+    #[builder(default = None)]
+    delta_record_count: Option<i64>,
+    /// record count of all changelog produced in this snapshot
+    #[builder(default = None)]
+    changelog_record_count: Option<i64>,
+    /// watermark for input records
+    #[builder(default = None)]
+    watermark: Option<i64>,
+    /// stats file name for statistics of this table
+    #[builder(default = None)]
+    statistics: Option<String>,
+}
+
+impl Snapshot {
+    /// Get the version of this snapshot.
+    #[inline]
+    pub fn version(&self) -> i32 {
+        self.version
+    }
+
+    /// Get the id of this snapshot.
+    #[inline]
+    pub fn id(&self) -> i64 {
+        self.id
+    }
+
+    /// Get the schema id of this snapshot.
+    #[inline]
+    pub fn schema_id(&self) -> i64 {
+        self.schema_id
+    }
+
+    /// Get the base manifest list of this snapshot.
+    #[inline]
+    pub fn base_manifest_list(&self) -> &str {
+        &self.base_manifest_list
+    }
+
+    /// Get the delta manifest list of this snapshot.
+    #[inline]
+    pub fn delta_manifest_list(&self) -> &str {
+        &self.delta_manifest_list
+    }
+
+    /// Get the changelog manifest list of this snapshot.
+    #[inline]
+    pub fn changelog_manifest_list(&self) -> Option<&str> {
+        self.changelog_manifest_list.as_deref()
+    }
+
+    /// Get the index manifest of this snapshot.
+    #[inline]
+    pub fn index_manifest(&self) -> Option<&str> {
+        self.index_manifest.as_deref()
+    }
+
+    /// Get the commit user of this snapshot.
+    #[inline]
+    pub fn commit_user(&self) -> &str {
+        &self.commit_user
+    }
+
+    /// Get the total record count of this snapshot.
+    #[inline]
+    pub fn total_record_count(&self) -> Option<i64> {
+        self.total_record_count
+    }
+
+    /// Get the delta record count of this snapshot.
+    #[inline]
+    pub fn delta_record_count(&self) -> Option<i64> {
+        self.delta_record_count
+    }
+
+    /// Get the changelog record count of this snapshot.
+    #[inline]
+    pub fn changelog_record_count(&self) -> Option<i64> {
+        self.changelog_record_count
+    }
+
+    /// Get the watermark of this snapshot.
+    #[inline]
+    pub fn watermark(&self) -> Option<i64> {
+        self.watermark
+    }
+
+    /// Get the statistics of this snapshot.
+    #[inline]
+    pub fn statistics(&self) -> Option<&str> {
+        self.statistics.as_deref()
+    }
+}