Aitozi commented on code in PR #18:
URL: https://github.com/apache/paimon-rust/pull/18#discussion_r1687981583


##########
crates/paimon/src/spec/types.rs:
##########
@@ -0,0 +1,985 @@
+// 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 bitflags::bitflags;
+use serde::{Deserialize, Serialize};
+use std::fmt::{Arguments, Display, Formatter};
+use std::str::FromStr;
+
+bitflags! {
+/// An enumeration of Data type families for clustering {@link DataTypeRoot}s 
into categories.
+///
+/// Impl Reference: 
<https://github.com/apache/paimon/blob/master/paimon-common/src/main/java/org/apache/paimon/types/DataTypeFamily.java>
+#[derive(Debug, Clone, PartialEq, Eq)]
+    pub struct DataTypeFamily: u32 {
+        const PREDEFINED = 1 << 0;
+        const CONSTRUCTED = 1 << 1;
+        const CHARACTER_STRING = 1 << 2;
+        const BINARY_STRING = 1 << 3;
+        const NUMERIC = 1 << 4;
+        const INTEGER_NUMERIC = 1 << 5;
+        const EXACT_NUMERIC = 1 << 6;
+        const APPROXIMATE_NUMERIC = 1 << 7;
+        const DATETIME = 1 << 8;
+        const TIME = 1 << 9;
+        const TIMESTAMP = 1 << 10;
+        const COLLECTION = 1 << 11;
+        const EXTENSION = 1 << 12;
+    }
+}
+
+/// 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, Deserialize, Serialize, Hash)]
+pub enum DataTypeRoot {
+    Char,
+    Varchar,
+    Boolean,
+    Binary,
+    Varbinary,
+    Decimal,
+    Tinyint,
+    Smallint,
+    Integer,
+    Bigint,
+    Float,
+    Double,
+    Date,
+    TimeWithoutTimeZone,
+    TimestampWithoutTimeZone,
+    TimestampWithLocalTimeZone,
+    Array,
+    Multiset,
+    Map,
+    Row,
+}
+
+impl DataTypeRoot {
+    pub fn families(&self) -> DataTypeFamily {
+        match self {
+            Self::Char => DataTypeFamily::PREDEFINED | 
DataTypeFamily::CHARACTER_STRING,
+            Self::Varchar => DataTypeFamily::PREDEFINED | 
DataTypeFamily::CHARACTER_STRING,
+            Self::Boolean => DataTypeFamily::PREDEFINED,
+            Self::Binary => DataTypeFamily::PREDEFINED | 
DataTypeFamily::BINARY_STRING,
+            Self::Varbinary => DataTypeFamily::PREDEFINED | 
DataTypeFamily::BINARY_STRING,
+            Self::Decimal => {
+                DataTypeFamily::PREDEFINED | DataTypeFamily::NUMERIC | 
DataTypeFamily::EXACT_NUMERIC
+            }
+            Self::Tinyint => {
+                DataTypeFamily::PREDEFINED
+                    | DataTypeFamily::NUMERIC
+                    | DataTypeFamily::INTEGER_NUMERIC
+                    | DataTypeFamily::EXACT_NUMERIC
+            }
+            Self::Smallint => {
+                DataTypeFamily::PREDEFINED
+                    | DataTypeFamily::NUMERIC
+                    | DataTypeFamily::INTEGER_NUMERIC
+                    | DataTypeFamily::EXACT_NUMERIC
+            }
+            Self::Integer => {
+                DataTypeFamily::PREDEFINED
+                    | DataTypeFamily::NUMERIC
+                    | DataTypeFamily::INTEGER_NUMERIC
+                    | DataTypeFamily::EXACT_NUMERIC
+            }
+            Self::Bigint => {
+                DataTypeFamily::PREDEFINED
+                    | DataTypeFamily::NUMERIC
+                    | DataTypeFamily::INTEGER_NUMERIC
+                    | DataTypeFamily::EXACT_NUMERIC
+            }
+            Self::Float => {
+                DataTypeFamily::PREDEFINED
+                    | DataTypeFamily::NUMERIC
+                    | DataTypeFamily::APPROXIMATE_NUMERIC
+            }
+            Self::Double => {
+                DataTypeFamily::PREDEFINED
+                    | DataTypeFamily::NUMERIC
+                    | DataTypeFamily::APPROXIMATE_NUMERIC
+            }
+            Self::Date => DataTypeFamily::PREDEFINED | 
DataTypeFamily::DATETIME,
+            Self::TimeWithoutTimeZone => {
+                DataTypeFamily::PREDEFINED | DataTypeFamily::DATETIME | 
DataTypeFamily::TIME
+            }
+            Self::TimestampWithoutTimeZone => {
+                DataTypeFamily::PREDEFINED | DataTypeFamily::DATETIME | 
DataTypeFamily::TIMESTAMP
+            }
+            Self::TimestampWithLocalTimeZone => {
+                DataTypeFamily::PREDEFINED
+                    | DataTypeFamily::DATETIME
+                    | DataTypeFamily::TIMESTAMP
+                    | DataTypeFamily::EXTENSION
+            }
+            Self::Array => DataTypeFamily::CONSTRUCTED | 
DataTypeFamily::COLLECTION,
+            Self::Multiset => DataTypeFamily::CONSTRUCTED | 
DataTypeFamily::COLLECTION,
+            Self::Map => DataTypeFamily::CONSTRUCTED | 
DataTypeFamily::EXTENSION,
+            Self::Row => DataTypeFamily::CONSTRUCTED,
+        }
+    }
+}
+
+/// A visitor that can visit different data types.
+pub trait DataTypeVisitor<R> {
+    fn visit(&mut self, data_type: &DataType) -> R;
+}
+
+/// 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, Deserialize, Serialize, Hash)]
+pub struct DataType {
+    is_nullable: bool,
+    type_root: DataTypeRoot,
+}
+
+impl Display for DataType {

Review Comment:
   I think we should impl Display for the concrete types such as `BigIntType` 
not for the `DataType`?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to