alamb commented on code in PR #6654:
URL: https://github.com/apache/arrow-datafusion/pull/6654#discussion_r1242685928
##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -827,7 +912,7 @@ mod tests {
(
"2020-09-08T13:42:29.190855Z",
"second",
- "2020-09-08T13:42:29.000000Z",
+ "2020-09-08T13:42:29.190855Z",
Review Comment:
This change doesn't seem correct to me -- the original value was correct
(truncated to microsecond). Do you know why it was changed? As written it still
has microsecond precision I think
##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -262,6 +268,53 @@ fn date_trunc_single(granularity: &str, value: i64) ->
Result<i64> {
Ok(value.unwrap().timestamp_nanos())
}
+fn _date_trunc(
+ tu: TimeUnit,
+ value: &Option<i64>,
+ granularity: &str,
+ f: impl Fn(Option<i64>) -> Result<Option<i64>>,
+ // tz_opt: &Option<Arc<str>>,
+) -> Result<Option<i64>, DataFusionError> {
+ let scale = match tu {
+ TimeUnit::Second => 1_000_000_000,
+ TimeUnit::Millisecond => 1_000_000,
+ TimeUnit::Microsecond => 1_000,
+ TimeUnit::Nanosecond => 1,
+ };
+
+ if value.is_none() {
+ return Ok(None);
+ }
Review Comment:
This works fine but I think you can simplify the logic with something like
the following (and then avoid all the unwraps)
```suggestion
let Some(value) = value else {
return Ok(None);
}
```
--
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]