comphead commented on code in PR #18390:
URL: https://github.com/apache/datafusion/pull/18390#discussion_r2482279145
##########
datafusion/functions/src/datetime/date_trunc.rs:
##########
@@ -47,6 +47,71 @@ use chrono::{
DateTime, Datelike, Duration, LocalResult, NaiveDateTime, Offset,
TimeDelta, Timelike,
};
+/// Represents the granularity for date truncation operations
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum DateTruncGranularity {
+ Microsecond,
+ Millisecond,
+ Second,
+ Minute,
+ Hour,
+ Day,
+ Week,
+ Month,
+ Quarter,
+ Year,
+}
+
+impl DateTruncGranularity {
+ /// Mapping of string representations to enum variants
+ const GRANULARITY_MAP: &[(&str, Self)] = &[
+ ("microsecond", Self::Microsecond),
+ ("millisecond", Self::Millisecond),
+ ("second", Self::Second),
+ ("minute", Self::Minute),
+ ("hour", Self::Hour),
+ ("day", Self::Day),
+ ("week", Self::Week),
+ ("month", Self::Month),
+ ("quarter", Self::Quarter),
+ ("year", Self::Year),
+ ];
+
+ /// Parse a granularity string into a DateTruncGranularity enum
+ fn from_str(s: &str) -> Result<Self> {
+ let s_lower = s.to_lowercase();
+ Self::GRANULARITY_MAP
+ .iter()
+ .find(|(key, _)| *key == s_lower.as_str())
Review Comment:
yeah, Rust still doesn't support const enums :(
--
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]