@@ -19,7 +19,6 @@ use std::hash::{Hash, Hasher};
19
19
use std:: io:: Write ;
20
20
use std:: ops:: { Add , Neg , Sub } ;
21
21
22
- use anyhow:: anyhow;
23
22
use byteorder:: { BigEndian , NetworkEndian , ReadBytesExt , WriteBytesExt } ;
24
23
use bytes:: BytesMut ;
25
24
use num_traits:: { CheckedAdd , CheckedNeg , CheckedSub , Zero } ;
@@ -69,10 +68,6 @@ impl IntervalUnit {
69
68
self . months
70
69
}
71
70
72
- pub fn get_years ( & self ) -> i32 {
73
- self . months / 12
74
- }
75
-
76
71
pub fn get_ms ( & self ) -> i64 {
77
72
self . ms
78
73
}
@@ -81,40 +76,12 @@ impl IntervalUnit {
81
76
self . ms . rem_euclid ( DAY_MS ) as u64
82
77
}
83
78
84
- pub fn from_protobuf_bytes ( bytes : & [ u8 ] , ty : IntervalType ) -> ArrayResult < Self > {
85
- // TODO: remove IntervalType later.
86
- match ty {
87
- // the unit is months
88
- Year | YearToMonth | Month => {
89
- let bytes = bytes
90
- . try_into ( )
91
- . map_err ( |e| anyhow ! ( "Failed to deserialize i32: {:?}" , e) ) ?;
92
- let mouths = i32:: from_be_bytes ( bytes) ;
93
- Ok ( IntervalUnit :: from_month ( mouths) )
94
- }
95
- // the unit is ms
96
- Day | DayToHour | DayToMinute | DayToSecond | Hour | HourToMinute | HourToSecond
97
- | Minute | MinuteToSecond | Second => {
98
- let bytes = bytes
99
- . try_into ( )
100
- . map_err ( |e| anyhow ! ( "Failed to deserialize i64: {:?}" , e) ) ?;
101
- let ms = i64:: from_be_bytes ( bytes) ;
102
- Ok ( IntervalUnit :: from_millis ( ms) )
103
- }
104
- Unspecified => {
105
- // Invalid means the interval is from the new frontend.
106
- // TODO: make this default path later.
107
- let mut cursor = Cursor :: new ( bytes) ;
108
- read_interval_unit ( & mut cursor)
109
- }
110
- }
111
- }
112
-
113
79
/// Justify interval, convert 1 month to 30 days and 86400 ms to 1 day.
114
80
/// If day is positive, complement the ms negative value.
115
81
/// These rules only use in interval comparison.
116
82
pub fn justify_interval ( & mut self ) {
117
- let total_ms = self . total_ms ( ) ;
83
+ #[ expect( deprecated) ]
84
+ let total_ms = self . as_ms_i64 ( ) ;
118
85
* self = Self {
119
86
months : 0 ,
120
87
days : ( total_ms / DAY_MS ) as i32 ,
@@ -128,8 +95,8 @@ impl IntervalUnit {
128
95
interval
129
96
}
130
97
131
- #[ must_use ]
132
- pub fn from_total_ms ( ms : i64 ) -> Self {
98
+ #[ deprecated ]
99
+ fn from_total_ms ( ms : i64 ) -> Self {
133
100
let mut remaining_ms = ms;
134
101
let months = remaining_ms / MONTH_MS ;
135
102
remaining_ms -= months * MONTH_MS ;
@@ -142,10 +109,6 @@ impl IntervalUnit {
142
109
}
143
110
}
144
111
145
- pub fn total_ms ( & self ) -> i64 {
146
- self . months as i64 * MONTH_MS + self . days as i64 * DAY_MS + self . ms
147
- }
148
-
149
112
#[ must_use]
150
113
pub fn from_ymd ( year : i32 , month : i32 , days : i32 ) -> Self {
151
114
let months = year * 12 + month;
@@ -186,13 +149,6 @@ impl IntervalUnit {
186
149
}
187
150
}
188
151
189
- pub fn to_protobuf_owned ( self ) -> Vec < u8 > {
190
- let buf = BytesMut :: with_capacity ( 16 ) ;
191
- let mut writer = buf. writer ( ) ;
192
- self . to_protobuf ( & mut writer) . unwrap ( ) ;
193
- writer. into_inner ( ) . to_vec ( )
194
- }
195
-
196
152
pub fn to_protobuf < T : Write > ( self , output : & mut T ) -> ArrayResult < usize > {
197
153
output. write_i32 :: < BigEndian > ( self . months ) ?;
198
154
output. write_i32 :: < BigEndian > ( self . days ) ?;
@@ -225,10 +181,13 @@ impl IntervalUnit {
225
181
return None ;
226
182
}
227
183
184
+ #[ expect( deprecated) ]
228
185
let ms = self . as_ms_i64 ( ) ;
186
+ #[ expect( deprecated) ]
229
187
Some ( IntervalUnit :: from_total_ms ( ( ms as f64 / rhs) . round ( ) as i64 ) )
230
188
}
231
189
190
+ #[ deprecated]
232
191
fn as_ms_i64 ( & self ) -> i64 {
233
192
self . months as i64 * MONTH_MS + self . days as i64 * DAY_MS + self . ms
234
193
}
@@ -241,7 +200,9 @@ impl IntervalUnit {
241
200
let rhs = rhs. try_into ( ) . ok ( ) ?;
242
201
let rhs = rhs. 0 ;
243
202
203
+ #[ expect( deprecated) ]
244
204
let ms = self . as_ms_i64 ( ) ;
205
+ #[ expect( deprecated) ]
245
206
Some ( IntervalUnit :: from_total_ms ( ( ms as f64 * rhs) . round ( ) as i64 ) )
246
207
}
247
208
@@ -474,6 +435,8 @@ impl IntervalUnit {
474
435
}
475
436
}
476
437
438
+ /// Wrapper so that `Debug for IntervalUnitDisplay` would use the concise format of `Display for
439
+ /// IntervalUnit`.
477
440
#[ derive( Clone , Copy ) ]
478
441
pub struct IntervalUnitDisplay < ' a > {
479
442
pub core : & ' a IntervalUnit ,
@@ -491,6 +454,8 @@ impl std::fmt::Debug for IntervalUnitDisplay<'_> {
491
454
}
492
455
}
493
456
457
+ /// Loss of information during the process due to `justify`. Only intended for memcomparable
458
+ /// encoding.
494
459
impl Serialize for IntervalUnit {
495
460
fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
496
461
where
@@ -512,6 +477,7 @@ impl<'de> Deserialize<'de> for IntervalUnit {
512
477
}
513
478
}
514
479
480
+ /// Duplicated logic only used by `HopWindow`. See #8452.
515
481
#[ expect( clippy:: from_over_into) ]
516
482
impl Into < IntervalUnitProto > for IntervalUnit {
517
483
fn into ( self ) -> IntervalUnitProto {
0 commit comments