-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spec): Impl the ManifestFile read functionality
- Loading branch information
Showing
9 changed files
with
524 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// 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 crate::spec::DataFileMeta; | ||
use serde::Deserialize; | ||
use serde_repr::{Deserialize_repr, Serialize_repr}; | ||
use serde_with::serde_derive::Serialize; | ||
|
||
/// Entry representing a file. | ||
/// | ||
/// Impl Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/manifest/FileEntry.java> | ||
#[allow(dead_code)] | ||
pub trait FileEntry { | ||
fn kind(&self) -> &FileKind; | ||
|
||
fn partition(&self) -> &Vec<u8>; | ||
|
||
fn bucket(&self) -> i32; | ||
|
||
fn level(&self) -> i32; | ||
|
||
fn file_name(&self) -> &str; | ||
|
||
fn min_key(&self) -> &Vec<u8>; | ||
|
||
fn max_key(&self) -> &Vec<u8>; | ||
|
||
fn identifier(&self) -> Identifier; | ||
} | ||
|
||
/// The same {@link Identifier} indicates that the {@link ManifestEntry} refers to the same data file. | ||
/// | ||
/// Impl Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/manifest/FileEntry.java#L58> | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct Identifier { | ||
pub partition: Vec<u8>, | ||
pub bucket: i32, | ||
pub level: i32, | ||
pub file_name: String, | ||
} | ||
/// Kind of a file. | ||
/// Impl Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/manifest/FileKind.java> | ||
#[derive(PartialEq, Eq, Debug, Clone, Serialize_repr, Deserialize_repr)] | ||
#[repr(u8)] | ||
pub enum FileKind { | ||
Add = 0, | ||
Delete = 1, | ||
} | ||
|
||
/// Entry of a manifest file, representing an addition / deletion of a data file. | ||
/// Impl Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/manifest/ManifestEntry.java> | ||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct ManifestEntry { | ||
#[serde(rename = "_KIND")] | ||
kind: FileKind, | ||
|
||
#[serde(rename = "_PARTITION", with = "serde_bytes")] | ||
partition: Vec<u8>, | ||
|
||
#[serde(rename = "_BUCKET")] | ||
bucket: i32, | ||
|
||
#[serde(rename = "_TOTAL_BUCKETS")] | ||
total_buckets: i32, | ||
|
||
#[serde(rename = "_FILE")] | ||
file: DataFileMeta, | ||
|
||
#[serde(rename = "_VERSION")] | ||
version: i32, | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl FileEntry for ManifestEntry { | ||
fn kind(&self) -> &FileKind { | ||
&self.kind | ||
} | ||
|
||
fn partition(&self) -> &Vec<u8> { | ||
&self.partition | ||
} | ||
|
||
fn bucket(&self) -> i32 { | ||
self.bucket | ||
} | ||
|
||
fn level(&self) -> i32 { | ||
self.file.level | ||
} | ||
|
||
fn file_name(&self) -> &str { | ||
&self.file.file_name | ||
} | ||
|
||
fn min_key(&self) -> &Vec<u8> { | ||
&self.file.min_key | ||
} | ||
|
||
fn max_key(&self) -> &Vec<u8> { | ||
&self.file.max_key | ||
} | ||
|
||
fn identifier(&self) -> Identifier { | ||
Identifier { | ||
partition: self.partition.clone(), | ||
bucket: self.bucket, | ||
level: self.file.level, | ||
file_name: self.file.file_name.clone(), | ||
} | ||
} | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl ManifestEntry { | ||
pub fn total_buckets(&self) -> i32 { | ||
self.total_buckets | ||
} | ||
|
||
pub fn file(&self) -> &DataFileMeta { | ||
&self.file | ||
} | ||
|
||
pub fn new( | ||
kind: FileKind, | ||
partition: Vec<u8>, | ||
bucket: i32, | ||
total_buckets: i32, | ||
file: DataFileMeta, | ||
version: i32, | ||
) -> Self { | ||
ManifestEntry { | ||
kind, | ||
partition, | ||
bucket, | ||
total_buckets, | ||
file, | ||
version, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.