findepi commented on code in PR #16859: URL: https://github.com/apache/datafusion/pull/16859#discussion_r2229281161
########## datafusion/functions/src/datetime/date_trunc.rs: ########## @@ -185,6 +187,21 @@ impl ScalarUDFImpl for DateTruncFunc { ) -> Result<ColumnarValue> { let parsed_tz = parse_tz(tz_opt)?; let array = as_primitive_array::<T>(array)?; + + // fast path for fine granularities + if matches!( + granularity.as_str(), + "second" | "minute" | "millisecond" | "microsecond" + ) || (parsed_tz.is_none() && granularity.as_str() == "hour") + { + let result = general_date_trunc_array_fine_granularity( Review Comment: ```sql SELECT date_trunc('minute', arrow_cast('1910-01-01T00:00:00Z', 'Timestamp(Second, Some("Asia/Kathmandu"))')); SELECT date_trunc('minute', arrow_cast(v, 'Timestamp(Second, Some("Asia/Kathmandu"))')) FROM (VALUES ('1910-01-01T00:00:00Z')) t(v); ``` ``` +-----------------------------------------------------------------------------------------------------------------------+ | date_trunc(Utf8("minute"),arrow_cast(Utf8("1910-01-01T00:00:00Z"),Utf8("Timestamp(Second, Some("Asia/Kathmandu"))"))) | +-----------------------------------------------------------------------------------------------------------------------+ | 1910-01-01T05:41:16+05:41 | +-----------------------------------------------------------------------------------------------------------------------+ 1 row(s) fetched. Elapsed 0.065 seconds. +----------------------------------------------------------------------------------------------+ | date_trunc(Utf8("minute"),arrow_cast(t.v,Utf8("Timestamp(Second, Some("Asia/Kathmandu"))"))) | +----------------------------------------------------------------------------------------------+ | 1910-01-01T05:41:16+05:41 | +----------------------------------------------------------------------------------------------+ 1 row(s) fetched. Elapsed 0.012 seconds. ``` this doesn't look correct to me however, this is the same result as on `main`, so it's not a regression. Is it because the existing date_trunc code do similar logic as the new optimized code path? -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org