pub enum DataType {
Show 28 variants
Null,
Boolean,
Byte,
Short,
Integer,
Long,
Float,
Double,
Decimal {
precision: i32,
scale: i32,
},
String {
collation: String,
},
Char {
length: i32,
},
Varchar {
length: i32,
},
Binary,
Date,
Timestamp,
TimestampNtz,
Time {
precision: i32,
},
CalendarInterval,
YearMonthInterval {
start_field: i32,
end_field: i32,
},
DayTimeInterval {
start_field: i32,
end_field: i32,
},
Array {
element_type: Box<DataType>,
contains_null: bool,
},
Map {
key_type: Box<DataType>,
value_type: Box<DataType>,
value_contains_null: bool,
},
Struct {
fields: Vec<StructField>,
},
Variant,
Geometry {
srid: i32,
},
Geography {
srid: i32,
},
Udt {
type_str: String,
jvm_class: Option<String>,
python_class: Option<String>,
serialized_python_class: Option<String>,
sql_type: Option<Box<DataType>>,
},
Unparsed {
data_type_string: String,
},
}Expand description
The base DataType representation, mirroring pyspark.sql.types.DataType.
All concrete types are variants of this enum. Each variant carries the data needed to fully specify that type (e.g., DecimalType carries precision and scale).
Variants§
Null
pyspark.sql.types.NullType
Boolean
pyspark.sql.types.BooleanType
Byte
pyspark.sql.types.ByteType (tinyint)
Short
pyspark.sql.types.ShortType (smallint)
Integer
pyspark.sql.types.IntegerType (int)
Long
pyspark.sql.types.LongType (bigint)
Float
pyspark.sql.types.FloatType
Double
pyspark.sql.types.DoubleType
Decimal
pyspark.sql.types.DecimalType
String
pyspark.sql.types.StringType
Char
pyspark.sql.types.CharType
Varchar
pyspark.sql.types.VarcharType
Binary
pyspark.sql.types.BinaryType
Date
pyspark.sql.types.DateType
Timestamp
pyspark.sql.types.TimestampType
TimestampNtz
pyspark.sql.types.TimestampNTZType
Time
pyspark.sql.types.TimeType
CalendarInterval
pyspark.sql.types.CalendarIntervalType
YearMonthInterval
pyspark.sql.types.YearMonthIntervalType
DayTimeInterval
pyspark.sql.types.DayTimeIntervalType
Array
pyspark.sql.types.ArrayType
Map
pyspark.sql.types.MapType
Struct
pyspark.sql.types.StructType
Fields
fields: Vec<StructField>Variant
pyspark.sql.types.VariantType
Geometry
pyspark.sql.types.GeometryType
Geography
pyspark.sql.types.GeographyType
Udt
pyspark.sql.types.UserDefinedType (stub)
Fields
Unparsed
pyspark.sql.connect.types.UnparsedDataType - a DDL type string left for
the server to parse (round-trips through the unparsed proto).
Implementations§
Source§impl DataType
impl DataType
Sourcepub fn from_ddl(ddl_str: &str) -> Result<DataType>
pub fn from_ddl(ddl_str: &str) -> Result<DataType>
Parses a DDL-formatted string into a DataType, mirroring DataType.fromDDL().
This supports:
- Primitive types: int, bigint, string, double, boolean, date, timestamp, binary, tinyint, smallint, float, decimal(p,s), char(n), varchar(n), interval
- Complex types: array<…>, map<…,…>, structname:type,...
- Top-level struct can omit the “struct<>” wrapper for backward compatibility
- DDL like “a INT, b STRING” is parsed as a struct
Examples:
DataType::from_ddl("int") // IntegerType
DataType::from_ddl("array<string>") // ArrayType(StringType, true)
DataType::from_ddl("struct<name:string,age:int>") // StructType
DataType::from_ddl("a INT, b STRING") // Top-level structSourcepub fn need_conversion(&self) -> bool
pub fn need_conversion(&self) -> bool
Returns whether this type needs conversion between Python objects and internal SQL objects. This is used to avoid unnecessary conversions for ArrayType/MapType/StructType.
Types that need conversion include:
- DateType: needs conversion to/from datetime.date
- TimestampType: needs conversion to/from datetime.datetime
- TimestampNTZType: needs conversion to/from datetime.datetime (no timezone)
- TimeType: needs conversion to/from datetime.time
- DayTimeIntervalType: needs conversion to/from datetime.timedelta
- CalendarIntervalType: needs conversion
- YearMonthIntervalType: needs conversion (complex)
- ArrayType: if element type needs conversion
- MapType: if key or value type needs conversion
- StructType: always needs conversion
Sourcepub fn type_name(&self) -> String
pub fn type_name(&self) -> String
Returns the type name, mirroring DataType.typeName().
For most types, this is the class name with the “Type” suffix removed and lowercased. E.g., “ByteType” -> “byte”, but NullType -> “void”, and special handling for others.
Sourcepub fn simple_string(&self) -> String
pub fn simple_string(&self) -> String
Returns the simple string representation, mirroring DataType.simpleString().
For example:
- “int”, “string”, “boolean”
- “decimal(10,0)”, “char(50)”, “varchar(100)”
- “array
”, “map<string,int>”, “structname:string,age:int” - “interval day to second”
Sourcepub fn json_value(&self) -> Value
pub fn json_value(&self) -> Value
Returns the JSON value representation, mirroring DataType.jsonValue().
Most simple types return their type name as a string. Complex types (Array, Map, Struct) return a dictionary with type and component info.
Sourcepub fn from_json(value: &Value) -> Result<DataType>
pub fn from_json(value: &Value) -> Result<DataType>
Parses a JSON value into a DataType, mirroring the reverse of json() / jsonValue().
Sourcepub fn from_json_str(s: &str) -> Result<DataType>
pub fn from_json_str(s: &str) -> Result<DataType>
Parses a JSON string into a DataType (convenience over [from_json]).
Sourcepub fn to_proto(&self) -> DataType
pub fn to_proto(&self) -> DataType
Converts to a protobuf DataType, mirroring
pyspark.sql.connect.types.pyspark_types_to_proto_types.
Sourcepub fn from_proto(proto: &DataType) -> Result<DataType>
pub fn from_proto(proto: &DataType) -> Result<DataType>
Converts from a protobuf DataType, mirroring
pyspark.sql.connect.types.proto_schema_to_pyspark_data_type.
Source§impl DataType
Helper methods for StructType operations, mirroring pyspark.sql.types.StructType.
Since StructType is represented as DataType::Struct { fields }, these methods provide
convenience operations for struct types.
impl DataType
Helper methods for StructType operations, mirroring pyspark.sql.types.StructType.
Since StructType is represented as DataType::Struct { fields }, these methods provide
convenience operations for struct types.
Sourcepub fn field_names(&self) -> Result<Vec<String>>
pub fn field_names(&self) -> Result<Vec<String>>
Returns all field names in a StructType, mirroring StructType.fieldNames().
Returns an error if called on a non-Struct type.
Sourcepub fn names(&self) -> Result<Vec<String>>
pub fn names(&self) -> Result<Vec<String>>
Alias for field_names(), also mirroring pyspark’s names attribute.
Sourcepub fn to_ddl(&self) -> Result<String>
pub fn to_ddl(&self) -> Result<String>
DDL string for a StructType, mirroring StructType.toDDL():
comma-separated name type[ NOT NULL][ COMMENT '...'] per field.
Sourcepub fn tree_string(&self) -> Result<String>
pub fn tree_string(&self) -> Result<String>
Tree-string for a StructType, mirroring StructType.treeString().
Sourcepub fn tree_string_with_depth(&self, max_depth: i32) -> Result<String>
pub fn tree_string_with_depth(&self, max_depth: i32) -> Result<String>
Like DataType::tree_string, but stops recursing into nested structs
once max_depth nesting levels have been printed (top-level fields are
depth 1). Mirrors StructType.treeString(maxDepth).
Sourcepub fn to_nullable(&self) -> DataType
pub fn to_nullable(&self) -> DataType
Return a copy with every field made nullable (recursively), mirroring
StructType.toNullable().
Sourcepub fn add(
&self,
field_name: &str,
field_type: DataType,
nullable: bool,
metadata: Option<BTreeMap<String, Value>>,
) -> Result<DataType>
pub fn add( &self, field_name: &str, field_type: DataType, nullable: bool, metadata: Option<BTreeMap<String, Value>>, ) -> Result<DataType>
Adds a field to a StructType, mirroring StructType.add().
This is a builder method that returns a new StructType with the field added. Returns an error if called on a non-Struct type.
Example:
let struct_type = DataType::Struct { fields: vec![] };
let with_field = struct_type.add(
"name",
DataType::String { collation: "UTF8_BINARY".to_string() },
true,
None,
)?;Trait Implementations§
impl StructuralPartialEq for DataType
Auto Trait Implementations§
impl Freeze for DataType
impl RefUnwindSafe for DataType
impl Send for DataType
impl Sync for DataType
impl Unpin for DataType
impl UnsafeUnpin for DataType
impl UnwindSafe for DataType
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request