@@ -1817,43 +1817,11 @@ where
1817
1817
{
1818
1818
let units = a. unwrap_str ( ) ;
1819
1819
match units. parse ( ) {
1820
- Ok ( units) => date_trunc_inner ( units, ts) ,
1820
+ Ok ( units) => Ok ( date_trunc_inner ( units, ts) ? . into ( ) ) ,
1821
1821
Err ( _) => Err ( EvalError :: UnknownUnits ( units. to_owned ( ) ) ) ,
1822
1822
}
1823
1823
}
1824
1824
1825
- fn date_trunc_inner < ' a , T > ( units : DateTimeUnits , ts : T ) -> Result < Datum < ' a > , EvalError >
1826
- where
1827
- T : TimestampLike ,
1828
- {
1829
- match units {
1830
- DateTimeUnits :: Millennium => Ok ( ts. truncate_millennium ( ) . into ( ) ) ,
1831
- DateTimeUnits :: Century => Ok ( ts. truncate_century ( ) . into ( ) ) ,
1832
- DateTimeUnits :: Decade => Ok ( ts. truncate_decade ( ) . into ( ) ) ,
1833
- DateTimeUnits :: Year => Ok ( ts. truncate_year ( ) . into ( ) ) ,
1834
- DateTimeUnits :: Quarter => Ok ( ts. truncate_quarter ( ) . into ( ) ) ,
1835
- DateTimeUnits :: Week => Ok ( ts. truncate_week ( ) ?. into ( ) ) ,
1836
- DateTimeUnits :: Day => Ok ( ts. truncate_day ( ) . into ( ) ) ,
1837
- DateTimeUnits :: Hour => Ok ( ts. truncate_hour ( ) . into ( ) ) ,
1838
- DateTimeUnits :: Minute => Ok ( ts. truncate_minute ( ) . into ( ) ) ,
1839
- DateTimeUnits :: Second => Ok ( ts. truncate_second ( ) . into ( ) ) ,
1840
- DateTimeUnits :: Month => Ok ( ts. truncate_month ( ) . into ( ) ) ,
1841
- DateTimeUnits :: Milliseconds => Ok ( ts. truncate_milliseconds ( ) . into ( ) ) ,
1842
- DateTimeUnits :: Microseconds => Ok ( ts. truncate_microseconds ( ) . into ( ) ) ,
1843
- DateTimeUnits :: Epoch
1844
- | DateTimeUnits :: Timezone
1845
- | DateTimeUnits :: TimezoneHour
1846
- | DateTimeUnits :: TimezoneMinute
1847
- | DateTimeUnits :: DayOfWeek
1848
- | DateTimeUnits :: DayOfYear
1849
- | DateTimeUnits :: IsoDayOfWeek
1850
- | DateTimeUnits :: IsoDayOfYear => Err ( EvalError :: Unsupported {
1851
- feature : format ! ( "'{}' timestamp units" , units) ,
1852
- issue_no : None ,
1853
- } ) ,
1854
- }
1855
- }
1856
-
1857
1825
fn date_trunc_interval < ' a > ( a : Datum , b : Datum ) -> Result < Datum < ' a > , EvalError > {
1858
1826
let mut interval = b. unwrap_interval ( ) ;
1859
1827
let units = a. unwrap_str ( ) ;
@@ -1883,40 +1851,6 @@ fn timezone_time(tz: Timezone, t: NaiveTime, wall_time: &NaiveDateTime) -> Datum
1883
1851
( t + offset) . into ( )
1884
1852
}
1885
1853
1886
- /// Converts the timestamp `dt`, which is assumed to be in the time of the timezone `tz` to a timestamptz in UTC.
1887
- /// This operation is fallible because certain timestamps at timezones that observe DST are simply impossible or
1888
- /// ambiguous. In case of ambiguity (when a hour repeats) we will prefer the latest variant, and when an hour is
1889
- /// impossible, we will attempt to fix it by advancing it. For example, `EST` and `2020-11-11T12:39:14` would return
1890
- /// `2020-11-11T17:39:14Z`. A DST observing timezone like `America/New_York` would cause the following DST anomalies:
1891
- /// `2020-11-01T00:59:59` -> `2020-11-01T04:59:59Z` and `2020-11-01T01:00:00` -> `2020-11-01T06:00:00Z`
1892
- /// `2020-03-08T02:59:59` -> `2020-03-08T07:59:59Z` and `2020-03-08T03:00:00` -> `2020-03-08T07:00:00Z`
1893
- fn timezone_timestamp ( tz : Timezone , mut dt : NaiveDateTime ) -> Result < Datum < ' static > , EvalError > {
1894
- let offset = match tz {
1895
- Timezone :: FixedOffset ( offset) => offset,
1896
- Timezone :: Tz ( tz) => match tz. offset_from_local_datetime ( & dt) . latest ( ) {
1897
- Some ( offset) => offset. fix ( ) ,
1898
- None => {
1899
- dt += Duration :: hours ( 1 ) ;
1900
- tz. offset_from_local_datetime ( & dt)
1901
- . latest ( )
1902
- . ok_or ( EvalError :: InvalidTimezoneConversion ) ?
1903
- . fix ( )
1904
- }
1905
- } ,
1906
- } ;
1907
- Ok ( DateTime :: from_utc ( dt - offset, Utc ) . into ( ) )
1908
- }
1909
-
1910
- /// Converts the UTC timestamptz `utc` to the local timestamp of the timezone `tz`.
1911
- /// For example, `EST` and `2020-11-11T17:39:14Z` would return `2020-11-11T12:39:14`.
1912
- fn timezone_timestamptz ( tz : Timezone , utc : DateTime < Utc > ) -> Datum < ' static > {
1913
- let offset = match tz {
1914
- Timezone :: FixedOffset ( offset) => offset,
1915
- Timezone :: Tz ( tz) => tz. offset_from_utc_datetime ( & utc. naive_utc ( ) ) . fix ( ) ,
1916
- } ;
1917
- ( utc. naive_utc ( ) + offset) . into ( )
1918
- }
1919
-
1920
1854
/// Converts the time datum `b`, which is assumed to be in UTC, to the timezone that the interval datum `a` is assumed
1921
1855
/// to represent. The interval is not allowed to hold months, but there are no limits on the amount of seconds.
1922
1856
/// The interval acts like a `chrono::FixedOffset`, without the `-86,400 < x < 86,400` limitation.
@@ -2274,11 +2208,11 @@ impl BinaryFunc {
2274
2208
}
2275
2209
BinaryFunc :: TimezoneTimestamp => {
2276
2210
eager ! ( |a: Datum , b: Datum | parse_timezone( a. unwrap_str( ) )
2277
- . and_then( |tz| timezone_timestamp( tz, b. unwrap_timestamp( ) ) ) )
2211
+ . and_then( |tz| Ok ( timezone_timestamp( tz, b. unwrap_timestamp( ) ) ? . into ( ) ) ) )
2278
2212
}
2279
2213
BinaryFunc :: TimezoneTimestampTz => {
2280
2214
eager ! ( |a: Datum , b: Datum | parse_timezone( a. unwrap_str( ) )
2281
- . map( |tz| timezone_timestamptz( tz, b. unwrap_timestamptz( ) ) ) )
2215
+ . map( |tz| timezone_timestamptz( tz, b. unwrap_timestamptz( ) ) . into ( ) ) )
2282
2216
}
2283
2217
BinaryFunc :: TimezoneTime { wall_time } => {
2284
2218
eager ! (
@@ -3155,14 +3089,14 @@ pub enum UnaryFunc {
3155
3089
ExtractTimestampTz ( ExtractTimestampTz ) ,
3156
3090
DatePartTimestamp ( DatePartTimestamp ) ,
3157
3091
DatePartTimestampTz ( DatePartTimestampTz ) ,
3092
+ DateTruncTimestamp ( DateTruncTimestamp ) ,
3093
+ DateTruncTimestampTz ( DateTruncTimestampTz ) ,
3094
+ TimezoneTimestamp ( TimezoneTimestamp ) ,
3095
+ TimezoneTimestampTz ( TimezoneTimestampTz ) ,
3158
3096
3159
3097
ExtractDate ( DateTimeUnits ) ,
3160
3098
ExtractTime ( DateTimeUnits ) ,
3161
3099
DatePartTime ( DateTimeUnits ) ,
3162
- DateTruncTimestamp ( DateTimeUnits ) ,
3163
- DateTruncTimestampTz ( DateTimeUnits ) ,
3164
- TimezoneTimestamp ( Timezone ) ,
3165
- TimezoneTimestampTz ( Timezone ) ,
3166
3100
TimezoneTime {
3167
3101
tz : Timezone ,
3168
3102
wall_time : NaiveDateTime ,
@@ -3410,7 +3344,11 @@ derive_unary!(
3410
3344
ExtractTimestamp ,
3411
3345
ExtractTimestampTz ,
3412
3346
DatePartTimestamp ,
3413
- DatePartTimestampTz
3347
+ DatePartTimestampTz ,
3348
+ DateTruncTimestamp ,
3349
+ DateTruncTimestampTz ,
3350
+ TimezoneTimestamp ,
3351
+ TimezoneTimestampTz
3414
3352
) ;
3415
3353
3416
3354
impl UnaryFunc {
@@ -3621,6 +3559,10 @@ impl UnaryFunc {
3621
3559
| ExtractTimestampTz ( _)
3622
3560
| DatePartTimestamp ( _)
3623
3561
| DatePartTimestampTz ( _)
3562
+ | DateTruncTimestamp ( _)
3563
+ | DateTruncTimestampTz ( _)
3564
+ | TimezoneTimestamp ( _)
3565
+ | TimezoneTimestampTz ( _)
3624
3566
| Chr ( _) => unreachable ! ( ) ,
3625
3567
CastRecordToString { ty }
3626
3568
| CastArrayToString { ty }
@@ -3636,10 +3578,6 @@ impl UnaryFunc {
3636
3578
ExtractTime ( units) => date_part_time_inner :: < Numeric > ( * units, a) ,
3637
3579
ExtractDate ( units) => extract_date_inner ( * units, a) ,
3638
3580
DatePartTime ( units) => date_part_time_inner :: < f64 > ( * units, a) ,
3639
- DateTruncTimestamp ( units) => date_trunc_inner ( * units, a. unwrap_timestamp ( ) ) ,
3640
- DateTruncTimestampTz ( units) => date_trunc_inner ( * units, a. unwrap_timestamptz ( ) ) ,
3641
- TimezoneTimestamp ( tz) => timezone_timestamp ( * tz, a. unwrap_timestamp ( ) ) ,
3642
- TimezoneTimestampTz ( tz) => Ok ( timezone_timestamptz ( * tz, a. unwrap_timestamptz ( ) ) ) ,
3643
3581
TimezoneTime { tz, wall_time } => Ok ( timezone_time ( * tz, a. unwrap_time ( ) , wall_time) ) ,
3644
3582
RecordGet ( i) => Ok ( record_get ( a, * i) ) ,
3645
3583
ListLength => list_length ( a) ,
@@ -3852,6 +3790,10 @@ impl UnaryFunc {
3852
3790
| ExtractTimestampTz ( _)
3853
3791
| DatePartTimestamp ( _)
3854
3792
| DatePartTimestampTz ( _)
3793
+ | DateTruncTimestamp ( _)
3794
+ | DateTruncTimestampTz ( _)
3795
+ | TimezoneTimestamp ( _)
3796
+ | TimezoneTimestampTz ( _)
3855
3797
| Chr ( _) => unreachable ! ( ) ,
3856
3798
3857
3799
CastRecordToString { .. }
@@ -3862,10 +3804,6 @@ impl UnaryFunc {
3862
3804
3863
3805
TimezoneTime { .. } => ScalarType :: Time . nullable ( nullable) ,
3864
3806
3865
- TimezoneTimestampTz ( _) => ScalarType :: Timestamp . nullable ( nullable) ,
3866
-
3867
- TimezoneTimestamp ( _) => ScalarType :: TimestampTz . nullable ( nullable) ,
3868
-
3869
3807
CastRecord1ToRecord2 { return_ty, .. } => {
3870
3808
return_ty. without_modifiers ( ) . nullable ( nullable)
3871
3809
}
@@ -3878,9 +3816,6 @@ impl UnaryFunc {
3878
3816
3879
3817
DatePartTime ( _) => ScalarType :: Float64 . nullable ( nullable) ,
3880
3818
3881
- DateTruncTimestamp ( _) => ScalarType :: Timestamp . nullable ( nullable) ,
3882
- DateTruncTimestampTz ( _) => ScalarType :: TimestampTz . nullable ( nullable) ,
3883
-
3884
3819
RecordGet ( i) => match input_type. scalar_type {
3885
3820
ScalarType :: Record { mut fields, .. } => {
3886
3821
let ( _name, mut ty) = fields. swap_remove ( * i) ;
@@ -4106,6 +4041,10 @@ impl UnaryFunc {
4106
4041
| ExtractTimestampTz ( _)
4107
4042
| DatePartTimestamp ( _)
4108
4043
| DatePartTimestampTz ( _)
4044
+ | DateTruncTimestamp ( _)
4045
+ | DateTruncTimestampTz ( _)
4046
+ | TimezoneTimestamp ( _)
4047
+ | TimezoneTimestampTz ( _)
4109
4048
| Chr ( _) => unreachable ! ( ) ,
4110
4049
// Return null if the inner field is null
4111
4050
RecordGet ( _) => true ,
@@ -4116,13 +4055,10 @@ impl UnaryFunc {
4116
4055
| CastMapToString { .. }
4117
4056
| CastInt2VectorToString => false ,
4118
4057
TimezoneTime { .. } => false ,
4119
- TimezoneTimestampTz ( _) => false ,
4120
- TimezoneTimestamp ( _) => false ,
4121
4058
CastList1ToList2 { .. } | CastRecord1ToRecord2 { .. } => false ,
4122
4059
ListLength | MapLength => false ,
4123
4060
ExtractTime ( _) | ExtractDate ( _) => false ,
4124
4061
DatePartTime ( _) => false ,
4125
- DateTruncTimestamp ( _) | DateTruncTimestampTz ( _) => false ,
4126
4062
RescaleNumeric ( _) => false ,
4127
4063
}
4128
4064
}
@@ -4230,6 +4166,10 @@ impl UnaryFunc {
4230
4166
| ExtractTimestampTz ( _)
4231
4167
| DatePartTimestamp ( _)
4232
4168
| DatePartTimestampTz ( _)
4169
+ | DateTruncTimestamp ( _)
4170
+ | DateTruncTimestampTz ( _)
4171
+ | TimezoneTimestamp ( _)
4172
+ | TimezoneTimestampTz ( _)
4233
4173
| CastVarCharToString ( _) => unreachable ! ( ) ,
4234
4174
_ => false ,
4235
4175
}
@@ -4432,6 +4372,10 @@ impl UnaryFunc {
4432
4372
| ExtractTimestampTz ( _)
4433
4373
| DatePartTimestamp ( _)
4434
4374
| DatePartTimestampTz ( _)
4375
+ | DateTruncTimestamp ( _)
4376
+ | DateTruncTimestampTz ( _)
4377
+ | TimezoneTimestamp ( _)
4378
+ | TimezoneTimestampTz ( _)
4435
4379
| Chr ( _) => unreachable ! ( ) ,
4436
4380
CastRecordToString { .. } => f. write_str ( "recordtostr" ) ,
4437
4381
CastRecord1ToRecord2 { .. } => f. write_str ( "record1torecord2" ) ,
@@ -4443,10 +4387,6 @@ impl UnaryFunc {
4443
4387
ExtractTime ( units) => write ! ( f, "extract_{}_t" , units) ,
4444
4388
ExtractDate ( units) => write ! ( f, "extract_{}_d" , units) ,
4445
4389
DatePartTime ( units) => write ! ( f, "date_part_{}_t" , units) ,
4446
- DateTruncTimestamp ( units) => write ! ( f, "date_trunc_{}_ts" , units) ,
4447
- DateTruncTimestampTz ( units) => write ! ( f, "date_trunc_{}_tstz" , units) ,
4448
- TimezoneTimestamp ( tz) => write ! ( f, "timezone_{}_ts" , tz) ,
4449
- TimezoneTimestampTz ( tz) => write ! ( f, "timezone_{}_tstz" , tz) ,
4450
4390
TimezoneTime { tz, .. } => write ! ( f, "timezone_{}_t" , tz) ,
4451
4391
RecordGet ( i) => write ! ( f, "record_get[{}]" , i) ,
4452
4392
ListLength => f. write_str ( "list_length" ) ,
0 commit comments