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/07/13 10:47:38 UTC

[GitHub] [arrow-rs] alamb commented on a diff in pull request #2052: feat(compute): Support week0 (PostgreSQL behaviour) for temporal

alamb commented on code in PR #2052:
URL: https://github.com/apache/arrow-rs/pull/2052#discussion_r919932672


##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -112,31 +112,28 @@ macro_rules! return_compute_error_with {
     };
 }
 
-trait ChronoDateQuarter {
+// Internal trait, which is used for mapping values from DateLike structures
+trait ChronoDateExt {
     /// Returns a value in range `1..=4` indicating the quarter this date falls into
     fn quarter(&self) -> u32;
 
     /// Returns a value in range `0..=3` indicating the quarter (zero-based) this date falls into
     fn quarter0(&self) -> u32;
+
+    fn weekday0(&self) -> i32;

Review Comment:
   ```suggestion
       /// Returns the day of week; Sunday is encoded as `0`, Monday as `1`, etc.
       fn weekday0(&self) -> i32;
   ```



##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -298,6 +295,37 @@ where
     Ok(b.finish())
 }
 
+/// Extracts the day of week of a given temporal array as an array of
+/// integers.

Review Comment:
   ```suggestion
   /// integers, starting at Sunday. This is different than [`weekday`] which starts at Monday.
   ```



##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -112,31 +112,28 @@ macro_rules! return_compute_error_with {
     };
 }
 
-trait ChronoDateQuarter {
+// Internal trait, which is used for mapping values from DateLike structures
+trait ChronoDateExt {
     /// Returns a value in range `1..=4` indicating the quarter this date falls into
     fn quarter(&self) -> u32;
 
     /// Returns a value in range `0..=3` indicating the quarter (zero-based) this date falls into
     fn quarter0(&self) -> u32;
+
+    fn weekday0(&self) -> i32;
 }
 
-impl ChronoDateQuarter for NaiveDateTime {
+impl<T: Datelike> ChronoDateExt for T {
     fn quarter(&self) -> u32 {
         self.quarter0() + 1
     }
 
     fn quarter0(&self) -> u32 {
         self.month0() / 3
     }
-}
-
-impl ChronoDateQuarter for NaiveDate {
-    fn quarter(&self) -> u32 {
-        self.quarter0() + 1
-    }
 
-    fn quarter0(&self) -> u32 {
-        self.month0() / 3
+    fn weekday0(&self) -> i32 {
+        self.weekday().num_days_from_sunday() as i32

Review Comment:
   🤔  now I see that chrono uses the names `num_days_from_sunday` and `num_days_from_monday`
   
   https://docs.rs/chrono/0.4.19/chrono/enum.Weekday.html#method.num_days_from_sunday
   https://docs.rs/chrono/0.4.19/chrono/enum.Weekday.html#method.num_days_from_monday
   
   What would  you think about using those names instead of `weekday0` and `weekday` @ovr  (I would be happy to rename things in a follow on PR prior to release)?



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