@@ -49,8 +49,9 @@ use crate::datatypes::*;
4949use crate :: error:: { ArrowError , Result } ;
5050use crate :: { array:: * , compute:: take} ;
5151use crate :: {
52- buffer:: Buffer , util:: display:: array_value_to_string,
53- util:: serialization:: lexical_to_string,
52+ buffer:: Buffer ,
53+ util:: display:: array_value_to_string,
54+ util:: serialization:: { float_lexical_to_string, lexical_to_string} ,
5455} ;
5556use num:: { NumCast , ToPrimitive } ;
5657
@@ -832,8 +833,8 @@ pub fn cast_with_options(
832833 Int16 => cast_numeric_to_string :: < Int16Type , i32 > ( array) ,
833834 Int32 => cast_numeric_to_string :: < Int32Type , i32 > ( array) ,
834835 Int64 => cast_numeric_to_string :: < Int64Type , i32 > ( array) ,
835- Float32 => cast_numeric_to_string :: < Float32Type , i32 > ( array) ,
836- Float64 => cast_numeric_to_string :: < Float64Type , i32 > ( array) ,
836+ Float32 => cast_float_to_string :: < Float32Type , i32 > ( array) ,
837+ Float64 => cast_float_to_string :: < Float64Type , i32 > ( array) ,
837838 Timestamp ( unit, _) => match unit {
838839 TimeUnit :: Nanosecond => {
839840 cast_timestamp_to_string :: < TimestampNanosecondType , i32 > ( array)
@@ -888,8 +889,8 @@ pub fn cast_with_options(
888889 Int16 => cast_numeric_to_string :: < Int16Type , i64 > ( array) ,
889890 Int32 => cast_numeric_to_string :: < Int32Type , i64 > ( array) ,
890891 Int64 => cast_numeric_to_string :: < Int64Type , i64 > ( array) ,
891- Float32 => cast_numeric_to_string :: < Float32Type , i64 > ( array) ,
892- Float64 => cast_numeric_to_string :: < Float64Type , i64 > ( array) ,
892+ Float32 => cast_float_to_string :: < Float32Type , i64 > ( array) ,
893+ Float64 => cast_float_to_string :: < Float64Type , i64 > ( array) ,
893894 Timestamp ( unit, _) => match unit {
894895 TimeUnit :: Nanosecond => {
895896 cast_timestamp_to_string :: < TimestampNanosecondType , i64 > ( array)
@@ -1592,6 +1593,36 @@ where
15921593 . collect ( )
15931594}
15941595
1596+ /// Cast float types to Utf8
1597+ fn cast_float_to_string < FROM , OffsetSize > ( array : & ArrayRef ) -> Result < ArrayRef >
1598+ where
1599+ FROM : ArrowFloatNumericType ,
1600+ FROM :: Native :
1601+ lexical_core:: ToLexicalWithOptions < Options = lexical_core:: WriteFloatOptions > ,
1602+ OffsetSize : StringOffsetSizeTrait ,
1603+ {
1604+ Ok ( Arc :: new ( float_to_string_cast :: < FROM , OffsetSize > (
1605+ array
1606+ . as_any ( )
1607+ . downcast_ref :: < PrimitiveArray < FROM > > ( )
1608+ . unwrap ( ) ,
1609+ ) ) )
1610+ }
1611+
1612+ fn float_to_string_cast < T , OffsetSize > (
1613+ from : & PrimitiveArray < T > ,
1614+ ) -> GenericStringArray < OffsetSize >
1615+ where
1616+ T : ArrowPrimitiveType + ArrowFloatNumericType ,
1617+ T :: Native :
1618+ lexical_core:: ToLexicalWithOptions < Options = lexical_core:: WriteFloatOptions > ,
1619+ OffsetSize : StringOffsetSizeTrait ,
1620+ {
1621+ from. iter ( )
1622+ . map ( |maybe_value| maybe_value. map ( float_lexical_to_string) )
1623+ . collect ( )
1624+ }
1625+
15951626/// Cast numeric types to Utf8
15961627fn cast_string_to_numeric < T , Offset : StringOffsetSizeTrait > (
15971628 from : & ArrayRef ,
0 commit comments