goldmedal commented on code in PR #10984:
URL: https://github.com/apache/datafusion/pull/10984#discussion_r1644885689
##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -819,8 +820,49 @@ impl Unparser<'_> {
ScalarValue::TimestampMicrosecond(None, _) => {
Ok(ast::Expr::Value(ast::Value::Null))
}
- ScalarValue::TimestampNanosecond(Some(_ts), _) => {
- not_impl_err!("Unsupported scalar: {v:?}")
+ ScalarValue::TimestampNanosecond(Some(_ts), tz) => {
+ if let Some(tz) = tz {
+ let result = v
+ .to_array()?
+ .as_any()
+ .downcast_ref::<TimestampNanosecondArray>()
+ .ok_or(internal_datafusion_err!(
+ "Unable to downcast to TimestampNanosecond from
TimestampNanosecond scalar"
+ ))?
+ .value_as_datetime_with_tz(0, tz.parse()?)
+ .ok_or(internal_datafusion_err!(
+ "Unable to convert TimestampNanosecond to DateTime"
+ ))?;
+ Ok(ast::Expr::Cast {
+ kind: ast::CastKind::Cast,
+ expr:
Box::new(ast::Expr::Value(ast::Value::SingleQuotedString(
+ result.to_string(),
+ ))),
+ data_type: ast::DataType::Timestamp(None,
TimezoneInfo::None),
+ format: None,
+ })
Review Comment:
Thanks, @alamb, for reminding me of this point. I forgot to refactor this
part.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]