Skip to content

Commit afc776f

Browse files
committed
Interval -> FixedSizeBinary(16)
1 parent 9e58cd9 commit afc776f

File tree

40 files changed

+373
-463
lines changed

40 files changed

+373
-463
lines changed

src/common/column/src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ mod private {
114114
impl Sealed for OrderedFloat<f32> {}
115115
impl Sealed for OrderedFloat<f64> {}
116116
impl Sealed for super::days_ms {}
117-
impl Sealed for super::months_days_ns {}
117+
impl Sealed for super::months_days_micros {}
118118
impl Sealed for View {}
119119
}

src/common/column/src/types/native.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ impl NativeType for days_ms {
268268
)]
269269
#[allow(non_camel_case_types)]
270270
#[repr(C)]
271-
pub struct months_days_ns(pub i32, pub i32, pub i64);
271+
pub struct months_days_micros(pub i32, pub i32, pub i64);
272272

273-
impl NumCast for months_days_ns {
273+
impl NumCast for months_days_micros {
274274
fn from<T: ToPrimitive>(n: T) -> Option<Self> {
275275
n.to_i64().map(|n| Self::new(0, 0, n))
276276
}
277277
}
278278

279-
impl ToPrimitive for months_days_ns {
279+
impl ToPrimitive for months_days_micros {
280280
fn to_i64(&self) -> Option<i64> {
281281
Some(self.2)
282282
}
@@ -286,11 +286,11 @@ impl ToPrimitive for months_days_ns {
286286
}
287287
}
288288

289-
impl months_days_ns {
290-
/// A new [`months_days_ns`].
289+
impl months_days_micros {
290+
/// A new [`months_days_micros`].
291291
#[inline]
292-
pub fn new(months: i32, days: i32, nanoseconds: i64) -> Self {
293-
Self(months, days, nanoseconds)
292+
pub fn new(months: i32, days: i32, micros: i64) -> Self {
293+
Self(months, days, micros)
294294
}
295295

296296
/// The number of months
@@ -305,14 +305,14 @@ impl months_days_ns {
305305
self.1
306306
}
307307

308-
/// The number of nanoseconds
308+
/// The number of microseconds
309309
#[inline]
310310
pub fn ns(&self) -> i64 {
311311
self.2
312312
}
313313
}
314314

315-
impl NativeType for months_days_ns {
315+
impl NativeType for months_days_micros {
316316
const PRIMITIVE: PrimitiveType = PrimitiveType::MonthDayNano;
317317
type Bytes = [u8; 16];
318318
#[inline]
@@ -408,9 +408,9 @@ impl std::fmt::Display for days_ms {
408408
}
409409
}
410410

411-
impl std::fmt::Display for months_days_ns {
411+
impl std::fmt::Display for months_days_micros {
412412
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
413-
write!(f, "{}m {}d {}ns", self.months(), self.days(), self.ns())
413+
write!(f, "{}m {}d {}micros", self.months(), self.days(), self.ns())
414414
}
415415
}
416416

@@ -423,7 +423,7 @@ impl Neg for days_ms {
423423
}
424424
}
425425

426-
impl Neg for months_days_ns {
426+
impl Neg for months_days_micros {
427427
type Output = Self;
428428

429429
#[inline(always)]

src/common/column/src/types/simd/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use super::days_ms;
2020
use super::f16;
2121
use super::i256;
22-
use super::months_days_ns;
22+
use super::months_days_micros;
2323
use super::BitChunk;
2424
use super::BitChunkIter;
2525
use super::NativeType;
@@ -151,7 +151,7 @@ pub(super) use native_simd;
151151
// of how they are represented in the different channels.
152152
native_simd!(f16x32, f16, 32, u32);
153153
native_simd!(days_msx8, days_ms, 8, u8);
154-
native_simd!(months_days_nsx8, months_days_ns, 8, u8);
154+
native_simd!(months_days_nsx8, months_days_micros, 8, u8);
155155
native_simd!(i128x8, i128, 8, u8);
156156
native_simd!(i256x8, i256, 8, u8);
157157

@@ -185,4 +185,4 @@ native!(f64, f64x8);
185185
native!(i128, i128x8);
186186
native!(i256, i256x8);
187187
native!(days_ms, days_msx8);
188-
native!(months_days_ns, months_days_nsx8);
188+
native!(months_days_micros, months_days_nsx8);

src/common/io/src/interval.rs

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub trait BufferReadIntervalExt {
2626
pub struct Interval {
2727
pub months: i32,
2828
pub days: i32,
29-
pub nanos: i64,
29+
pub micros: i64,
3030
}
3131

3232
impl Display for Interval {
@@ -72,11 +72,11 @@ impl IntervalToStringCast {
7272
}
7373
}
7474

75-
fn format_nanos(mut nanos: i64, buffer: &mut [u8], length: &mut usize) {
76-
if nanos < 0 {
77-
nanos = -nanos;
75+
fn format_micros(mut micros: i64, buffer: &mut [u8], length: &mut usize) {
76+
if micros < 0 {
77+
micros = -micros;
7878
}
79-
let s = format!("{:09}", nanos);
79+
let s = format!("{:06}", micros);
8080
let bytes = s.as_bytes();
8181
buffer[*length..*length + bytes.len()].copy_from_slice(bytes);
8282
*length += bytes.len();
@@ -97,23 +97,23 @@ impl IntervalToStringCast {
9797
if interval.days != 0 {
9898
Self::format_interval_value(interval.days, buffer, &mut length, " day");
9999
}
100-
if interval.nanos != 0 {
100+
if interval.micros != 0 {
101101
if length != 0 {
102102
buffer[length] = b' ';
103103
length += 1;
104104
}
105-
let mut nanos = interval.nanos;
105+
let mut nanos = interval.micros;
106106
if nanos < 0 {
107107
buffer[length] = b'-';
108108
length += 1;
109109
nanos = -nanos;
110110
}
111-
let hour = nanos / NANO_PER_HOUR;
112-
nanos -= hour * NANO_PER_HOUR;
113-
let min = nanos / NANO_PER_MINUTE;
114-
nanos -= min * NANO_PER_MINUTE;
115-
let sec = nanos / NANO_PER_SEC;
116-
nanos -= sec * NANO_PER_SEC;
111+
let hour = nanos / MICROS_PER_HOUR;
112+
nanos -= hour * MICROS_PER_HOUR;
113+
let min = nanos / MICROS_PER_MINUTE;
114+
nanos -= min * MICROS_PER_MINUTE;
115+
let sec = nanos / MICROS_PER_SEC;
116+
nanos -= sec * MICROS_PER_SEC;
117117

118118
Self::format_signed_number(hour, buffer, &mut length);
119119
buffer[length] = b':';
@@ -125,7 +125,7 @@ impl IntervalToStringCast {
125125
if nanos != 0 {
126126
buffer[length] = b'.';
127127
length += 1;
128-
Self::format_nanos(nanos, buffer, &mut length);
128+
Self::format_micros(nanos, buffer, &mut length);
129129
}
130130
} else if length == 0 {
131131
buffer[..8].copy_from_slice(b"00:00:00");
@@ -213,7 +213,7 @@ impl Interval {
213213
}
214214
result.months = -result.months;
215215
result.days = -result.days;
216-
result.nanos = -result.nanos;
216+
result.micros = -result.micros;
217217
return Ok(result);
218218
}
219219
_ => {
@@ -261,12 +261,12 @@ fn parse_number(bytes: &[u8]) -> Result<(i64, i64, usize)> {
261261
if pos < bytes.len() && bytes[pos] == b':' {
262262
let time_bytes = &bytes[pos..];
263263
let mut time_pos = 0;
264-
let mut total_nanos: i64 = number * 60 * 60 * NANO_PER_SEC;
264+
let mut total_nanos: i64 = number * 60 * 60 * MICROS_PER_SEC;
265265
let mut colon_count = 0;
266266

267267
while colon_count < 2 && time_bytes.len() > time_pos {
268268
let (minute, _, next_pos) = parse_time_part(&time_bytes[time_pos..])?;
269-
let minute_nanos = minute * 60 * NANO_PER_SEC;
269+
let minute_nanos = minute * 60 * MICROS_PER_SEC;
270270
total_nanos += minute_nanos;
271271
time_pos += next_pos;
272272

@@ -279,7 +279,7 @@ fn parse_number(bytes: &[u8]) -> Result<(i64, i64, usize)> {
279279
}
280280
if time_bytes.len() > time_pos {
281281
let (seconds, nanos, next_pos) = parse_time_part_with_nanos(&time_bytes[time_pos..])?;
282-
total_nanos += seconds * NANO_PER_SEC + nanos;
282+
total_nanos += seconds * MICROS_PER_SEC + nanos;
283283
time_pos += next_pos;
284284
}
285285
return Ok((total_nanos, 0, pos + time_pos));
@@ -390,11 +390,10 @@ fn try_get_date_part_specifier(specifier_str: &str) -> Result<DatePartSpecifier>
390390
}
391391
}
392392

393-
const NANO_PER_SEC: i64 = 1_000_000_000;
394-
const NANO_PER_MSEC: i64 = 1_000_000;
395-
const NANO_PER_MICROS: i64 = 1_000;
396-
const NANO_PER_MINUTE: i64 = 60 * NANO_PER_SEC;
397-
const NANO_PER_HOUR: i64 = 60 * NANO_PER_MINUTE;
393+
const MICROS_PER_SEC: i64 = 1_000_000;
394+
const MICROS_PER_MSEC: i64 = 1_000;
395+
const MICROS_PER_MINUTE: i64 = 60 * MICROS_PER_SEC;
396+
const MICROS_PER_HOUR: i64 = 60 * MICROS_PER_MINUTE;
398397
const DAYS_PER_WEEK: i32 = 7;
399398
const MONTHS_PER_QUARTER: i32 = 3;
400399
const MONTHS_PER_YEAR: i32 = 12;
@@ -409,12 +408,12 @@ fn apply_specifier(
409408
specifier_str: &str,
410409
) -> Result<()> {
411410
if specifier_str.is_empty() {
412-
result.nanos = result
413-
.nanos
411+
result.micros = result
412+
.micros
414413
.checked_add(number)
415414
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?;
416-
result.nanos = result
417-
.nanos
415+
result.micros = result
416+
.micros
418417
.checked_add(fraction)
419418
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?;
420419
return Ok(());
@@ -515,51 +514,47 @@ fn apply_specifier(
515514
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?;
516515
}
517516
DatePartSpecifier::Microseconds => {
518-
result.nanos = result
519-
.nanos
520-
.checked_add(
521-
number
522-
.checked_mul(NANO_PER_MICROS)
523-
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?,
524-
)
517+
result.micros = result
518+
.micros
519+
.checked_add(number)
525520
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?;
526521
}
527522
DatePartSpecifier::Milliseconds => {
528-
result.nanos = result
529-
.nanos
523+
result.micros = result
524+
.micros
530525
.checked_add(
531526
number
532-
.checked_mul(NANO_PER_MSEC)
527+
.checked_mul(MICROS_PER_MSEC)
533528
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?,
534529
)
535530
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?;
536531
}
537532
DatePartSpecifier::Second => {
538-
result.nanos = result
539-
.nanos
533+
result.micros = result
534+
.micros
540535
.checked_add(
541536
number
542-
.checked_mul(NANO_PER_SEC)
537+
.checked_mul(MICROS_PER_SEC)
543538
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?,
544539
)
545540
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?;
546541
}
547542
DatePartSpecifier::Minute => {
548-
result.nanos = result
549-
.nanos
543+
result.micros = result
544+
.micros
550545
.checked_add(
551546
number
552-
.checked_mul(NANO_PER_MINUTE)
547+
.checked_mul(MICROS_PER_MINUTE)
553548
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?,
554549
)
555550
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?;
556551
}
557552
DatePartSpecifier::Hour => {
558-
result.nanos = result
559-
.nanos
553+
result.micros = result
554+
.micros
560555
.checked_add(
561556
number
562-
.checked_mul(NANO_PER_HOUR)
557+
.checked_mul(MICROS_PER_HOUR)
563558
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?,
564559
)
565560
.ok_or(ErrorCode::BadArguments("Overflow".to_string()))?;

0 commit comments

Comments
 (0)