@@ -374,34 +374,35 @@ impl SQLExprVisitor<'_> {
374374 } ,
375375 // identify "CAST(expr AS type) <op> string" and/or "expr::type <op> string" expressions
376376 ( Expr :: Cast { expr, dtype, .. } , Expr :: Literal ( LiteralValue :: String ( s) ) ) => {
377- if let Expr :: Column ( name) = & * * expr {
378- ( Some ( name. clone ( ) ) , Some ( s) , Some ( dtype) )
379- } else {
380- ( None , Some ( s) , Some ( dtype) )
377+ match & * * expr {
378+ Expr :: Column ( name) => ( Some ( name. clone ( ) ) , Some ( s) , Some ( dtype) ) ,
379+ _ => ( None , Some ( s) , Some ( dtype) ) ,
381380 }
382381 } ,
383382 _ => ( None , None , None ) ,
384383 } {
385384 if expr_dtype. is_none ( ) && self . active_schema . is_none ( ) {
386385 right. clone ( )
387386 } else {
388- let left_dtype = expr_dtype
389- . unwrap_or_else ( || self . active_schema . as_ref ( ) . unwrap ( ) . get ( & name) . unwrap ( ) ) ;
390-
387+ let left_dtype = expr_dtype. or_else ( || {
388+ self . active_schema
389+ . as_ref ( )
390+ . and_then ( |schema| schema. get ( & name) )
391+ } ) ;
391392 match left_dtype {
392- DataType :: Time if is_iso_time ( s) => {
393+ Some ( DataType :: Time ) if is_iso_time ( s) => {
393394 right. clone ( ) . str ( ) . to_time ( StrptimeOptions {
394395 strict : true ,
395396 ..Default :: default ( )
396397 } )
397398 } ,
398- DataType :: Date if is_iso_date ( s) => {
399+ Some ( DataType :: Date ) if is_iso_date ( s) => {
399400 right. clone ( ) . str ( ) . to_date ( StrptimeOptions {
400401 strict : true ,
401402 ..Default :: default ( )
402403 } )
403404 } ,
404- DataType :: Datetime ( tu, tz) if is_iso_datetime ( s) || is_iso_date ( s) => {
405+ Some ( DataType :: Datetime ( tu, tz) ) if is_iso_datetime ( s) || is_iso_date ( s) => {
405406 if s. len ( ) == 10 {
406407 // handle upcast from ISO date string (10 chars) to datetime
407408 lit ( format ! ( "{}T00:00:00" , s) )
0 commit comments