Skip to main content

Module cast

Module cast 

Source
Expand description

Cast kernels to convert [ArrayRef] between supported datatypes.

See cast_with_options for more information on specific conversions.

Example:

// int32 to float64
let a = Int32Array::from(vec![5, 6, 7]);
let b = cast(&a, &DataType::Float64).unwrap();
let c = b.as_primitive::<Float64Type>();
assert_eq!(5.0, c.value(0));
assert_eq!(6.0, c.value(1));
assert_eq!(7.0, c.value(2));

Modulesยง

decimal ๐Ÿ”’
dictionary ๐Ÿ”’
list ๐Ÿ”’
map ๐Ÿ”’
run_array ๐Ÿ”’
string ๐Ÿ”’
structs ๐Ÿ”’
union ๐Ÿ”’
Cast support for union arrays.

Structsยง

CastOptions
CastOptions provides a way to override the default cast behaviors

Traitsยง

DecimalCast
A utility trait that provides checked conversions between decimal types inspired by NumCast

Functionsยง

adjust_timestamp_to_timezone ๐Ÿ”’
as_time_res_with_timezone ๐Ÿ”’
bool_to_numeric_cast ๐Ÿ”’
can_cast_types
Return true if a value of type from_type can be cast into a value of to_type.
cast
Cast array to the provided data type and return a new Array with type to_type, if possible.
cast_binary_to_fixed_size_binary ๐Ÿ”’
Helper function to cast from one BinaryArray or โ€˜LargeBinaryArrayโ€™ to โ€˜FixedSizeBinaryArrayโ€™.
cast_bool_to_numeric ๐Ÿ”’
Cast Boolean types to numeric
cast_byte_container ๐Ÿ”’
Helper function to cast from one ByteArrayType to another and vice versa. If the target one (e.g., LargeUtf8) is too large for the source array it will return an Error.
cast_duration_to_interval ๐Ÿ”’
Cast the array from duration and interval
cast_fixed_size_binary_to_binary ๐Ÿ”’
Helper function to cast from โ€˜FixedSizeBinaryArrayโ€™ to one BinaryArray or โ€˜LargeBinaryArrayโ€™. If the target one is too large for the source array it will return an Error.
cast_fixed_size_binary_to_binary_view ๐Ÿ”’
cast_from_decimal ๐Ÿ”’
cast_integer_to_decimal ๐Ÿ”’
cast_interval_day_time_to_interval_month_day_nano ๐Ÿ”’
Cast the array from interval day time to month day nano
cast_interval_year_month_to_interval_month_day_nano ๐Ÿ”’
Cast the array from interval year month to month day nano
cast_month_day_nano_to_duration ๐Ÿ”’
Cast the array from interval to duration
cast_num_to_bool
Cast numeric types to boolean
cast_numeric_arrays ๐Ÿ”’
Convert Array into a PrimitiveArray of type, and apply numeric cast
cast_numeric_to_binary ๐Ÿ”’
cast_numeric_to_bool ๐Ÿ”’
Cast numeric types to Boolean
cast_reinterpret_arrays ๐Ÿ”’
Cast the primitive array using [PrimitiveArray::reinterpret_cast]
cast_single_string_to_boolean_default
Cast a single string to boolean with default cast option(safe=true).
cast_time64_to_time32 ๐Ÿ”’
cast_to_decimal ๐Ÿ”’
cast_view_to_byte ๐Ÿ”’
Helper function to cast from one ByteViewType array to ByteArrayType array.
cast_with_options
Try to cast array to to_type if possible.
integer_to_decimal_native ๐Ÿ”’
Convert an integer to a decimal native value without wrapping.
make_duration_array ๐Ÿ”’
make_timestamp_array ๐Ÿ”’
num_cast
Natural cast between numeric types Return None if the input value canโ€™t be casted to type O.
numeric_cast ๐Ÿ”’
numeric_to_bool_cast ๐Ÿ”’
parse_string_to_decimal_nativeDeprecated
Parses the given string as a decimal with the given scale, returning the unscaled representation in the decimal typeโ€™s native integer (e.g. i32 for Decimal32Type, i256 for Decimal256Type).
rescale_decimal
Rescales a decimal value from (input_precision, input_scale) to (output_precision, output_scale) and returns the converted number when it fits within the output precision.
single_bool_to_numeric
Cast single bool value to numeric value.
single_decimal_to_float_lossy
Lossy conversion from decimal to float.
single_float_to_decimal
Cast a single floating point value to a decimal native with the given multiple. Returns None if the value cannot be represented with the requested precision.
time_unit_multiple ๐Ÿ”’
Get the time unit as a multiple of a second
timestamp_to_date32 ๐Ÿ”’
try_numeric_cast ๐Ÿ”’
union_extract_by_type
Extracts the best-matching child array from a [UnionArray] for a given target type, and casts it to that type.