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


##########
crates/paimon/src/spec/types.rs:
##########
@@ -0,0 +1,1035 @@
+// 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::{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, Copy, 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, Copy, PartialEq, Eq, Deserialize, Serialize, Hash)]
+pub struct DataType {
+    is_nullable: bool,
+    type_root: DataTypeRoot,
+}
+
+impl Display for DataType {
+    fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
+        todo!()
+    }
+}
+
+impl FromStr for DataType {
+    type Err = Error;
+
+    fn from_str(_: &str) -> Result<Self, Self::Err> {
+        todo!()
+    }
+}
+
+#[allow(dead_code)]
+impl DataType {
+    fn new(is_nullable: bool, type_root: DataTypeRoot) -> Self {
+        Self {
+            is_nullable,
+            type_root,
+        }
+    }
+
+    /// Returns true if the data type is nullable.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L59>
+    fn is_nullable(&self) -> bool {
+        self.is_nullable
+    }
+
+    /// Returns the root of the data type.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L66>
+    fn type_root(&self) -> &DataTypeRoot {
+        &self.type_root
+    }
+
+    /// Returns whether the root of the type equals to the type_root or not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L75>
+    fn is(&self, type_root: &DataTypeRoot) -> bool {
+        &self.type_root == type_root
+    }
+
+    /// Returns whether the family type of the type equals to the family or 
not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L103>
+    fn with_family(&self, family: DataTypeFamily) -> bool {

Review Comment:
   How about naming it `is_family`?



##########
crates/paimon/src/spec/types.rs:
##########
@@ -0,0 +1,1035 @@
+// 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::{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, Copy, 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, Copy, PartialEq, Eq, Deserialize, Serialize, Hash)]
+pub struct DataType {
+    is_nullable: bool,
+    type_root: DataTypeRoot,
+}
+
+impl Display for DataType {
+    fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
+        todo!()
+    }
+}
+
+impl FromStr for DataType {
+    type Err = Error;
+
+    fn from_str(_: &str) -> Result<Self, Self::Err> {
+        todo!()
+    }
+}
+
+#[allow(dead_code)]
+impl DataType {
+    fn new(is_nullable: bool, type_root: DataTypeRoot) -> Self {
+        Self {
+            is_nullable,
+            type_root,
+        }
+    }
+
+    /// Returns true if the data type is nullable.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L59>
+    fn is_nullable(&self) -> bool {
+        self.is_nullable
+    }
+
+    /// Returns the root of the data type.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L66>
+    fn type_root(&self) -> &DataTypeRoot {
+        &self.type_root
+    }
+
+    /// Returns whether the root of the type equals to the type_root or not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L75>
+    fn is(&self, type_root: &DataTypeRoot) -> bool {
+        &self.type_root == type_root
+    }
+
+    /// Returns whether the family type of the type equals to the family or 
not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L103>
+    fn with_family(&self, family: DataTypeFamily) -> bool {
+        self.type_root.families().contains(family)
+    }
+
+    /// Returns whether the root of the type equals to at least on of the 
type_roots or not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L84>
+    fn is_any_of(&self, type_roots: &[DataTypeRoot]) -> bool {
+        type_roots.iter().any(|tr: &DataTypeRoot| self.is(tr))
+    }
+
+    /// Returns whether the root of the type is part of at least one family of 
the families or not.
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L94>
+    fn is_any_with_family(&self, families: &[DataTypeFamily]) -> bool {
+        families
+            .iter()
+            .any(|f: &DataTypeFamily| self.with_family(f.clone()))

Review Comment:
   `DataTypeFamily` is Copy, so I'm guessing we don't need to clone it.
   
   Have you tried:
   
   ```rust
   families
       .iter()
       .any(self.is_family)
   ```



##########
crates/paimon/src/spec/types.rs:
##########
@@ -0,0 +1,1035 @@
+// 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::{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, Copy, 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, Copy, PartialEq, Eq, Deserialize, Serialize, Hash)]
+pub struct DataType {
+    is_nullable: bool,
+    type_root: DataTypeRoot,
+}
+
+impl Display for DataType {
+    fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
+        todo!()
+    }
+}
+
+impl FromStr for DataType {
+    type Err = Error;
+
+    fn from_str(_: &str) -> Result<Self, Self::Err> {
+        todo!()
+    }
+}
+
+#[allow(dead_code)]
+impl DataType {
+    fn new(is_nullable: bool, type_root: DataTypeRoot) -> Self {
+        Self {
+            is_nullable,
+            type_root,
+        }
+    }
+
+    /// Returns true if the data type is nullable.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L59>
+    fn is_nullable(&self) -> bool {
+        self.is_nullable
+    }
+
+    /// Returns the root of the data type.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L66>
+    fn type_root(&self) -> &DataTypeRoot {
+        &self.type_root
+    }
+
+    /// Returns whether the root of the type equals to the type_root or not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L75>
+    fn is(&self, type_root: &DataTypeRoot) -> bool {
+        &self.type_root == type_root
+    }
+
+    /// Returns whether the family type of the type equals to the family or 
not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L103>
+    fn with_family(&self, family: DataTypeFamily) -> bool {
+        self.type_root.families().contains(family)
+    }
+
+    /// Returns whether the root of the type equals to at least on of the 
type_roots or not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L84>
+    fn is_any_of(&self, type_roots: &[DataTypeRoot]) -> bool {
+        type_roots.iter().any(|tr: &DataTypeRoot| self.is(tr))
+    }
+
+    /// Returns whether the root of the type is part of at least one family of 
the families or not.
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L94>
+    fn is_any_with_family(&self, families: &[DataTypeFamily]) -> bool {

Review Comment:
   How about naming it `is_any_of_family` to align with `is_any_of`?



##########
crates/paimon/src/spec/types.rs:
##########
@@ -0,0 +1,1035 @@
+// 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::{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, Copy, 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, Copy, PartialEq, Eq, Deserialize, Serialize, Hash)]
+pub struct DataType {
+    is_nullable: bool,
+    type_root: DataTypeRoot,
+}
+
+impl Display for DataType {
+    fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
+        todo!()
+    }
+}
+
+impl FromStr for DataType {
+    type Err = Error;
+
+    fn from_str(_: &str) -> Result<Self, Self::Err> {
+        todo!()
+    }
+}
+
+#[allow(dead_code)]
+impl DataType {
+    fn new(is_nullable: bool, type_root: DataTypeRoot) -> Self {
+        Self {
+            is_nullable,
+            type_root,
+        }
+    }
+
+    /// Returns true if the data type is nullable.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L59>
+    fn is_nullable(&self) -> bool {
+        self.is_nullable
+    }
+
+    /// Returns the root of the data type.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L66>
+    fn type_root(&self) -> &DataTypeRoot {
+        &self.type_root
+    }
+
+    /// Returns whether the root of the type equals to the type_root or not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L75>
+    fn is(&self, type_root: &DataTypeRoot) -> bool {
+        &self.type_root == type_root
+    }
+
+    /// Returns whether the family type of the type equals to the family or 
not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L103>
+    fn with_family(&self, family: DataTypeFamily) -> bool {
+        self.type_root.families().contains(family)
+    }
+
+    /// Returns whether the root of the type equals to at least on of the 
type_roots or not.
+    ///
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L84>
+    fn is_any_of(&self, type_roots: &[DataTypeRoot]) -> bool {
+        type_roots.iter().any(|tr: &DataTypeRoot| self.is(tr))
+    }
+
+    /// Returns whether the root of the type is part of at least one family of 
the families or not.
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L94>
+    fn is_any_with_family(&self, families: &[DataTypeFamily]) -> bool {
+        families
+            .iter()
+            .any(|f: &DataTypeFamily| self.with_family(f.clone()))
+    }
+
+    /// Returns a deep copy of this type with possibly different nullability.
+    /// Impl Reference: 
<https://github.com/apache/paimon/blob/db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5/paimon-common/src/main/java/org/apache/paimon/types/DataType.java#L113>
+    fn with_nullable(&self, is_nullable: bool) -> Self {

Review Comment:
   We can place construct API in the front to make it easier to find.



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