You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/24 17:58:22 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2786: wip: Implement extract epoch

alamb commented on code in PR #2786:
URL: https://github.com/apache/arrow-datafusion/pull/2786#discussion_r906281699


##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -356,8 +360,9 @@ pub fn date_part(args: &[ColumnarValue]) -> Result<ColumnarValue> {
         "hour" => extract_date_part!(array, temporal::hour),
         "minute" => extract_date_part!(array, temporal::minute),
         "second" => extract_date_part!(array, temporal::second),
+        "epoch" => extract_date_part!(array, extract_epoch),
         _ => Err(DataFusionError::Execution(format!(
-            "Date part '{}' not supported",
+            "Date partx '{}' not supported",

Review Comment:
   ```suggestion
               "Date part '{}' not supported",
   ```



##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -372,6 +377,40 @@ pub fn date_part(args: &[ColumnarValue]) -> Result<ColumnarValue> {
     })
 }
 
+fn extract_epoch<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::Timestamp(ref unit, _) => {
+            for i in 0..array.len() {
+                if array.is_null(i) {
+                    b.append_null()?;
+                } else {
+                    let scale = match unit {

Review Comment:
   I would recommend using the `chrono` functions for this, such as done here:
   
   https://sourcegraph.com/github.com/apache/arrow-rs/-/blob/arrow/src/compute/kernels/temporal.rs?L214-240&subtree=true
   
   



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org