@@ -22,12 +22,12 @@ use std::sync::Arc;
22
22
23
23
use crate :: PhysicalExpr ;
24
24
use arrow:: compute;
25
- use arrow:: compute:: { cast_with_options , CastOptions } ;
25
+ use arrow:: compute:: CastOptions ;
26
26
use arrow:: datatypes:: { DataType , FieldRef , Schema } ;
27
27
use arrow:: record_batch:: RecordBatch ;
28
28
use compute:: can_cast_types;
29
29
use datafusion_common:: format:: DEFAULT_FORMAT_OPTIONS ;
30
- use datafusion_common:: { not_impl_err, Result , ScalarValue } ;
30
+ use datafusion_common:: { not_impl_err, Result } ;
31
31
use datafusion_expr:: ColumnarValue ;
32
32
33
33
/// TRY_CAST expression casts an expression to a specific data type and returns NULL on invalid cast
@@ -96,18 +96,7 @@ impl PhysicalExpr for TryCastExpr {
96
96
safe : true ,
97
97
format_options : DEFAULT_FORMAT_OPTIONS ,
98
98
} ;
99
- match value {
100
- ColumnarValue :: Array ( array) => {
101
- let cast = cast_with_options ( & array, & self . cast_type , & options) ?;
102
- Ok ( ColumnarValue :: Array ( cast) )
103
- }
104
- ColumnarValue :: Scalar ( scalar) => {
105
- let array = scalar. to_array ( ) ?;
106
- let cast_array = cast_with_options ( & array, & self . cast_type , & options) ?;
107
- let cast_scalar = ScalarValue :: try_from_array ( & cast_array, 0 ) ?;
108
- Ok ( ColumnarValue :: Scalar ( cast_scalar) )
109
- }
110
- }
99
+ value. cast_to ( & self . cast_type , Some ( & options) )
111
100
}
112
101
113
102
fn return_field ( & self , input_schema : & Schema ) -> Result < FieldRef > {
0 commit comments