alamb commented on a change in pull request #493:
URL: https://github.com/apache/arrow-rs/pull/493#discussion_r656989067



##########
File path: arrow/src/compute/kernels/temporal.rs
##########
@@ -100,6 +100,72 @@ where
     Ok(b.finish())
 }
 
+/// Extracts the minutes of a given temporal array as an array of integers
+pub fn minute<T>(array: &PrimitiveArray<T>) -> Result<Int32Array>
+where
+    T: ArrowTemporalType + ArrowNumericType,
+    i64: std::convert::From<T::Native>,
+{
+    let mut b = Int32Builder::new(array.len());
+    match array.data_type() {
+        &DataType::Date64 | &DataType::Timestamp(_, _) => {
+            for i in 0..array.len() {
+                if array.is_null(i) {
+                    b.append_null()?;
+                } else {
+                    match array.value_as_datetime(i) {
+                        Some(dt) => b.append_value(dt.minute() as i32)?,
+                        None => b.append_null()?,
+                    }
+                }
+            }
+        }
+        dt => {
+            return {
+                Err(ArrowError::ComputeError(format!(
+                    "minute does not support type {:?}",
+                    dt
+                )))
+            }
+        }
+    }
+
+    Ok(b.finish())
+}
+
+/// Extracts the seconds of a given temporal array as an array of integers
+pub fn second<T>(array: &PrimitiveArray<T>) -> Result<Int32Array>
+where
+    T: ArrowTemporalType + ArrowNumericType,
+    i64: std::convert::From<T::Native>,
+{
+    let mut b = Int32Builder::new(array.len());
+    match array.data_type() {
+        &DataType::Date64 | &DataType::Timestamp(_, _) => {

Review comment:
       🤔  In general I think Rust/Arrow and DataFusion's support for timezone 
aware timestamps is pretty poor. I wonder if we could perhaps change this to 
`DataType::Timestamp(_, None)` and error if `DataType::Timestamp(_, Some(tz))`




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to