Enum dbcrossbarlib::schema::DataType [−][src]
pub enum DataType {
}
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:
- Class hierarchies provide an extensible set of types (subclasses), but a closed set of operations (instance methods on the root class).
- Rust
enum
s 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)
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>)
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
0: 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
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for DataType
impl UnwindSafe for DataType
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
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