mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-17 21:40:37 +00:00
fix: impl total order for Timestamp (#878)
* 1. Reimplement Eq for Timestamp 2. Add and/or for GenericRange * chore: add test for TimestampRange with diff unit * chore: optimize split implementation * fix: clippy * fix: add fast path * fix: CR comments
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
use std::any::Any;
|
||||
|
||||
use common_error::prelude::*;
|
||||
use common_time::timestamp::TimeUnit;
|
||||
use common_time::Timestamp;
|
||||
use datatypes::prelude::ConcreteDataType;
|
||||
use sqlparser::parser::ParserError;
|
||||
use sqlparser::tokenizer::TokenizerError;
|
||||
@@ -134,6 +136,17 @@ pub enum Error {
|
||||
|
||||
#[snafu(display("Invalid sql value: {}", value))]
|
||||
InvalidSqlValue { value: String, backtrace: Backtrace },
|
||||
|
||||
#[snafu(display(
|
||||
"Converting timestamp {:?} to unit {:?} overflow",
|
||||
timestamp,
|
||||
target_unit
|
||||
))]
|
||||
TimestampOverflow {
|
||||
timestamp: Timestamp,
|
||||
target_unit: TimeUnit,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
}
|
||||
|
||||
impl ErrorExt for Error {
|
||||
@@ -160,6 +173,7 @@ impl ErrorExt for Error {
|
||||
SerializeColumnDefaultConstraint { source, .. } => source.status_code(),
|
||||
ConvertToGrpcDataType { source, .. } => source.status_code(),
|
||||
InvalidSqlValue { .. } => StatusCode::InvalidArguments,
|
||||
TimestampOverflow { .. } => StatusCode::InvalidArguments,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ use datatypes::prelude::ConcreteDataType;
|
||||
use datatypes::schema::{ColumnDefaultConstraint, ColumnSchema};
|
||||
use datatypes::types::DateTimeType;
|
||||
use datatypes::value::Value;
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ensure, OptionExt, ResultExt};
|
||||
|
||||
use crate::ast::{
|
||||
ColumnDef, ColumnOption, ColumnOptionDef, DataType as SqlDataType, Expr, ObjectName,
|
||||
@@ -40,7 +40,7 @@ use crate::ast::{
|
||||
};
|
||||
use crate::error::{
|
||||
self, ColumnTypeMismatchSnafu, ConvertToGrpcDataTypeSnafu, InvalidSqlValueSnafu,
|
||||
ParseSqlValueSnafu, Result, SerializeColumnDefaultConstraintSnafu,
|
||||
ParseSqlValueSnafu, Result, SerializeColumnDefaultConstraintSnafu, TimestampOverflowSnafu,
|
||||
UnsupportedDefaultValueSnafu,
|
||||
};
|
||||
|
||||
@@ -112,10 +112,12 @@ fn parse_string_to_value(
|
||||
}
|
||||
ConcreteDataType::Timestamp(t) => {
|
||||
if let Ok(ts) = Timestamp::from_str(&s) {
|
||||
Ok(Value::Timestamp(Timestamp::new(
|
||||
ts.convert_to(t.unit()),
|
||||
t.unit(),
|
||||
)))
|
||||
Ok(Value::Timestamp(ts.convert_to(t.unit()).context(
|
||||
TimestampOverflowSnafu {
|
||||
timestamp: ts,
|
||||
target_unit: t.unit(),
|
||||
},
|
||||
)?))
|
||||
} else {
|
||||
ParseSqlValueSnafu {
|
||||
msg: format!("Failed to parse {s} to Timestamp value"),
|
||||
|
||||
Reference in New Issue
Block a user