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:
Ruihang Xia
2024-07-09 16:59:06 +08:00
committed by GitHub
parent 7fe3f496ac
commit 185953e586
21 changed files with 422 additions and 35 deletions

View File

@@ -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.

View File

@@ -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)]

View File

@@ -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)]

View File

@@ -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.

View File

@@ -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 {

View File

@@ -145,6 +145,11 @@ impl Time {
None
}
}
pub fn negative(mut self) -> Self {
self.value = -self.value;
self
}
}
impl From<i64> for Time {

View File

@@ -441,6 +441,11 @@ impl Timestamp {
ParseTimestampSnafu { raw: s }.fail()
}
pub fn negative(mut self) -> Self {
self.value = -self.value;
self
}
}
impl Timestamp {