pub struct Field {
name: String,
data_type: DataType,
nullable: bool,
dict_id: i64,
dict_is_ordered: bool,
metadata: HashMap<String, String>,
}
Expand description
Fields§
§name: String
§data_type: DataType
§nullable: bool
§dict_id: i64
dict_is_ordered: bool
§metadata: HashMap<String, String>
A map of key-value pairs containing additional custom meta data.
Implementations§
Source§impl Field
impl Field
Sourcepub const LIST_FIELD_DEFAULT_NAME: &'static str = "item"
pub const LIST_FIELD_DEFAULT_NAME: &'static str = "item"
Default list member field name
Sourcepub fn new(name: impl Into<String>, data_type: DataType, nullable: bool) -> Self
pub fn new(name: impl Into<String>, data_type: DataType, nullable: bool) -> Self
Creates a new field with the given name, type, and nullability
Sourcepub fn new_list_field(data_type: DataType, nullable: bool) -> Self
pub fn new_list_field(data_type: DataType, nullable: bool) -> Self
Creates a new Field
suitable for DataType::List
and
DataType::LargeList
While not required, this method follows the convention of naming the
Field
"item"
.
§Example
assert_eq!(
Field::new("item", DataType::Int32, true),
Field::new_list_field(DataType::Int32, true)
);
Sourcepub fn new_dict(
name: impl Into<String>,
data_type: DataType,
nullable: bool,
dict_id: i64,
dict_is_ordered: bool,
) -> Self
👎Deprecated since 54.0.0: The ability to preserve dictionary IDs will be removed. With the dict_id field disappearing this function signature will change by removing the dict_id parameter.
pub fn new_dict( name: impl Into<String>, data_type: DataType, nullable: bool, dict_id: i64, dict_is_ordered: bool, ) -> Self
Creates a new field that has additional dictionary information
Sourcepub fn new_dictionary(
name: impl Into<String>,
key: DataType,
value: DataType,
nullable: bool,
) -> Self
pub fn new_dictionary( name: impl Into<String>, key: DataType, value: DataType, nullable: bool, ) -> Self
Create a new Field
with DataType::Dictionary
Use Self::new_dict
for more advanced dictionary options
§Panics
Panics if !key.is_dictionary_key_type
Sourcepub fn new_struct(
name: impl Into<String>,
fields: impl Into<Fields>,
nullable: bool,
) -> Self
pub fn new_struct( name: impl Into<String>, fields: impl Into<Fields>, nullable: bool, ) -> Self
Create a new Field
with DataType::Struct
name
: the name of theDataType::Struct
fieldfields
: the description of each struct elementnullable
: if theDataType::Struct
array is nullable
Sourcepub fn new_list(
name: impl Into<String>,
value: impl Into<FieldRef>,
nullable: bool,
) -> Self
pub fn new_list( name: impl Into<String>, value: impl Into<FieldRef>, nullable: bool, ) -> Self
Create a new Field
with DataType::List
name
: the name of theDataType::List
fieldvalue
: the description of each list elementnullable
: if theDataType::List
array is nullable
Sourcepub fn new_large_list(
name: impl Into<String>,
value: impl Into<FieldRef>,
nullable: bool,
) -> Self
pub fn new_large_list( name: impl Into<String>, value: impl Into<FieldRef>, nullable: bool, ) -> Self
Create a new Field
with DataType::LargeList
name
: the name of theDataType::LargeList
fieldvalue
: the description of each list elementnullable
: if theDataType::LargeList
array is nullable
Sourcepub fn new_fixed_size_list(
name: impl Into<String>,
value: impl Into<FieldRef>,
size: i32,
nullable: bool,
) -> Self
pub fn new_fixed_size_list( name: impl Into<String>, value: impl Into<FieldRef>, size: i32, nullable: bool, ) -> Self
Create a new Field
with DataType::FixedSizeList
name
: the name of theDataType::FixedSizeList
fieldvalue
: the description of each list elementsize
: the size of the fixed size listnullable
: if theDataType::FixedSizeList
array is nullable
Sourcepub fn new_map(
name: impl Into<String>,
entries: impl Into<String>,
keys: impl Into<FieldRef>,
values: impl Into<FieldRef>,
sorted: bool,
nullable: bool,
) -> Self
pub fn new_map( name: impl Into<String>, entries: impl Into<String>, keys: impl Into<FieldRef>, values: impl Into<FieldRef>, sorted: bool, nullable: bool, ) -> Self
Create a new Field
with DataType::Map
name
: the name of theDataType::Map
fieldentries
: the name of the innerDataType::Struct
fieldkeys
: the map keysvalues
: the map valuessorted
: if theDataType::Map
array is sortednullable
: if theDataType::Map
array is nullable
Sourcepub fn new_union<S, F, T>(
name: S,
type_ids: T,
fields: F,
mode: UnionMode,
) -> Self
pub fn new_union<S, F, T>( name: S, type_ids: T, fields: F, mode: UnionMode, ) -> Self
Create a new Field
with DataType::Union
name
: the name of theDataType::Union
fieldtype_ids
: the union type idsfields
: the union fieldsmode
: the union mode
Sourcepub fn set_metadata(&mut self, metadata: HashMap<String, String>)
pub fn set_metadata(&mut self, metadata: HashMap<String, String>)
Sets the Field
’s optional custom metadata.
Sourcepub fn with_metadata(self, metadata: HashMap<String, String>) -> Self
pub fn with_metadata(self, metadata: HashMap<String, String>) -> Self
Sets the metadata of this Field
to be metadata
and returns self
Sourcepub const fn metadata(&self) -> &HashMap<String, String>
pub const fn metadata(&self) -> &HashMap<String, String>
Returns the immutable reference to the Field
’s optional custom metadata.
Sourcepub fn with_name(self, name: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
Set the name of the Field
and returns self.
let field = Field::new("c1", DataType::Int64, false)
.with_name("c2");
assert_eq!(field.name(), "c2");
Sourcepub fn with_data_type(self, data_type: DataType) -> Self
pub fn with_data_type(self, data_type: DataType) -> Self
Sourcepub fn extension_type_name(&self) -> Option<&str>
pub fn extension_type_name(&self) -> Option<&str>
Returns the extension type name of this Field
, if set.
This returns the value of EXTENSION_TYPE_NAME_KEY
, if set in
Field::metadata
. If the key is missing, there is no extension type
name and this returns None
.
§Example
let field = Field::new("", DataType::Null, false);
assert_eq!(field.extension_type_name(), None);
let field = Field::new("", DataType::Null, false).with_metadata(
[(EXTENSION_TYPE_NAME_KEY.to_owned(), "example".to_owned())]
.into_iter()
.collect(),
);
assert_eq!(field.extension_type_name(), Some("example"));
Sourcepub fn extension_type_metadata(&self) -> Option<&str>
pub fn extension_type_metadata(&self) -> Option<&str>
Returns the extension type metadata of this Field
, if set.
This returns the value of EXTENSION_TYPE_METADATA_KEY
, if set in
Field::metadata
. If the key is missing, there is no extension type
metadata and this returns None
.
§Example
let field = Field::new("", DataType::Null, false);
assert_eq!(field.extension_type_metadata(), None);
let field = Field::new("", DataType::Null, false).with_metadata(
[(EXTENSION_TYPE_METADATA_KEY.to_owned(), "example".to_owned())]
.into_iter()
.collect(),
);
assert_eq!(field.extension_type_metadata(), Some("example"));
Sourcepub fn try_extension_type<E: ExtensionType>(&self) -> Result<E, ArrowError>
pub fn try_extension_type<E: ExtensionType>(&self) -> Result<E, ArrowError>
Returns an instance of the given ExtensionType
of this Field
,
if set in the Field::metadata
.
§Error
Returns an error if
- this field does not have the name of this extension type
(
ExtensionType::NAME
) in theField::metadata
(mismatch or missing) - the deserialization of the metadata
(
ExtensionType::deserialize_metadata
) fails - the construction of the extension type (
ExtensionType::try_new
) fail (for example when theField::data_type
is not supported by the extension type (ExtensionType::supports_data_type
))
Sourcepub fn extension_type<E: ExtensionType>(&self) -> E
pub fn extension_type<E: ExtensionType>(&self) -> E
Returns an instance of the given ExtensionType
of this Field
,
panics if this Field
does not have this extension type.
§Panic
This calls Field::try_extension_type
and panics when it returns an
error.
Sourcepub fn try_with_extension_type<E: ExtensionType>(
&mut self,
extension_type: E,
) -> Result<(), ArrowError>
pub fn try_with_extension_type<E: ExtensionType>( &mut self, extension_type: E, ) -> Result<(), ArrowError>
Updates the metadata of this Field
with the ExtensionType::NAME
and ExtensionType::metadata
of the given ExtensionType
, if the
given extension type supports the Field::data_type
of this field
(ExtensionType::supports_data_type
).
If the given extension type defines no metadata, a previously set
value of EXTENSION_TYPE_METADATA_KEY
is cleared.
§Error
This functions returns an error if the data type of this field does not match any of the supported storage types of the given extension type.
Sourcepub fn with_extension_type<E: ExtensionType>(self, extension_type: E) -> Self
pub fn with_extension_type<E: ExtensionType>(self, extension_type: E) -> Self
Updates the metadata of this Field
with the ExtensionType::NAME
and ExtensionType::metadata
of the given ExtensionType
.
§Panics
This calls Field::try_with_extension_type
and panics when it
returns an error.
Sourcepub fn try_canonical_extension_type(
&self,
) -> Result<CanonicalExtensionType, ArrowError>
pub fn try_canonical_extension_type( &self, ) -> Result<CanonicalExtensionType, ArrowError>
Returns the CanonicalExtensionType
of this Field
, if set.
§Error
Returns an error if
- this field does have a canonical extension type (mismatch or missing)
- the canonical extension is not supported
- the construction of the extension type fails
Sourcepub const fn is_nullable(&self) -> bool
pub const fn is_nullable(&self) -> bool
Indicates whether this Field
supports null values.
Sourcepub fn with_nullable(self, nullable: bool) -> Self
pub fn with_nullable(self, nullable: bool) -> Self
Set nullable
of the Field
and returns self.
let field = Field::new("c1", DataType::Int64, false)
.with_nullable(true);
assert_eq!(field.is_nullable(), true);
fn _fields(dt: &DataType) -> Vec<&Field>
Sourcepub(crate) fn fields_with_dict_id(&self, id: i64) -> Vec<&Field>
👎Deprecated since 54.0.0: The ability to preserve dictionary IDs will be removed. With it, all fields related to it.
pub(crate) fn fields_with_dict_id(&self, id: i64) -> Vec<&Field>
Returns a vector containing all (potentially nested) Field
instances selected by the
dictionary ID they use
Sourcepub const fn dict_id(&self) -> Option<i64>
👎Deprecated since 54.0.0: The ability to preserve dictionary IDs will be removed. With it, all fields related to it.
pub const fn dict_id(&self) -> Option<i64>
Returns the dictionary ID, if this is a dictionary type.
Sourcepub const fn dict_is_ordered(&self) -> Option<bool>
pub const fn dict_is_ordered(&self) -> Option<bool>
Returns whether this Field
’s dictionary is ordered, if this is a dictionary type.
§Example
// non dictionaries do not have a dict is ordered flat
let field = Field::new("c1", DataType::Int64, false);
assert_eq!(field.dict_is_ordered(), None);
// by default dictionary is not ordered
let field = Field::new("c1", DataType::Dictionary(Box::new(DataType::Int64), Box::new(DataType::Utf8)), false);
assert_eq!(field.dict_is_ordered(), Some(false));
let field = field.with_dict_is_ordered(true);
assert_eq!(field.dict_is_ordered(), Some(true));
Sourcepub fn with_dict_is_ordered(self, dict_is_ordered: bool) -> Self
pub fn with_dict_is_ordered(self, dict_is_ordered: bool) -> Self
Set the is ordered field for this Field
, if it is a dictionary.
Does nothing if this is not a dictionary type.
See Field::dict_is_ordered
for more information.
Sourcepub fn try_merge(&mut self, from: &Field) -> Result<(), ArrowError>
pub fn try_merge(&mut self, from: &Field) -> Result<(), ArrowError>
Merge this field into self if it is compatible.
Struct fields are merged recursively.
NOTE: self
may be updated to a partial / unexpected state in case of merge failure.
Example:
let mut field = Field::new("c1", DataType::Int64, false);
assert!(field.try_merge(&Field::new("c1", DataType::Int64, true)).is_ok());
assert!(field.is_nullable());
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Field
impl<'de> Deserialize<'de> for Field
Source§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>,
Source§impl Extend<Field> for SchemaBuilder
impl Extend<Field> for SchemaBuilder
Source§fn extend<T: IntoIterator<Item = Field>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Field>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)