From 063ea51d3450e322d9e01a3e2ec6178800f6bb26 Mon Sep 17 00:00:00 2001 From: evenyag Date: Thu, 26 Sep 2024 15:17:29 +0800 Subject: [PATCH] chore: remove unused codes --- src/common/time/src/interval.rs | 411 -------------------------------- 1 file changed, 411 deletions(-) diff --git a/src/common/time/src/interval.rs b/src/common/time/src/interval.rs index 706c158dedb5..0ca40f7d79d8 100644 --- a/src/common/time/src/interval.rs +++ b/src/common/time/src/interval.rs @@ -53,21 +53,6 @@ impl From for IntervalUnit { } } -// /// Interval Type represents a period of time. -// /// It is composed of months, days and nanoseconds. -// /// 3 kinds of interval are supported: year-month, day-time and -// /// month-day-nano, which will be stored in the following format. -// /// Interval data format: -// /// | months | days | nsecs | -// /// | 4bytes | 4bytes | 8bytes | -// #[derive(Debug, Clone, Default, Copy, Serialize, Deserialize)] -// pub struct Interval { -// months: i32, -// days: i32, -// nsecs: i64, -// unit: IntervalUnit, -// } - // The `Value` type requires Serialize, Deserialize. #[derive( Debug, Default, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, @@ -334,240 +319,6 @@ pub fn interval_day_time_to_month_day_nano(interval: IntervalDayTime) -> Interva } } -// impl Interval { -// /// Creates a new interval from months, days and nanoseconds. -// /// Precision is nanosecond. -// pub fn from_month_day_nano(months: i32, days: i32, nsecs: i64) -> Self { -// Interval { -// months, -// days, -// nsecs, -// unit: IntervalUnit::MonthDayNano, -// } -// } - -// /// Creates a new interval from months. -// pub fn from_year_month(months: i32) -> Self { -// Interval { -// months, -// days: 0, -// nsecs: 0, -// unit: IntervalUnit::YearMonth, -// } -// } - -// /// Creates a new interval from days and milliseconds. -// pub fn from_day_time(days: i32, millis: i32) -> Self { -// Interval { -// months: 0, -// days, -// nsecs: (millis as i64) * NANOS_PER_MILLI, -// unit: IntervalUnit::DayTime, -// } -// } - -// pub fn to_duration(&self) -> Result { -// Ok(Duration::new_nanosecond( -// self.to_nanosecond() -// .try_into() -// .context(TimestampOverflowSnafu)?, -// )) -// } - -// /// Return a tuple(months, days, nanoseconds) from the interval. -// pub fn to_month_day_nano(&self) -> (i32, i32, i64) { -// (self.months, self.days, self.nsecs) -// } - -// /// Converts the interval to nanoseconds. -// pub fn to_nanosecond(&self) -> i128 { -// let days = (self.days as i64) + DAYS_PER_MONTH * (self.months as i64); -// (self.nsecs as i128) + (NANOS_PER_DAY as i128) * (days as i128) -// } - -// /// Smallest interval value. -// pub const MIN: Self = Self { -// months: i32::MIN, -// days: i32::MIN, -// nsecs: i64::MIN, -// unit: IntervalUnit::MonthDayNano, -// }; - -// /// Largest interval value. -// pub const MAX: Self = Self { -// months: i32::MAX, -// days: i32::MAX, -// nsecs: i64::MAX, -// unit: IntervalUnit::MonthDayNano, -// }; - -// /// Returns the justified interval. -// /// allows you to adjust the interval of 30-day as one month and the interval of 24-hour as one day -// pub fn justified_interval(&self) -> Self { -// let mut result = *self; -// let extra_months_d = self.days as i64 / DAYS_PER_MONTH; -// let extra_months_nsecs = self.nsecs / NANOS_PER_MONTH; -// result.days -= (extra_months_d * DAYS_PER_MONTH) as i32; -// result.nsecs -= extra_months_nsecs * NANOS_PER_MONTH; - -// let extra_days = self.nsecs / NANOS_PER_DAY; -// result.nsecs -= extra_days * NANOS_PER_DAY; - -// result.months += extra_months_d as i32 + extra_months_nsecs as i32; -// result.days += extra_days as i32; - -// result -// } - -// /// is_zero -// pub fn is_zero(&self) -> bool { -// self.months == 0 && self.days == 0 && self.nsecs == 0 -// } - -// /// get unit -// pub fn unit(&self) -> IntervalUnit { -// self.unit -// } - -// /// Multiple Interval by an integer with overflow check. -// /// Returns justified Interval, or `None` if overflow occurred. -// pub fn checked_mul_int(&self, rhs: I) -> Option -// where -// I: TryInto, -// { -// let rhs = rhs.try_into().ok()?; -// let months = self.months.checked_mul(rhs)?; -// let days = self.days.checked_mul(rhs)?; -// let nsecs = self.nsecs.checked_mul(rhs as i64)?; - -// Some( -// Self { -// months, -// days, -// nsecs, -// unit: self.unit, -// } -// .justified_interval(), -// ) -// } - -// /// Convert Interval to ISO 8601 string -// pub fn to_iso8601_string(self) -> String { -// IntervalFormat::from(self).to_iso8601_string() -// } - -// /// Convert Interval to postgres verbose string -// pub fn to_postgres_string(self) -> String { -// IntervalFormat::from(self).to_postgres_string() -// } - -// /// Convert Interval to sql_standard string -// pub fn to_sql_standard_string(self) -> String { -// IntervalFormat::from(self).to_sql_standard_string() -// } - -// /// Interval Type and i128 [IntervalUnit::MonthDayNano] Convert -// /// v consists of months(i32) | days(i32) | nsecs(i64) -// pub fn from_i128(v: i128) -> Self { -// Interval { -// nsecs: v as i64, -// days: (v >> 64) as i32, -// months: (v >> 96) as i32, -// unit: IntervalUnit::MonthDayNano, -// } -// } - -// /// `Interval` Type and i64 [IntervalUnit::DayTime] Convert -// /// v consists of days(i32) | milliseconds(i32) -// pub fn from_i64(v: i64) -> Self { -// Interval { -// nsecs: ((v as i32) as i64) * NANOS_PER_MILLI, -// days: (v >> 32) as i32, -// months: 0, -// unit: IntervalUnit::DayTime, -// } -// } - -// /// `Interval` Type and i32 [IntervalUnit::YearMonth] Convert -// /// v consists of months(i32) -// pub fn from_i32(v: i32) -> Self { -// Interval { -// nsecs: 0, -// days: 0, -// months: v, -// unit: IntervalUnit::YearMonth, -// } -// } - -// pub fn to_i128(&self) -> i128 { -// // 128 96 64 0 -// // +-------+-------+-------+-------+-------+-------+-------+-------+ -// // | months | days | nanoseconds | -// // +-------+-------+-------+-------+-------+-------+-------+-------+ -// let months = (self.months as u128 & u32::MAX as u128) << 96; -// let days = (self.days as u128 & u32::MAX as u128) << 64; -// let nsecs = self.nsecs as u128 & u64::MAX as u128; -// (months | days | nsecs) as i128 -// } - -// pub fn to_i64(&self) -> i64 { -// // 64 32 0 -// // +-------+-------+-------+-------+-------+-------+-------+-------+ -// // | days | milliseconds | -// // +-------+-------+-------+-------+-------+-------+-------+-------+ -// let days = (self.days as u64 & u32::MAX as u64) << 32; -// let milliseconds = (self.nsecs / NANOS_PER_MILLI) as u64 & u32::MAX as u64; -// (days | milliseconds) as i64 -// } - -// pub fn to_i32(&self) -> i32 { -// self.months -// } - -// pub fn negative(&self) -> Self { -// Self { -// months: -self.months, -// days: -self.days, -// nsecs: -self.nsecs, -// unit: self.unit, -// } -// } -// } - -// impl From for Interval { -// fn from(v: i128) -> Self { -// Self::from_i128(v) -// } -// } - -// impl From for i128 { -// fn from(v: Interval) -> Self { -// v.to_i128() -// } -// } - -// impl From for serde_json::Value { -// fn from(v: Interval) -> Self { -// Value::String(v.to_string()) -// } -// } - -// impl Display for Interval { -// fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { -// let mut s = String::new(); -// if self.months != 0 { -// write!(s, "{} months ", self.months)?; -// } -// if self.days != 0 { -// write!(s, "{} days ", self.days)?; -// } -// if self.nsecs != 0 { -// write!(s, "{} nsecs", self.nsecs)?; -// } -// write!(f, "{}", s.trim()) -// } -// } - /// /// support postgres format, iso8601 format and sql standard format #[derive(Debug, Clone, Default, Copy, Serialize, Deserialize)] @@ -581,31 +332,6 @@ pub struct IntervalFormat { pub microseconds: i64, } -// impl From for IntervalFormat { -// fn from(val: Interval) -> IntervalFormat { -// let months = val.months; -// let days = val.days; -// let microseconds = val.nsecs / NANOS_PER_MICRO; -// let years = (months - (months % 12)) / 12; -// let months = months - years * 12; -// let hours = (microseconds - (microseconds % 3_600_000_000)) / 3_600_000_000; -// let microseconds = microseconds - hours * 3_600_000_000; -// let minutes = (microseconds - (microseconds % 60_000_000)) / 60_000_000; -// let microseconds = microseconds - minutes * 60_000_000; -// let seconds = (microseconds - (microseconds % 1_000_000)) / 1_000_000; -// let microseconds = microseconds - seconds * 1_000_000; -// IntervalFormat { -// years, -// months, -// days, -// hours, -// minutes, -// seconds, -// microseconds, -// } -// } -// } - impl IntervalFormat { /// All the field in the interval is 0 pub fn is_zero(&self) -> bool { @@ -782,43 +508,6 @@ fn get_time_part( interval } -// /// IntervalCompare is used to compare two intervals -// /// It makes interval into nanoseconds style. -// #[derive(PartialEq, Eq, Hash, PartialOrd, Ord)] -// struct IntervalCompare(i128); - -// impl From for IntervalCompare { -// fn from(interval: Interval) -> Self { -// Self(interval.to_nanosecond()) -// } -// } - -// impl Ord for Interval { -// fn cmp(&self, other: &Self) -> Ordering { -// IntervalCompare::from(*self).cmp(&IntervalCompare::from(*other)) -// } -// } - -// impl PartialOrd for Interval { -// fn partial_cmp(&self, other: &Self) -> Option { -// Some(self.cmp(other)) -// } -// } - -// impl Eq for Interval {} - -// impl PartialEq for Interval { -// fn eq(&self, other: &Self) -> bool { -// self.cmp(other).is_eq() -// } -// } - -// impl Hash for Interval { -// fn hash(&self, state: &mut H) { -// IntervalCompare::from(*self).hash(state) -// } -// } - #[cfg(test)] mod tests { use super::*; @@ -844,43 +533,6 @@ mod tests { assert_eq!(interval.nanoseconds, 3); } - // #[test] - // fn test_to_duration() { - // let interval = Interval::from_day_time(1, 2); - - // let duration = interval.to_duration().unwrap(); - // assert_eq!(86400002000000, duration.value()); - // assert_eq!(TimeUnit::Nanosecond, duration.unit()); - - // let interval = Interval::from_year_month(12); - - // let duration = interval.to_duration().unwrap(); - // assert_eq!(31104000000000000, duration.value()); - // assert_eq!(TimeUnit::Nanosecond, duration.unit()); - // } - - // #[test] - // fn test_to_nanosecond() { - // let interval = Interval::from_year_month(1); - // assert_eq!(interval.to_nanosecond(), 2592000000000000); - // let interval = Interval::from_day_time(1, 2); - // assert_eq!(interval.to_nanosecond(), 86400002000000); - - // let max_interval = Interval::from_month_day_nano(i32::MAX, i32::MAX, i64::MAX); - // assert_eq!(max_interval.to_nanosecond(), 5751829423496836854775807); - - // let min_interval = Interval::from_month_day_nano(i32::MIN, i32::MIN, i64::MIN); - // assert_eq!(min_interval.to_nanosecond(), -5751829426175236854775808); - // } - - // #[test] - // fn test_interval_is_zero() { - // let interval = Interval::from_month_day_nano(1, 1, 1); - // assert!(!interval.is_zero()); - // let interval = Interval::from_month_day_nano(0, 0, 0); - // assert!(interval.is_zero()); - // } - #[test] fn test_interval_i128_convert() { let test_interval_eq = |month, day, nano| { @@ -932,69 +584,6 @@ mod tests { assert_eq!(interval_format.microseconds, 1000); } - // #[test] - // fn test_interval_hash() { - // let interval = Interval::from_month_day_nano(1, 31, 1); - // let interval2 = Interval::from_month_day_nano(2, 1, 1); - // let mut map = HashMap::new(); - // map.insert(interval, 1); - // assert_eq!(map.get(&interval2), Some(&1)); - // } - - // #[test] - // fn test_interval_mul_int() { - // let interval = Interval::from_month_day_nano(1, 1, 1); - // let interval2 = interval.checked_mul_int(2).unwrap(); - // assert_eq!(interval2.months, 2); - // assert_eq!(interval2.days, 2); - // assert_eq!(interval2.nsecs, 2); - - // // test justified interval - // let interval = Interval::from_month_day_nano(1, 31, 1); - // let interval2 = interval.checked_mul_int(2).unwrap(); - // assert_eq!(interval2.months, 4); - // assert_eq!(interval2.days, 2); - // assert_eq!(interval2.nsecs, 2); - - // // test overflow situation - // let interval = Interval::from_month_day_nano(i32::MAX, 1, 1); - // let interval2 = interval.checked_mul_int(2); - // assert!(interval2.is_none()); - // } - - // #[test] - // fn test_display() { - // let interval = Interval::from_month_day_nano(1, 1, 1); - // assert_eq!(interval.to_string(), "1 months 1 days 1 nsecs"); - - // let interval = Interval::from_month_day_nano(14, 31, 10000000000); - // assert_eq!(interval.to_string(), "14 months 31 days 10000000000 nsecs"); - // } - - // #[test] - // fn test_interval_justified() { - // let interval = Interval::from_month_day_nano(1, 131, 1).justified_interval(); - // let interval2 = Interval::from_month_day_nano(5, 11, 1); - // assert_eq!(interval, interval2); - - // let interval = Interval::from_month_day_nano(1, 1, NANOS_PER_MONTH + 2 * NANOS_PER_DAY) - // .justified_interval(); - // let interval2 = Interval::from_month_day_nano(2, 3, 0); - // assert_eq!(interval, interval2); - // } - - // #[test] - // fn test_serde_json() { - // let interval = Interval::from_month_day_nano(1, 1, 1); - // let json = serde_json::to_string(&interval).unwrap(); - // assert_eq!( - // json, - // "{\"months\":1,\"days\":1,\"nsecs\":1,\"unit\":\"MonthDayNano\"}" - // ); - // let interval2: Interval = serde_json::from_str(&json).unwrap(); - // assert_eq!(interval, interval2); - // } - #[test] fn test_to_iso8601_string() { // Test interval zero