Skip to content

Commit

Permalink
feat(spec): Add schema types (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuanwo authored Jul 8, 2024
1 parent 36ea378 commit 6777f09
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 17 deletions.
21 changes: 12 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
# specific language governing permissions and limitations
# under the License.

[package]
categories = ["command-line-utilities"]
description = "The rust implementation of paimon"
documentation = "https://docs.rs/paimon"
repository = "https://github.com/apache/paimon-rust"
edition = "2021"
license = "Apache-2.0"
name = "paimon"
[workspace]
resolver = "2"
members = [
"crates/paimon",
]

[workspace.package]
version = "0.0.0"
edition = "2021"
homepage = "https://paimon.apache.org/"

[dependencies]
repository = "https://github.com/apache/paimon-rust"
license = "Apache-2.0"
rust-version = "1.77.1"
31 changes: 31 additions & 0 deletions crates/paimon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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.

[package]
categories = ["command-line-utilities"]
description = "The rust implementation of paimon"
documentation = "https://docs.rs/paimon"
repository = "https://github.com/apache/paimon-rust"
edition = "2021"
license = "Apache-2.0"
name = "paimon"
version = "0.0.0"

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_with = "3.8.3"
snafu = "0.8.3"
30 changes: 30 additions & 0 deletions crates/paimon/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 snafu::Snafu;

/// Error type for paimon.
#[allow(dead_code)]
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("paimon data invalid for {}: {:?}", message, source))]
DataInvalid {
message: String,
#[snafu(backtrace)]
source: snafu::Whatever,
},
}
10 changes: 2 additions & 8 deletions src/lib.rs → crates/paimon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,5 @@
// specific language governing permissions and limitations
// under the License.

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
mod error;
pub mod spec;
22 changes: 22 additions & 0 deletions crates/paimon/src/spec/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

//! Spec module for paimon.
//!
//! All paimon specs types are defined here.

mod schema;
84 changes: 84 additions & 0 deletions crates/paimon/src/spec/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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::error::Error;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::str::FromStr;

/// The table schema for paimon table.
///
/// Impl References: <https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-core/src/main/java/org/apache/paimon/schema/TableSchema.java#L47>
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TableSchema {
/// version of schema for paimon
version: i32,
id: i64,
fields: Vec<DataField>,
highest_field_id: i32,
partition_keys: Vec<String>,
primary_keys: Vec<String>,
options: HashMap<String, String>,
comment: Option<String>,
time_millis: i64,
}

/// Data field for paimon table.
///
/// Impl Reference: <https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataField.java#L40>
#[serde_as]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DataField {
id: i32,
name: String,
#[serde(rename = "type")]
#[serde_as(as = "DisplayFromStr")]
typ: DataType,
description: Option<String>,
}

/// Data type for paimon table.
///
/// Impl Reference: <https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L45>
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DataType {
is_nullable: bool,
type_root: DataTypeRoot,
}

impl Display for DataType {
fn fmt(&self, _: &mut Formatter<'_>) -> std::fmt::Result {
todo!()
}
}

impl FromStr for DataType {
type Err = Error;

fn from_str(_: &str) -> Result<Self, Self::Err> {
todo!()
}
}

/// The root of data type.
///
/// Impl Reference: <https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataTypeRoot.java#L49>
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DataTypeRoot {}

0 comments on commit 6777f09

Please sign in to comment.