Enum dbcrossbarlib::schema::DataType[][src]

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

Tuple Fields

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)

Tuple Fields

0: 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)

Tuple Fields

0: String

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

OneOf(Vec<String>)

Tuple Fields

0: 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>)

Tuple Fields

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

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

Performs the conversion.

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

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

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

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

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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

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

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