@@ -1418,7 +1418,7 @@ fn date_addsub_year_month(t: NaiveDateTime, i: i32, is_add: bool) -> Result<Naiv
14181418 }
14191419 debug_assert ! ( 0 <= month) ;
14201420 year += month / 12 ;
1421- month = month % 12 ;
1421+ month %= 12 ;
14221422
14231423 match change_ym ( t, year, 1 + month as u32 ) {
14241424 Some ( t) => return Ok ( t) ,
@@ -1442,13 +1442,13 @@ fn date_addsub_month_day_nano(
14421442 let result = if month > 0 && is_add || month < 0 && !is_add {
14431443 t. checked_add_months ( Months :: new ( month as u32 ) )
14441444 } else {
1445- t. checked_sub_months ( Months :: new ( month. abs ( ) as u32 ) )
1445+ t. checked_sub_months ( Months :: new ( month. unsigned_abs ( ) ) )
14461446 } ;
14471447
14481448 let result = if day > 0 && is_add || day < 0 && !is_add {
14491449 result. and_then ( |t| t. checked_add_days ( Days :: new ( day as u64 ) ) )
14501450 } else {
1451- result. and_then ( |t| t. checked_sub_days ( Days :: new ( day. abs ( ) as u64 ) ) )
1451+ result. and_then ( |t| t. checked_sub_days ( Days :: new ( day. unsigned_abs ( ) as u64 ) ) )
14521452 } ;
14531453
14541454 let result = result. and_then ( |t| {
@@ -1472,7 +1472,7 @@ fn date_addsub_day_time(
14721472 let result = if days > 0 && is_add || days < 0 && !is_add {
14731473 t. checked_add_days ( Days :: new ( days as u64 ) )
14741474 } else {
1475- t. checked_sub_days ( Days :: new ( days. abs ( ) as u64 ) )
1475+ t. checked_sub_days ( Days :: new ( days. unsigned_abs ( ) as u64 ) )
14761476 } ;
14771477
14781478 let result = result. and_then ( |t| {
@@ -1501,9 +1501,9 @@ fn last_day_of_month(y: i32, m: u32) -> u32 {
15011501 return 31 ;
15021502 }
15031503 NaiveDate :: from_ymd_opt ( y, m + 1 , 1 )
1504- . expect ( & format ! ( "Invalid year month: {}-{}" , y, m) )
1504+ . unwrap_or_else ( || panic ! ( "Invalid year month: {}-{}" , y, m) )
15051505 . pred_opt ( )
1506- . expect ( & format ! ( "Invalid year month: {}-{}" , y, m) )
1506+ . unwrap_or_else ( || panic ! ( "Invalid year month: {}-{}" , y, m) )
15071507 . day ( )
15081508}
15091509
@@ -1564,10 +1564,7 @@ pub fn create_str_to_date_udf() -> ScalarUDF {
15641564
15651565 let res = NaiveDateTime :: parse_from_str ( timestamp, & format) . map_err ( |e| {
15661566 DataFusionError :: Execution ( format ! (
1567- "Error evaluating str_to_date('{}', '{}'): {}" ,
1568- timestamp,
1569- format,
1570- e. to_string( )
1567+ "Error evaluating str_to_date('{timestamp}', '{format}'): {e}"
15711568 ) )
15721569 } ) ?;
15731570
@@ -1671,7 +1668,7 @@ pub fn create_to_char_udf() -> ScalarUDF {
16711668 let secs = duration. num_seconds ( ) ;
16721669 let nanosecs = duration. num_nanoseconds ( ) . unwrap_or ( 0 ) - secs * 1_000_000_000 ;
16731670 let timestamp = NaiveDateTime :: from_timestamp_opt ( secs, nanosecs as u32 )
1674- . expect ( format ! ( "Invalid secs {} nanosecs {}" , secs, nanosecs) . as_str ( ) ) ;
1671+ . unwrap_or_else ( || panic ! ( "Invalid secs {} nanosecs {}" , secs, nanosecs) ) ;
16751672
16761673 // chrono's strftime is missing quarter format, as such a workaround is required
16771674 let quarter = & format ! ( "{}" , timestamp. date( ) . month0( ) / 3 + 1 ) ;
@@ -2237,10 +2234,7 @@ pub fn create_pg_get_constraintdef_udf() -> ScalarUDF {
22372234 let oids_arr = downcast_primitive_arg ! ( args[ 0 ] , "oid" , OidType ) ;
22382235 let result = oids_arr
22392236 . iter ( )
2240- . map ( |oid| match oid {
2241- Some ( _oid) => Some ( "PRIMARY KEY (oid)" . to_string ( ) ) ,
2242- _ => None ,
2243- } )
2237+ . map ( |oid| oid. map ( |_oid| "PRIMARY KEY (oid)" . to_string ( ) ) )
22442238 . collect :: < StringArray > ( ) ;
22452239
22462240 Ok ( Arc :: new ( result) )
@@ -3583,7 +3577,7 @@ pub fn create_array_to_string_udf() -> ScalarUDF {
35833577 let join_str = join_strs. value ( i) ;
35843578 let strings = downcast_string_arg ! ( array, "str" , i32 ) ;
35853579 let joined_string =
3586- itertools:: Itertools :: intersperse ( strings. iter ( ) . filter_map ( |s| s ) , join_str)
3580+ itertools:: Itertools :: intersperse ( strings. iter ( ) . flatten ( ) , join_str)
35873581 . collect :: < String > ( ) ;
35883582 builder. append_value ( joined_string) ?;
35893583 }
0 commit comments