pub enum DataType {
Show 18 variants Array(Box<DataType>), Bool, Date, Decimal, Float32, Float64, GeoJson(Srid), Int16, Int32, Int64, Json, Named(String), OneOf(Vec<String>), Struct(Vec<StructField>), Text, TimestampWithoutTimeZone, TimestampWithTimeZone, Uuid,
}
Expand description

The data type of a column.

This is a rather interesting type: It only exists to provide a reasonable set of “interchange” types, that we might want to preserve when moving from on database to another. So it’s less precise than PostgreSQL’s built-in types, but more precise than BigQuery’s built-in types. It exists to be a “happy medium”–every output driver should be able to understand every one of these types meaningfully, and it should almost always be able to map it to something in the local database.

Essentially, this fulfills a similar role to the standard JSON types (number, string, array, map, boolean, etc.). It’s an interchange format. It’s not supposed to cover every imaginable type. But it should at least cover common, generic types that make sense to many database backends.

We represent this as a Rust enum, and not a class hierarchy, because:

  1. Class hierarchies provide an extensible set of types (subclasses), but a closed set of operations (instance methods on the root class).
  2. Rust enums provide a closed set of types (enum variants), but an open set of operations (match statements matching each possible variant).

In this case, we will extend and change our set of operations regularly, as we add new input and output filters. But we will only change the possible data types after careful deliberation. So enum is the better choice here.

Variants§

§

Array(Box<DataType>)

An array of another data type. For many output formats, it may not be possible to nest arrays.

§

Bool

A boolean value.

§

Date

A date, with no associated time value.

§

Decimal

A decimal integer (can represent currency, etc., without rounding errors).

§

Float32

4-byte float.

§

Float64

8-byte float.

§

GeoJson(Srid)

Geodata in GeoJSON format, using the specified SRID.

§

Int16

2-byte int.

§

Int32

4-byte integer.

§

Int64

8-byte integer.

§

Json

JSON data. This includes both Postgres json and jsonb types, the differences between which don’t usually matter when converting schemas.

§

Named(String)

A named data type. This should correspond to a type defined in Schema::named_data_types.

§

OneOf(Vec<String>)

One of a fixed list of strings. This represents an enum in some databases, or a "red" | "green" | "blue"-style union type in TypeScript, or a “categorical” value in a machine-learning system, or a CHECK (val IN ('red', ...)) column constraint in standard SQL.

We treat this separately from Text because it’s semantically important in machine learning, and because enumeration types are an important optimization for large tables in some databases.

§

Struct(Vec<StructField>)

A structure with a known set of named fields.

Field names must be unique within a struct, and non-empty.

§

Text

A text type.

§

TimestampWithoutTimeZone

A timestamp with no timezone. Ideally, this will would be in UTC, and some systems like BigQuery may automatically assume that.

§

TimestampWithTimeZone

A timestamp with a timezone.

§

Uuid

A UUID.

Trait Implementations§

source§

impl Clone for DataType

source§

fn clone(&self) -> DataType

Returns a copy 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<'de> Deserialize<'de> for DataType

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<DataType> for DataType

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for DataType

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for DataType

source§

impl StructuralEq for DataType

source§

impl StructuralPartialEq for DataType

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,