pub enum Type {
Simple(TypeCode),
FixedString {
size: usize,
},
DateTime {
timezone: Option<String>,
},
DateTime64 {
precision: usize,
timezone: Option<String>,
},
Decimal {
precision: usize,
scale: usize,
},
Enum8 {
items: Vec<EnumItem>,
},
Enum16 {
items: Vec<EnumItem>,
},
Array {
item_type: Box<Type>,
},
Nullable {
nested_type: Box<Type>,
},
Tuple {
item_types: Vec<Type>,
},
LowCardinality {
nested_type: Box<Type>,
},
Map {
key_type: Box<Type>,
value_type: Box<Type>,
},
}Expand description
ClickHouse type definition, representing both simple and parametric types.
Variants§
Simple(TypeCode)
A non-parametric type identified by its TypeCode.
FixedString
Fixed-length byte string with the given size in bytes.
DateTime
Date and time with optional timezone.
DateTime64
High-precision date and time with sub-second precision and optional timezone.
Fields
Decimal
Arbitrary-precision decimal with given precision and scale.
Fields
Enum8
Enum with Int8 storage, containing named integer variants.
Enum16
Enum with Int16 storage, containing named integer variants.
Array
Variable-length array of the given element type.
Nullable
Nullable wrapper around the given nested type.
Tuple
Fixed-size tuple of heterogeneous element types.
LowCardinality
Dictionary-encoded wrapper around the given nested type.
Map
Key-value map with typed keys and values.
Implementations§
Source§impl Type
impl Type
Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
Returns the full ClickHouse type name string, including parameters.
Sourcepub fn storage_size_bytes(&self) -> Option<usize>
pub fn storage_size_bytes(&self) -> Option<usize>
Returns the storage size in bytes for fixed-size types
This is used for calculating buffer sizes when reading/writing
uncompressed column data. Returns None for variable-length types.
§Examples
use clickhouse_native_client::types::Type;
assert_eq!(Type::uint32().storage_size_bytes(), Some(4));
assert_eq!(Type::uint64().storage_size_bytes(), Some(8));
assert_eq!(Type::fixed_string(10).storage_size_bytes(), Some(10));
assert_eq!(Type::string().storage_size_bytes(), None); // Variable lengthSourcepub fn fixed_string(size: usize) -> Self
pub fn fixed_string(size: usize) -> Self
Creates a FixedString type with the given size in bytes.
Sourcepub fn datetime(timezone: Option<String>) -> Self
pub fn datetime(timezone: Option<String>) -> Self
Creates a DateTime type with an optional timezone.
Sourcepub fn datetime64(precision: usize, timezone: Option<String>) -> Self
pub fn datetime64(precision: usize, timezone: Option<String>) -> Self
Creates a DateTime64 type with the given sub-second precision and optional timezone.
Sourcepub fn decimal(precision: usize, scale: usize) -> Self
pub fn decimal(precision: usize, scale: usize) -> Self
Creates a Decimal type with the given precision and scale.
Sourcepub fn enum8(items: Vec<EnumItem>) -> Self
pub fn enum8(items: Vec<EnumItem>) -> Self
Creates an Enum8 type with the given name-value items.
Sourcepub fn enum16(items: Vec<EnumItem>) -> Self
pub fn enum16(items: Vec<EnumItem>) -> Self
Creates an Enum16 type with the given name-value items.
Sourcepub fn low_cardinality(nested_type: Type) -> Self
pub fn low_cardinality(nested_type: Type) -> Self
Creates a LowCardinality wrapper around the given type.
Sourcepub fn map(key_type: Type, value_type: Type) -> Self
pub fn map(key_type: Type, value_type: Type) -> Self
Creates a Map type with the given key and value types.
Sourcepub fn has_enum_value(&self, value: i16) -> bool
pub fn has_enum_value(&self, value: i16) -> bool
Returns true if this enum type contains a variant with the given integer value.
Sourcepub fn has_enum_name(&self, name: &str) -> bool
pub fn has_enum_name(&self, name: &str) -> bool
Returns true if this enum type contains a variant with the given name.
Sourcepub fn get_enum_name(&self, value: i16) -> Option<&str>
pub fn get_enum_name(&self, value: i16) -> Option<&str>
Returns the enum variant name for the given integer value, if it exists.
Sourcepub fn get_enum_value(&self, name: &str) -> Option<i16>
pub fn get_enum_value(&self, name: &str) -> Option<i16>
Returns the integer value for the given enum variant name, if it exists.
Sourcepub fn enum_items(&self) -> Option<&[EnumItem]>
pub fn enum_items(&self) -> Option<&[EnumItem]>
Returns the enum items slice if this is an Enum8 or Enum16 type, or None otherwise.
Sourcepub fn multi_polygon() -> Self
pub fn multi_polygon() -> Self
Creates a MultiPolygon geo type (Array(Polygon)).
Sourcepub fn for_rust_type<T: ToType>() -> Self
pub fn for_rust_type<T: ToType>() -> Self
Create a Type from a Rust primitive type
Equivalent to C++ Type::CreateSimple<T>()
§Examples
use clickhouse_native_client::types::Type;
assert_eq!(Type::for_rust_type::<i32>(), Type::int32());
assert_eq!(Type::for_rust_type::<u64>(), Type::uint64());
assert_eq!(Type::for_rust_type::<f32>(), Type::float32());