Skip to main content

Type

Enum Type 

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

Fields

§size: usize

Length of the fixed string in bytes.

§

DateTime

Date and time with optional timezone.

Fields

§timezone: Option<String>

Optional IANA timezone name (e.g. “UTC”, “Europe/Moscow”).

§

DateTime64

High-precision date and time with sub-second precision and optional timezone.

Fields

§precision: usize

Number of sub-second decimal digits (0 to 18).

§timezone: Option<String>

Optional IANA timezone name.

§

Decimal

Arbitrary-precision decimal with given precision and scale.

Fields

§precision: usize

Total number of significant digits.

§scale: usize

Number of digits after the decimal point.

§

Enum8

Enum with Int8 storage, containing named integer variants.

Fields

§items: Vec<EnumItem>

The named variants with their integer values.

§

Enum16

Enum with Int16 storage, containing named integer variants.

Fields

§items: Vec<EnumItem>

The named variants with their integer values.

§

Array

Variable-length array of the given element type.

Fields

§item_type: Box<Type>

The type of each element in the array.

§

Nullable

Nullable wrapper around the given nested type.

Fields

§nested_type: Box<Type>

The type that is made nullable.

§

Tuple

Fixed-size tuple of heterogeneous element types.

Fields

§item_types: Vec<Type>

The ordered list of element types in the tuple.

§

LowCardinality

Dictionary-encoded wrapper around the given nested type.

Fields

§nested_type: Box<Type>

The type that is dictionary-encoded.

§

Map

Key-value map with typed keys and values.

Fields

§key_type: Box<Type>

The type of map keys.

§value_type: Box<Type>

The type of map values.

Implementations§

Source§

impl Type

Source

pub fn code(&self) -> TypeCode

Returns the TypeCode for this type.

Source

pub fn name(&self) -> String

Returns the full ClickHouse type name string, including parameters.

Source

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

pub fn int8() -> Self

Creates an Int8 type.

Source

pub fn int16() -> Self

Creates an Int16 type.

Source

pub fn int32() -> Self

Creates an Int32 type.

Source

pub fn int64() -> Self

Creates an Int64 type.

Source

pub fn int128() -> Self

Creates an Int128 type.

Source

pub fn uint8() -> Self

Creates a UInt8 type.

Source

pub fn uint16() -> Self

Creates a UInt16 type.

Source

pub fn uint32() -> Self

Creates a UInt32 type.

Source

pub fn uint64() -> Self

Creates a UInt64 type.

Source

pub fn uint128() -> Self

Creates a UInt128 type.

Source

pub fn float32() -> Self

Creates a Float32 type.

Source

pub fn float64() -> Self

Creates a Float64 type.

Source

pub fn string() -> Self

Creates a variable-length String type.

Source

pub fn fixed_string(size: usize) -> Self

Creates a FixedString type with the given size in bytes.

Source

pub fn date() -> Self

Creates a Date type (days since 1970-01-01, stored as UInt16).

Source

pub fn date32() -> Self

Creates a Date32 type (days since 1970-01-01, stored as Int32).

Source

pub fn datetime(timezone: Option<String>) -> Self

Creates a DateTime type with an optional timezone.

Source

pub fn datetime64(precision: usize, timezone: Option<String>) -> Self

Creates a DateTime64 type with the given sub-second precision and optional timezone.

Source

pub fn decimal(precision: usize, scale: usize) -> Self

Creates a Decimal type with the given precision and scale.

Source

pub fn ipv4() -> Self

Creates an IPv4 address type.

Source

pub fn ipv6() -> Self

Creates an IPv6 address type.

Source

pub fn uuid() -> Self

Creates a UUID type.

Source

pub fn array(item_type: Type) -> Self

Creates an Array type with the given element type.

Source

pub fn nullable(nested_type: Type) -> Self

Creates a Nullable wrapper around the given type.

Source

pub fn tuple(item_types: Vec<Type>) -> Self

Creates a Tuple type with the given element types.

Source

pub fn enum8(items: Vec<EnumItem>) -> Self

Creates an Enum8 type with the given name-value items.

Source

pub fn enum16(items: Vec<EnumItem>) -> Self

Creates an Enum16 type with the given name-value items.

Source

pub fn low_cardinality(nested_type: Type) -> Self

Creates a LowCardinality wrapper around the given type.

Source

pub fn map(key_type: Type, value_type: Type) -> Self

Creates a Map type with the given key and value types.

Source

pub fn has_enum_value(&self, value: i16) -> bool

Returns true if this enum type contains a variant with the given integer value.

Source

pub fn has_enum_name(&self, name: &str) -> bool

Returns true if this enum type contains a variant with the given name.

Source

pub fn get_enum_name(&self, value: i16) -> Option<&str>

Returns the enum variant name for the given integer value, if it exists.

Source

pub fn get_enum_value(&self, name: &str) -> Option<i16>

Returns the integer value for the given enum variant name, if it exists.

Source

pub fn enum_items(&self) -> Option<&[EnumItem]>

Returns the enum items slice if this is an Enum8 or Enum16 type, or None otherwise.

Source

pub fn point() -> Self

Creates a Point geo type (Tuple(Float64, Float64)).

Source

pub fn ring() -> Self

Creates a Ring geo type (Array(Point)).

Source

pub fn polygon() -> Self

Creates a Polygon geo type (Array(Ring)).

Source

pub fn multi_polygon() -> Self

Creates a MultiPolygon geo type (Array(Polygon)).

Source

pub fn nothing() -> Self

Creates a Nothing/Void type, used for NULL-only columns.

Source

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());
Source

pub fn from_ast(ast: &TypeAst) -> Result<Self>

Convert TypeAst to Type Mirrors C++ CreateColumnFromAst logic

Source

pub fn parse(type_str: &str) -> Result<Self>

Parse a type from its string representation

Uses token-based parser with AST caching for performance

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Type

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Type

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Type

Auto Trait Implementations§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more