Skip to main content

DataType

Enum DataType 

Source
pub enum DataType {
Show 20 variants Boolean, SmallInt, Integer, BigInt, Float, Double, Decimal { precision: u8, scale: u8, }, Varchar { max_length: Option<u32>, }, Char { length: u32, }, Text, Blob, Date, Time, Timestamp { with_timezone: bool, }, Interval, Array(Box<DataType>), Struct(Vec<(String, DataType)>), Map(Box<DataType>, Box<DataType>), Null, Unknown,
}
Expand description

SQL data types supported by smelt

This enum represents the logical SQL types. Backend-specific variations (e.g., DuckDB’s HUGEINT) are mapped to these canonical types.

Variants§

§

Boolean

Boolean (TRUE/FALSE)

§

SmallInt

Small integer (2 bytes, -32768 to 32767)

§

Integer

Integer (4 bytes)

§

BigInt

Big integer (8 bytes)

§

Float

Single-precision floating point

§

Double

Double-precision floating point

§

Decimal

Exact decimal with precision and scale

Fields

§precision: u8
§scale: u8
§

Varchar

Variable-length string with optional max length

Fields

§max_length: Option<u32>
§

Char

Fixed-length string

Fields

§length: u32
§

Text

Unbounded text

§

Blob

Binary large object

§

Date

Calendar date (year, month, day)

§

Time

Time of day

§

Timestamp

Timestamp (date + time)

Fields

§with_timezone: bool
§

Interval

Time interval

§

Array(Box<DataType>)

Array of elements

§

Struct(Vec<(String, DataType)>)

Struct with named fields: STRUCT(a INTEGER, b VARCHAR)

§

Map(Box<DataType>, Box<DataType>)

Map from key type to value type: MAP(VARCHAR, INTEGER)

§

Null

NULL literal type

§

Unknown

Type could not be determined (error recovery)

Implementations§

Source§

impl DataType

Source

pub fn is_numeric(&self) -> bool

Check if this type is numeric (supports arithmetic operations)

Source

pub fn is_string(&self) -> bool

Check if this type is a string type

Source

pub fn is_complex(&self) -> bool

Check if this type is a complex/nested type (Array, Struct, Map)

Source

pub fn is_temporal(&self) -> bool

Check if this type is a date/time type

Source

pub fn normalize(&self) -> DataType

Normalize this type to its canonical form for comparison.

  • TextVarchar { max_length: None } (canonical string type)
  • Recursively normalizes Array elements, Struct fields, Map key/value
  • All other types are returned as-is
Source

pub fn to_backend_sql(&self) -> String

Format as SQL type string for backend compilation.

Translates smelt-internal types to what backends actually support:

  • Text"VARCHAR" (backends don’t distinguish Text from VARCHAR)
Source

pub fn to_sql(&self) -> String

Format as SQL type string for the default dialect

Trait Implementations§

Source§

impl Clone for DataType

Source§

fn clone(&self) -> DataType

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 DataType

Source§

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

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

impl Display for DataType

Source§

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

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

impl Hash for DataType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DataType

Source§

fn eq(&self, other: &DataType) -> 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 DataType

Source§

impl StructuralPartialEq for DataType

Auto Trait Implementations§

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, 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.