Omega359 commented on code in PR #19078:
URL: https://github.com/apache/datafusion/pull/19078#discussion_r2636536554


##########
datafusion/functions/src/datetime/common.rs:
##########
@@ -176,14 +234,50 @@ pub(crate) fn string_to_timestamp_millis_formatted(s: 
&str, format: &str) -> Res
         .timestamp_millis())
 }
 
-pub(crate) fn handle<O, F, S>(
+pub(crate) struct ScalarDataType<T: PrimInt> {
+    data_type: DataType,
+    _marker: PhantomData<T>,
+}
+
+impl<T: PrimInt> ScalarDataType<T> {
+    pub(crate) fn new(dt: DataType) -> Self {
+        Self {
+            data_type: dt,
+            _marker: PhantomData,
+        }
+    }
+
+    fn scalar(&self, r: Option<i64>) -> Result<ScalarValue> {
+        match &self.data_type {
+            DataType::Date32 => Ok(ScalarValue::Date32(r.and_then(|v| 
v.to_i32()))),
+            DataType::Timestamp(u, tz) => match u {
+                TimeUnit::Second => Ok(ScalarValue::TimestampSecond(r, 
tz.clone())),
+                TimeUnit::Millisecond => {
+                    Ok(ScalarValue::TimestampMillisecond(r, tz.clone()))
+                }
+                TimeUnit::Microsecond => {
+                    Ok(ScalarValue::TimestampMicrosecond(r, tz.clone()))
+                }
+                TimeUnit::Nanosecond => {
+                    Ok(ScalarValue::TimestampNanosecond(r, tz.clone()))
+                }
+            },
+            t => Err(internal_datafusion_err!(
+                "Unsupported data type for ScalarDataType<T>: {t:?}"
+            )),

Review Comment:
   Hmm, I'll take a look at this. I'm currently working on a couple of other 
PR's as well so it may be a day or two.



-- 
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]

Reply via email to