Skip to content

Commit 50733bc

Browse files
authored
Implement timestamp_cast_dtype for SqliteDialect (#17479)
* Implement timestamp_cast_dtype for SqliteDialect * Fix lint
1 parent bfc5067 commit 50733bc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

datafusion/sql/src/unparser/dialect.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

datafusion/sql/src/unparser/expr.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,4 +3173,24 @@ mod tests {
31733173

31743174
Ok(())
31753175
}
3176+
3177+
#[test]
3178+
fn test_cast_timestamp_sqlite() -> Result<()> {
3179+
let dialect: Arc<dyn Dialect> = Arc::new(SqliteDialect {});
3180+
3181+
let unparser = Unparser::new(dialect.as_ref());
3182+
let expr = Expr::Cast(Cast {
3183+
expr: Box::new(col("a")),
3184+
data_type: DataType::Timestamp(TimeUnit::Nanosecond, None),
3185+
});
3186+
3187+
let ast = unparser.expr_to_sql(&expr)?;
3188+
3189+
let actual = ast.to_string();
3190+
let expected = "CAST(`a` AS TEXT)".to_string();
3191+
3192+
assert_eq!(actual, expected);
3193+
3194+
Ok(())
3195+
}
31763196
}

0 commit comments

Comments
 (0)