mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-31 20:30:37 +00:00
fix: support unary operator in default value, partition rule and prepare statement (#4301)
* handle unary operator Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * add sqlness test Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * add prepare test Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * add test and context Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix rebase error Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix merge error Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix sqlness Signed-off-by: Ruihang Xia <waynestxia@gmail.com> --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com> Co-authored-by: dennis zhuang <killme2008@gmail.com>
This commit is contained in:
@@ -121,6 +121,11 @@ impl Decimal128 {
|
||||
let value = (hi | lo) as i128;
|
||||
Self::new(value, precision, scale)
|
||||
}
|
||||
|
||||
pub fn negative(mut self) -> Self {
|
||||
self.value = -self.value;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// The default value of Decimal128 is 0, and its precision is 1 and scale is 0.
|
||||
|
||||
@@ -159,6 +159,10 @@ impl Date {
|
||||
.checked_sub_days(Days::new(days as u64))
|
||||
.map(Into::into)
|
||||
}
|
||||
|
||||
pub fn negative(&self) -> Self {
|
||||
Self(-self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -192,6 +192,10 @@ impl DateTime {
|
||||
pub fn to_date(&self) -> Option<Date> {
|
||||
self.to_chrono_datetime().map(|d| Date::from(d.date()))
|
||||
}
|
||||
|
||||
pub fn negative(&self) -> Self {
|
||||
Self(-self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -92,6 +92,11 @@ impl Duration {
|
||||
pub fn to_std_duration(self) -> std::time::Duration {
|
||||
self.into()
|
||||
}
|
||||
|
||||
pub fn negative(mut self) -> Self {
|
||||
self.value = -self.value;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert i64 to Duration Type.
|
||||
|
||||
@@ -281,6 +281,15 @@ impl Interval {
|
||||
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<i128> for Interval {
|
||||
|
||||
@@ -145,6 +145,11 @@ impl Time {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn negative(mut self) -> Self {
|
||||
self.value = -self.value;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i64> for Time {
|
||||
|
||||
@@ -441,6 +441,11 @@ impl Timestamp {
|
||||
|
||||
ParseTimestampSnafu { raw: s }.fail()
|
||||
}
|
||||
|
||||
pub fn negative(mut self) -> Self {
|
||||
self.value = -self.value;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Timestamp {
|
||||
|
||||
Reference in New Issue
Block a user