@@ -1877,43 +1877,11 @@ where
1877
1877
{
1878
1878
let units = a. unwrap_str ( ) ;
1879
1879
match units. parse ( ) {
1880
- Ok ( units) => date_trunc_inner ( units, ts) ,
1880
+ Ok ( units) => Ok ( date_trunc_inner ( units, ts) ? . into ( ) ) ,
1881
1881
Err ( _) => Err ( EvalError :: UnknownUnits ( units. to_owned ( ) ) ) ,
1882
1882
}
1883
1883
}
1884
1884
1885
- fn date_trunc_inner < ' a , T > ( units : DateTimeUnits , ts : T ) -> Result < Datum < ' a > , EvalError >
1886
- where
1887
- T : TimestampLike ,
1888
- {
1889
- match units {
1890
- DateTimeUnits :: Millennium => Ok ( ts. truncate_millennium ( ) . into ( ) ) ,
1891
- DateTimeUnits :: Century => Ok ( ts. truncate_century ( ) . into ( ) ) ,
1892
- DateTimeUnits :: Decade => Ok ( ts. truncate_decade ( ) . into ( ) ) ,
1893
- DateTimeUnits :: Year => Ok ( ts. truncate_year ( ) . into ( ) ) ,
1894
- DateTimeUnits :: Quarter => Ok ( ts. truncate_quarter ( ) . into ( ) ) ,
1895
- DateTimeUnits :: Week => Ok ( ts. truncate_week ( ) ?. into ( ) ) ,
1896
- DateTimeUnits :: Day => Ok ( ts. truncate_day ( ) . into ( ) ) ,
1897
- DateTimeUnits :: Hour => Ok ( ts. truncate_hour ( ) . into ( ) ) ,
1898
- DateTimeUnits :: Minute => Ok ( ts. truncate_minute ( ) . into ( ) ) ,
1899
- DateTimeUnits :: Second => Ok ( ts. truncate_second ( ) . into ( ) ) ,
1900
- DateTimeUnits :: Month => Ok ( ts. truncate_month ( ) . into ( ) ) ,
1901
- DateTimeUnits :: Milliseconds => Ok ( ts. truncate_milliseconds ( ) . into ( ) ) ,
1902
- DateTimeUnits :: Microseconds => Ok ( ts. truncate_microseconds ( ) . into ( ) ) ,
1903
- DateTimeUnits :: Epoch
1904
- | DateTimeUnits :: Timezone
1905
- | DateTimeUnits :: TimezoneHour
1906
- | DateTimeUnits :: TimezoneMinute
1907
- | DateTimeUnits :: DayOfWeek
1908
- | DateTimeUnits :: DayOfYear
1909
- | DateTimeUnits :: IsoDayOfWeek
1910
- | DateTimeUnits :: IsoDayOfYear => Err ( EvalError :: Unsupported {
1911
- feature : format ! ( "'{}' timestamp units" , units) ,
1912
- issue_no : None ,
1913
- } ) ,
1914
- }
1915
- }
1916
-
1917
1885
fn date_trunc_interval < ' a > ( a : Datum , b : Datum ) -> Result < Datum < ' a > , EvalError > {
1918
1886
let mut interval = b. unwrap_interval ( ) ;
1919
1887
let units = a. unwrap_str ( ) ;
@@ -1943,40 +1911,6 @@ fn timezone_time(tz: Timezone, t: NaiveTime, wall_time: &NaiveDateTime) -> Datum
1943
1911
( t + offset) . into ( )
1944
1912
}
1945
1913
1946
- /// Converts the timestamp `dt`, which is assumed to be in the time of the timezone `tz` to a timestamptz in UTC.
1947
- /// This operation is fallible because certain timestamps at timezones that observe DST are simply impossible or
1948
- /// ambiguous. In case of ambiguity (when a hour repeats) we will prefer the latest variant, and when an hour is
1949
- /// impossible, we will attempt to fix it by advancing it. For example, `EST` and `2020-11-11T12:39:14` would return
1950
- /// `2020-11-11T17:39:14Z`. A DST observing timezone like `America/New_York` would cause the following DST anomalies:
1951
- /// `2020-11-01T00:59:59` -> `2020-11-01T04:59:59Z` and `2020-11-01T01:00:00` -> `2020-11-01T06:00:00Z`
1952
- /// `2020-03-08T02:59:59` -> `2020-03-08T07:59:59Z` and `2020-03-08T03:00:00` -> `2020-03-08T07:00:00Z`
1953
- fn timezone_timestamp ( tz : Timezone , mut dt : NaiveDateTime ) -> Result < Datum < ' static > , EvalError > {
1954
- let offset = match tz {
1955
- Timezone :: FixedOffset ( offset) => offset,
1956
- Timezone :: Tz ( tz) => match tz. offset_from_local_datetime ( & dt) . latest ( ) {
1957
- Some ( offset) => offset. fix ( ) ,
1958
- None => {
1959
- dt += Duration :: hours ( 1 ) ;
1960
- tz. offset_from_local_datetime ( & dt)
1961
- . latest ( )
1962
- . ok_or ( EvalError :: InvalidTimezoneConversion ) ?
1963
- . fix ( )
1964
- }
1965
- } ,
1966
- } ;
1967
- Ok ( DateTime :: from_utc ( dt - offset, Utc ) . into ( ) )
1968
- }
1969
-
1970
- /// Converts the UTC timestamptz `utc` to the local timestamp of the timezone `tz`.
1971
- /// For example, `EST` and `2020-11-11T17:39:14Z` would return `2020-11-11T12:39:14`.
1972
- fn timezone_timestamptz ( tz : Timezone , utc : DateTime < Utc > ) -> Datum < ' static > {
1973
- let offset = match tz {
1974
- Timezone :: FixedOffset ( offset) => offset,
1975
- Timezone :: Tz ( tz) => tz. offset_from_utc_datetime ( & utc. naive_utc ( ) ) . fix ( ) ,
1976
- } ;
1977
- ( utc. naive_utc ( ) + offset) . into ( )
1978
- }
1979
-
1980
1914
/// Converts the time datum `b`, which is assumed to be in UTC, to the timezone that the interval datum `a` is assumed
1981
1915
/// to represent. The interval is not allowed to hold months, but there are no limits on the amount of seconds.
1982
1916
/// The interval acts like a `chrono::FixedOffset`, without the `-86,400 < x < 86,400` limitation.
@@ -2334,11 +2268,11 @@ impl BinaryFunc {
2334
2268
}
2335
2269
BinaryFunc :: TimezoneTimestamp => {
2336
2270
eager ! ( |a: Datum , b: Datum | parse_timezone( a. unwrap_str( ) )
2337
- . and_then( |tz| timezone_timestamp( tz, b. unwrap_timestamp( ) ) ) )
2271
+ . and_then( |tz| Ok ( timezone_timestamp( tz, b. unwrap_timestamp( ) ) ? . into ( ) ) ) )
2338
2272
}
2339
2273
BinaryFunc :: TimezoneTimestampTz => {
2340
2274
eager ! ( |a: Datum , b: Datum | parse_timezone( a. unwrap_str( ) )
2341
- . map( |tz| timezone_timestamptz( tz, b. unwrap_timestamptz( ) ) ) )
2275
+ . map( |tz| timezone_timestamptz( tz, b. unwrap_timestamptz( ) ) . into ( ) ) )
2342
2276
}
2343
2277
BinaryFunc :: TimezoneTime { wall_time } => {
2344
2278
eager ! (
@@ -3215,14 +3149,14 @@ pub enum UnaryFunc {
3215
3149
ExtractTimestampTz ( ExtractTimestampTz ) ,
3216
3150
DatePartTimestamp ( DatePartTimestamp ) ,
3217
3151
DatePartTimestampTz ( DatePartTimestampTz ) ,
3152
+ DateTruncTimestamp ( DateTruncTimestamp ) ,
3153
+ DateTruncTimestampTz ( DateTruncTimestampTz ) ,
3154
+ TimezoneTimestamp ( TimezoneTimestamp ) ,
3155
+ TimezoneTimestampTz ( TimezoneTimestampTz ) ,
3218
3156
3219
3157
ExtractDate ( DateTimeUnits ) ,
3220
3158
ExtractTime ( DateTimeUnits ) ,
3221
3159
DatePartTime ( DateTimeUnits ) ,
3222
- DateTruncTimestamp ( DateTimeUnits ) ,
3223
- DateTruncTimestampTz ( DateTimeUnits ) ,
3224
- TimezoneTimestamp ( Timezone ) ,
3225
- TimezoneTimestampTz ( Timezone ) ,
3226
3160
TimezoneTime {
3227
3161
tz : Timezone ,
3228
3162
wall_time : NaiveDateTime ,
@@ -3532,7 +3466,11 @@ derive_unary!(
3532
3466
ExtractTimestamp ,
3533
3467
ExtractTimestampTz ,
3534
3468
DatePartTimestamp ,
3535
- DatePartTimestampTz
3469
+ DatePartTimestampTz ,
3470
+ DateTruncTimestamp ,
3471
+ DateTruncTimestampTz ,
3472
+ TimezoneTimestamp ,
3473
+ TimezoneTimestampTz
3536
3474
) ;
3537
3475
3538
3476
impl UnaryFunc {
@@ -3743,6 +3681,10 @@ impl UnaryFunc {
3743
3681
| ExtractTimestampTz ( _)
3744
3682
| DatePartTimestamp ( _)
3745
3683
| DatePartTimestampTz ( _)
3684
+ | DateTruncTimestamp ( _)
3685
+ | DateTruncTimestampTz ( _)
3686
+ | TimezoneTimestamp ( _)
3687
+ | TimezoneTimestampTz ( _)
3746
3688
| Chr ( _) => unreachable ! ( ) ,
3747
3689
CastRecordToString { ty }
3748
3690
| CastArrayToString { ty }
@@ -3758,10 +3700,6 @@ impl UnaryFunc {
3758
3700
ExtractTime ( units) => date_part_time_inner :: < Numeric > ( * units, a) ,
3759
3701
ExtractDate ( units) => extract_date_inner ( * units, a) ,
3760
3702
DatePartTime ( units) => date_part_time_inner :: < f64 > ( * units, a) ,
3761
- DateTruncTimestamp ( units) => date_trunc_inner ( * units, a. unwrap_timestamp ( ) ) ,
3762
- DateTruncTimestampTz ( units) => date_trunc_inner ( * units, a. unwrap_timestamptz ( ) ) ,
3763
- TimezoneTimestamp ( tz) => timezone_timestamp ( * tz, a. unwrap_timestamp ( ) ) ,
3764
- TimezoneTimestampTz ( tz) => Ok ( timezone_timestamptz ( * tz, a. unwrap_timestamptz ( ) ) ) ,
3765
3703
TimezoneTime { tz, wall_time } => Ok ( timezone_time ( * tz, a. unwrap_time ( ) , wall_time) ) ,
3766
3704
RecordGet ( i) => Ok ( record_get ( a, * i) ) ,
3767
3705
ListLength => list_length ( a) ,
@@ -3974,6 +3912,10 @@ impl UnaryFunc {
3974
3912
| ExtractTimestampTz ( _)
3975
3913
| DatePartTimestamp ( _)
3976
3914
| DatePartTimestampTz ( _)
3915
+ | DateTruncTimestamp ( _)
3916
+ | DateTruncTimestampTz ( _)
3917
+ | TimezoneTimestamp ( _)
3918
+ | TimezoneTimestampTz ( _)
3977
3919
| Chr ( _) => unreachable ! ( ) ,
3978
3920
3979
3921
CastRecordToString { .. }
@@ -3984,10 +3926,6 @@ impl UnaryFunc {
3984
3926
3985
3927
TimezoneTime { .. } => ScalarType :: Time . nullable ( nullable) ,
3986
3928
3987
- TimezoneTimestampTz ( _) => ScalarType :: Timestamp . nullable ( nullable) ,
3988
-
3989
- TimezoneTimestamp ( _) => ScalarType :: TimestampTz . nullable ( nullable) ,
3990
-
3991
3929
CastRecord1ToRecord2 { return_ty, .. } => {
3992
3930
return_ty. without_modifiers ( ) . nullable ( nullable)
3993
3931
}
@@ -4000,9 +3938,6 @@ impl UnaryFunc {
4000
3938
4001
3939
DatePartTime ( _) => ScalarType :: Float64 . nullable ( nullable) ,
4002
3940
4003
- DateTruncTimestamp ( _) => ScalarType :: Timestamp . nullable ( nullable) ,
4004
- DateTruncTimestampTz ( _) => ScalarType :: TimestampTz . nullable ( nullable) ,
4005
-
4006
3941
RecordGet ( i) => match input_type. scalar_type {
4007
3942
ScalarType :: Record { mut fields, .. } => {
4008
3943
let ( _name, mut ty) = fields. swap_remove ( * i) ;
@@ -4228,6 +4163,10 @@ impl UnaryFunc {
4228
4163
| ExtractTimestampTz ( _)
4229
4164
| DatePartTimestamp ( _)
4230
4165
| DatePartTimestampTz ( _)
4166
+ | DateTruncTimestamp ( _)
4167
+ | DateTruncTimestampTz ( _)
4168
+ | TimezoneTimestamp ( _)
4169
+ | TimezoneTimestampTz ( _)
4231
4170
| Chr ( _) => unreachable ! ( ) ,
4232
4171
// Return null if the inner field is null
4233
4172
RecordGet ( _) => true ,
@@ -4238,13 +4177,10 @@ impl UnaryFunc {
4238
4177
| CastMapToString { .. }
4239
4178
| CastInt2VectorToString => false ,
4240
4179
TimezoneTime { .. } => false ,
4241
- TimezoneTimestampTz ( _) => false ,
4242
- TimezoneTimestamp ( _) => false ,
4243
4180
CastList1ToList2 { .. } | CastRecord1ToRecord2 { .. } => false ,
4244
4181
ListLength | MapLength => false ,
4245
4182
ExtractTime ( _) | ExtractDate ( _) => false ,
4246
4183
DatePartTime ( _) => false ,
4247
- DateTruncTimestamp ( _) | DateTruncTimestampTz ( _) => false ,
4248
4184
RescaleNumeric ( _) => false ,
4249
4185
}
4250
4186
}
@@ -4352,6 +4288,10 @@ impl UnaryFunc {
4352
4288
| ExtractTimestampTz ( _)
4353
4289
| DatePartTimestamp ( _)
4354
4290
| DatePartTimestampTz ( _)
4291
+ | DateTruncTimestamp ( _)
4292
+ | DateTruncTimestampTz ( _)
4293
+ | TimezoneTimestamp ( _)
4294
+ | TimezoneTimestampTz ( _)
4355
4295
| CastVarCharToString ( _) => unreachable ! ( ) ,
4356
4296
_ => false ,
4357
4297
}
@@ -4554,6 +4494,10 @@ impl UnaryFunc {
4554
4494
| ExtractTimestampTz ( _)
4555
4495
| DatePartTimestamp ( _)
4556
4496
| DatePartTimestampTz ( _)
4497
+ | DateTruncTimestamp ( _)
4498
+ | DateTruncTimestampTz ( _)
4499
+ | TimezoneTimestamp ( _)
4500
+ | TimezoneTimestampTz ( _)
4557
4501
| Chr ( _) => unreachable ! ( ) ,
4558
4502
CastRecordToString { .. } => f. write_str ( "recordtostr" ) ,
4559
4503
CastRecord1ToRecord2 { .. } => f. write_str ( "record1torecord2" ) ,
@@ -4565,10 +4509,6 @@ impl UnaryFunc {
4565
4509
ExtractTime ( units) => write ! ( f, "extract_{}_t" , units) ,
4566
4510
ExtractDate ( units) => write ! ( f, "extract_{}_d" , units) ,
4567
4511
DatePartTime ( units) => write ! ( f, "date_part_{}_t" , units) ,
4568
- DateTruncTimestamp ( units) => write ! ( f, "date_trunc_{}_ts" , units) ,
4569
- DateTruncTimestampTz ( units) => write ! ( f, "date_trunc_{}_tstz" , units) ,
4570
- TimezoneTimestamp ( tz) => write ! ( f, "timezone_{}_ts" , tz) ,
4571
- TimezoneTimestampTz ( tz) => write ! ( f, "timezone_{}_tstz" , tz) ,
4572
4512
TimezoneTime { tz, .. } => write ! ( f, "timezone_{}_t" , tz) ,
4573
4513
RecordGet ( i) => write ! ( f, "record_get[{}]" , i) ,
4574
4514
ListLength => f. write_str ( "list_length" ) ,
0 commit comments