FieldExt

Trait FieldExt 

Source
pub trait FieldExt {
    // Required methods
    fn renamed(self, new_name: &str) -> Self;
    fn retyped(self, new_data_type: DataType) -> Self;
    fn with_field_metadata(self, metadata: &FieldMetadata) -> Self;
    fn with_field_metadata_opt(self, metadata: Option<&FieldMetadata>) -> Self;
    fn into_list(self) -> Self;
    fn into_fixed_size_list(self, list_size: i32) -> Self;
    fn into_list_item(self) -> Self;
}
Expand description

DataFusion extension methods for Arrow Field and FieldRef

This trait is implemented for both Field and FieldRef and provides convenience methods for efficiently working with both types.

For FieldRef, the methods will attempt to unwrap the Arc to avoid unnecessary cloning when possible.

Required Methods§

Source

fn renamed(self, new_name: &str) -> Self

Ensure the field is named new_name, returning the given field if the name matches, and a new field if not.

This method avoids cloneing fields and names if the name is the same as the field’s existing name.

Example:

let int_field = Field::new("my_int", DataType::Int32, true);
// rename to "your_int"
let renamed_field = int_field.renamed("your_int");
assert_eq!(renamed_field.name(), "your_int");
Source

fn retyped(self, new_data_type: DataType) -> Self

Ensure the field has the given data type

Note this is different than simply calling Field::with_data_type as it avoids copying if the data type is already the same.

Example:

let int_field = Field::new("my_int", DataType::Int32, true);
// change to Float64
let retyped_field = int_field.retyped(DataType::Float64);
assert_eq!(retyped_field.data_type(), &DataType::Float64);
Source

fn with_field_metadata(self, metadata: &FieldMetadata) -> Self

Add field metadata to the Field

Source

fn with_field_metadata_opt(self, metadata: Option<&FieldMetadata>) -> Self

Add optional field metadata,

Source

fn into_list(self) -> Self

Returns a new Field representing a List of this Field’s DataType.

For example if input represents an Int32, the return value will represent a List<Int32>.

Example:

// Int32 field
let int_field = Field::new("my_int", DataType::Int32, true);
// convert to a List field
let list_field = int_field.into_list();
// List<Int32>
// Note that the item field name has been renamed to "item"
assert_eq!(list_field.data_type(), &DataType::List(Arc::new(
    Field::new("item", DataType::Int32, true)
)));
Source

fn into_fixed_size_list(self, list_size: i32) -> Self

Return a new Field representing this Field as the item type of a DataType::FixedSizeList

For example if input represents an Int32, the return value will represent a FixedSizeList<Int32, size>.

Example:

// Int32 field
let int_field = Field::new("my_int", DataType::Int32, true);
// convert to a FixedSizeList field of size 3
let fixed_size_list_field = int_field.into_fixed_size_list(3);
// FixedSizeList<Int32, 3>
// Note that the item field name has been renamed to "item"
assert_eq!(
  fixed_size_list_field.data_type(),
  &DataType::FixedSizeList(Arc::new(
   Field::new("item", DataType::Int32, true)),
   3
));
Source

fn into_list_item(self) -> Self

Update the field to have the default list field name (“item”)

Lists are allowed to have an arbitrarily named field; however, a name other than ‘item’ will cause it to fail an == check against a more idiomatically created list in arrow-rs which causes issues.

For example, if input represents an Int32 field named “my_int”, the return value will represent an Int32 field named “item”.

Example:

let my_field = Field::new("my_int", arrow::datatypes::DataType::Int32, true);
let item_field = my_field.into_list_item();
assert_eq!(item_field.name(), Field::LIST_FIELD_DEFAULT_NAME);
assert_eq!(item_field.name(), "item");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FieldExt for Arc<Field>

Source§

fn renamed(self, new_name: &str) -> Self

Source§

fn retyped(self, new_data_type: DataType) -> Self

Source§

fn with_field_metadata(self, metadata: &FieldMetadata) -> Self

Source§

fn with_field_metadata_opt(self, metadata: Option<&FieldMetadata>) -> Self

Source§

fn into_list(self) -> Self

Source§

fn into_fixed_size_list(self, list_size: i32) -> Self

Source§

fn into_list_item(self) -> Self

Source§

impl FieldExt for Field

Source§

fn renamed(self, new_name: &str) -> Self

Source§

fn retyped(self, new_data_type: DataType) -> Self

Source§

fn with_field_metadata(self, metadata: &FieldMetadata) -> Self

Source§

fn with_field_metadata_opt(self, metadata: Option<&FieldMetadata>) -> Self

Source§

fn into_list(self) -> Self

Source§

fn into_fixed_size_list(self, list_size: i32) -> Self

Source§

fn into_list_item(self) -> Self

Implementors§