File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
datafusion/sql/src/unparser Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -487,6 +487,14 @@ impl Dialect for SqliteDialect {
487487 false
488488 }
489489
490+ fn timestamp_cast_dtype (
491+ & self ,
492+ _time_unit : & TimeUnit ,
493+ tz : & Option < Arc < str > > ,
494+ ) -> ast:: DataType {
495+ ast:: DataType :: Text
496+ }
497+
490498 fn scalar_function_to_sql_overrides (
491499 & self ,
492500 unparser : & Unparser ,
Original file line number Diff line number Diff line change @@ -3152,4 +3152,30 @@ mod tests {
31523152
31533153 Ok ( ( ) )
31543154 }
3155+
3156+ #[ test]
3157+ fn test_cast_timestamp_sqlite ( ) -> Result < ( ) > {
3158+ let sqlite_dialect: Arc < dyn Dialect > = Arc :: new ( SqliteDialect { } ) ;
3159+
3160+ for ( dialect, expected) in [
3161+ ( sqlite_dialect, "CAST(`a` AS TEXT)" ) ,
3162+ ] {
3163+ let unparser = Unparser :: new ( dialect. as_ref ( ) ) ;
3164+ let expr = Expr :: Cast ( Cast {
3165+ expr : Box :: new ( col ( "a" ) ) ,
3166+ data_type : DataType :: Timestamp (
3167+ TimeUnit :: Nanosecond ,
3168+ None ,
3169+ ) ,
3170+ } ) ;
3171+
3172+ let ast = unparser. expr_to_sql ( & expr) ?;
3173+
3174+ let actual = ast. to_string ( ) ;
3175+ let expected = expected. to_string ( ) ;
3176+
3177+ assert_eq ! ( actual, expected) ;
3178+ }
3179+ Ok ( ( ) )
3180+ }
31553181}
You can’t perform that action at this time.
0 commit comments