diff --git a/src/api/src/helper.rs b/src/api/src/helper.rs index 8fd31cd241..6a398b05d3 100644 --- a/src/api/src/helper.rs +++ b/src/api/src/helper.rs @@ -19,9 +19,7 @@ use common_decimal::decimal128::{DECIMAL128_DEFAULT_SCALE, DECIMAL128_MAX_PRECIS use common_decimal::Decimal128; use common_time::time::Time; use common_time::timestamp::TimeUnit; -use common_time::{ - Date, DateTime, IntervalDayTime, IntervalMonthDayNano, IntervalYearMonth, Timestamp, -}; +use common_time::{Date, IntervalDayTime, IntervalMonthDayNano, IntervalYearMonth, Timestamp}; use datatypes::prelude::{ConcreteDataType, ValueRef}; use datatypes::scalars::ScalarVector; use datatypes::types::{ @@ -29,8 +27,8 @@ use datatypes::types::{ }; use datatypes::value::{OrderedF32, OrderedF64, Value}; use datatypes::vectors::{ - BinaryVector, BooleanVector, DateTimeVector, DateVector, Decimal128Vector, Float32Vector, - Float64Vector, Int32Vector, Int64Vector, IntervalDayTimeVector, IntervalMonthDayNanoVector, + BinaryVector, BooleanVector, DateVector, Decimal128Vector, Float32Vector, Float64Vector, + Int32Vector, Int64Vector, IntervalDayTimeVector, IntervalMonthDayNanoVector, IntervalYearMonthVector, PrimitiveVector, StringVector, TimeMicrosecondVector, TimeMillisecondVector, TimeNanosecondVector, TimeSecondVector, TimestampMicrosecondVector, TimestampMillisecondVector, TimestampNanosecondVector, TimestampSecondVector, UInt32Vector, @@ -118,7 +116,7 @@ impl From for ConcreteDataType { ColumnDataType::Json => ConcreteDataType::json_datatype(), ColumnDataType::String => ConcreteDataType::string_datatype(), ColumnDataType::Date => ConcreteDataType::date_datatype(), - ColumnDataType::Datetime => ConcreteDataType::datetime_datatype(), + ColumnDataType::Datetime => ConcreteDataType::timestamp_microsecond_datatype(), ColumnDataType::TimestampSecond => ConcreteDataType::timestamp_second_datatype(), ColumnDataType::TimestampMillisecond => { ConcreteDataType::timestamp_millisecond_datatype() @@ -271,7 +269,6 @@ impl TryFrom for ColumnDataTypeWrapper { ConcreteDataType::Binary(_) => ColumnDataType::Binary, ConcreteDataType::String(_) => ColumnDataType::String, ConcreteDataType::Date(_) => ColumnDataType::Date, - ConcreteDataType::DateTime(_) => ColumnDataType::Datetime, ConcreteDataType::Timestamp(t) => match t { TimestampType::Second(_) => ColumnDataType::TimestampSecond, TimestampType::Millisecond(_) => ColumnDataType::TimestampMillisecond, @@ -476,7 +473,6 @@ pub fn push_vals(column: &mut Column, origin_count: usize, vector: VectorRef) { Value::String(val) => values.string_values.push(val.as_utf8().to_string()), Value::Binary(val) => values.binary_values.push(val.to_vec()), Value::Date(val) => values.date_values.push(val.val()), - Value::DateTime(val) => values.datetime_values.push(val.val()), Value::Timestamp(val) => match val.unit() { TimeUnit::Second => values.timestamp_second_values.push(val.value()), TimeUnit::Millisecond => values.timestamp_millisecond_values.push(val.value()), @@ -577,12 +573,11 @@ pub fn pb_value_to_value_ref<'a>( ValueData::BinaryValue(bytes) => ValueRef::Binary(bytes.as_slice()), ValueData::StringValue(string) => ValueRef::String(string.as_str()), ValueData::DateValue(d) => ValueRef::Date(Date::from(*d)), - ValueData::DatetimeValue(d) => ValueRef::DateTime(DateTime::new(*d)), ValueData::TimestampSecondValue(t) => ValueRef::Timestamp(Timestamp::new_second(*t)), ValueData::TimestampMillisecondValue(t) => { ValueRef::Timestamp(Timestamp::new_millisecond(*t)) } - ValueData::TimestampMicrosecondValue(t) => { + ValueData::DatetimeValue(t) | ValueData::TimestampMicrosecondValue(t) => { ValueRef::Timestamp(Timestamp::new_microsecond(*t)) } ValueData::TimestampNanosecondValue(t) => { @@ -651,7 +646,6 @@ pub fn pb_values_to_vector_ref(data_type: &ConcreteDataType, values: Values) -> ConcreteDataType::Binary(_) => Arc::new(BinaryVector::from(values.binary_values)), ConcreteDataType::String(_) => Arc::new(StringVector::from_vec(values.string_values)), ConcreteDataType::Date(_) => Arc::new(DateVector::from_vec(values.date_values)), - ConcreteDataType::DateTime(_) => Arc::new(DateTimeVector::from_vec(values.datetime_values)), ConcreteDataType::Timestamp(unit) => match unit { TimestampType::Second(_) => Arc::new(TimestampSecondVector::from_vec( values.timestamp_second_values, @@ -787,11 +781,6 @@ pub fn pb_values_to_values(data_type: &ConcreteDataType, values: Values) -> Vec< .into_iter() .map(|val| val.into()) .collect(), - ConcreteDataType::DateTime(_) => values - .datetime_values - .into_iter() - .map(|v| Value::DateTime(v.into())) - .collect(), ConcreteDataType::Date(_) => values .date_values .into_iter() @@ -947,9 +936,6 @@ pub fn to_proto_value(value: Value) -> Option { Value::Date(v) => v1::Value { value_data: Some(ValueData::DateValue(v.val())), }, - Value::DateTime(v) => v1::Value { - value_data: Some(ValueData::DatetimeValue(v.val())), - }, Value::Timestamp(v) => match v.unit() { TimeUnit::Second => v1::Value { value_data: Some(ValueData::TimestampSecondValue(v.value())), @@ -1066,7 +1052,6 @@ pub fn value_to_grpc_value(value: Value) -> GrpcValue { Value::String(v) => Some(ValueData::StringValue(v.as_utf8().to_string())), Value::Binary(v) => Some(ValueData::BinaryValue(v.to_vec())), Value::Date(v) => Some(ValueData::DateValue(v.val())), - Value::DateTime(v) => Some(ValueData::DatetimeValue(v.val())), Value::Timestamp(v) => Some(match v.unit() { TimeUnit::Second => ValueData::TimestampSecondValue(v.value()), TimeUnit::Millisecond => ValueData::TimestampMillisecondValue(v.value()), @@ -1248,7 +1233,7 @@ mod tests { ColumnDataTypeWrapper::date_datatype().into() ); assert_eq!( - ConcreteDataType::datetime_datatype(), + ConcreteDataType::timestamp_microsecond_datatype(), ColumnDataTypeWrapper::datetime_datatype().into() ); assert_eq!( @@ -1339,10 +1324,6 @@ mod tests { ColumnDataTypeWrapper::date_datatype(), ConcreteDataType::date_datatype().try_into().unwrap() ); - assert_eq!( - ColumnDataTypeWrapper::datetime_datatype(), - ConcreteDataType::datetime_datatype().try_into().unwrap() - ); assert_eq!( ColumnDataTypeWrapper::timestamp_millisecond_datatype(), ConcreteDataType::timestamp_millisecond_datatype() @@ -1830,17 +1811,6 @@ mod tests { ] ); - test_convert_values!( - datetime, - vec![1.into(), 2.into(), 3.into()], - datetime, - vec![ - Value::DateTime(1.into()), - Value::DateTime(2.into()), - Value::DateTime(3.into()) - ] - ); - #[test] fn test_vectors_to_rows_for_different_types() { let boolean_vec = BooleanVector::from_vec(vec![true, false, true]); diff --git a/src/catalog/src/system_schema/information_schema/columns.rs b/src/catalog/src/system_schema/information_schema/columns.rs index 53ee5d432c..5747d6eea8 100644 --- a/src/catalog/src/system_schema/information_schema/columns.rs +++ b/src/catalog/src/system_schema/information_schema/columns.rs @@ -365,10 +365,6 @@ impl InformationSchemaColumnsBuilder { self.numeric_scales.push(None); match &column_schema.data_type { - ConcreteDataType::DateTime(datetime_type) => { - self.datetime_precisions - .push(Some(datetime_type.precision() as i64)); - } ConcreteDataType::Timestamp(ts_type) => { self.datetime_precisions .push(Some(ts_type.precision() as i64)); diff --git a/src/catalog/src/system_schema/information_schema/information_memory_table.rs b/src/catalog/src/system_schema/information_schema/information_memory_table.rs index bd7aba10a5..7d203087df 100644 --- a/src/catalog/src/system_schema/information_schema/information_memory_table.rs +++ b/src/catalog/src/system_schema/information_schema/information_memory_table.rs @@ -20,7 +20,7 @@ use datatypes::vectors::{Int64Vector, StringVector, VectorRef}; use super::table_names::*; use crate::system_schema::utils::tables::{ - bigint_column, datetime_column, string_column, string_columns, + bigint_column, string_column, string_columns, timestamp_micro_column, }; const NO_VALUE: &str = "NO"; @@ -163,17 +163,17 @@ pub(super) fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec string_column("EVENT_BODY"), string_column("EVENT_DEFINITION"), string_column("EVENT_TYPE"), - datetime_column("EXECUTE_AT"), + timestamp_micro_column("EXECUTE_AT"), bigint_column("INTERVAL_VALUE"), string_column("INTERVAL_FIELD"), string_column("SQL_MODE"), - datetime_column("STARTS"), - datetime_column("ENDS"), + timestamp_micro_column("STARTS"), + timestamp_micro_column("ENDS"), string_column("STATUS"), string_column("ON_COMPLETION"), - datetime_column("CREATED"), - datetime_column("LAST_ALTERED"), - datetime_column("LAST_EXECUTED"), + timestamp_micro_column("CREATED"), + timestamp_micro_column("LAST_ALTERED"), + timestamp_micro_column("LAST_EXECUTED"), string_column("EVENT_COMMENT"), bigint_column("ORIGINATOR"), string_column("CHARACTER_SET_CLIENT"), @@ -204,10 +204,10 @@ pub(super) fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec bigint_column("INITIAL_SIZE"), bigint_column("MAXIMUM_SIZE"), bigint_column("AUTOEXTEND_SIZE"), - datetime_column("CREATION_TIME"), - datetime_column("LAST_UPDATE_TIME"), - datetime_column("LAST_ACCESS_TIME"), - datetime_column("RECOVER_TIME"), + timestamp_micro_column("CREATION_TIME"), + timestamp_micro_column("LAST_UPDATE_TIME"), + timestamp_micro_column("LAST_ACCESS_TIME"), + timestamp_micro_column("RECOVER_TIME"), bigint_column("TRANSACTION_COUNTER"), string_column("VERSION"), string_column("ROW_FORMAT"), @@ -217,9 +217,9 @@ pub(super) fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec bigint_column("MAX_DATA_LENGTH"), bigint_column("INDEX_LENGTH"), bigint_column("DATA_FREE"), - datetime_column("CREATE_TIME"), - datetime_column("UPDATE_TIME"), - datetime_column("CHECK_TIME"), + timestamp_micro_column("CREATE_TIME"), + timestamp_micro_column("UPDATE_TIME"), + timestamp_micro_column("CHECK_TIME"), string_column("CHECKSUM"), string_column("STATUS"), string_column("EXTRA"), @@ -330,8 +330,8 @@ pub(super) fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec string_column("SQL_DATA_ACCESS"), string_column("SQL_PATH"), string_column("SECURITY_TYPE"), - datetime_column("CREATED"), - datetime_column("LAST_ALTERED"), + timestamp_micro_column("CREATED"), + timestamp_micro_column("LAST_ALTERED"), string_column("SQL_MODE"), string_column("ROUTINE_COMMENT"), string_column("DEFINER"), @@ -383,7 +383,7 @@ pub(super) fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec string_column("ACTION_REFERENCE_NEW_TABLE"), string_column("ACTION_REFERENCE_OLD_ROW"), string_column("ACTION_REFERENCE_NEW_ROW"), - datetime_column("CREATED"), + timestamp_micro_column("CREATED"), string_column("SQL_MODE"), string_column("DEFINER"), string_column("CHARACTER_SET_CLIENT"), diff --git a/src/catalog/src/system_schema/information_schema/partitions.rs b/src/catalog/src/system_schema/information_schema/partitions.rs index 38812c2cf4..31e2e69d29 100644 --- a/src/catalog/src/system_schema/information_schema/partitions.rs +++ b/src/catalog/src/system_schema/information_schema/partitions.rs @@ -20,17 +20,18 @@ use common_catalog::consts::INFORMATION_SCHEMA_PARTITIONS_TABLE_ID; use common_error::ext::BoxedError; use common_recordbatch::adapter::RecordBatchStreamAdapter; use common_recordbatch::{RecordBatch, SendableRecordBatchStream}; -use common_time::datetime::DateTime; use datafusion::execution::TaskContext; use datafusion::physical_plan::stream::RecordBatchStreamAdapter as DfRecordBatchStreamAdapter; use datafusion::physical_plan::streaming::PartitionStream as DfPartitionStream; use datafusion::physical_plan::SendableRecordBatchStream as DfSendableRecordBatchStream; use datatypes::prelude::{ConcreteDataType, ScalarVectorBuilder, VectorRef}; use datatypes::schema::{ColumnSchema, Schema, SchemaRef}; +use datatypes::timestamp::TimestampMicrosecond; use datatypes::value::Value; use datatypes::vectors::{ - ConstantVector, DateTimeVector, DateTimeVectorBuilder, Int64Vector, Int64VectorBuilder, - MutableVector, StringVector, StringVectorBuilder, UInt64VectorBuilder, + ConstantVector, Int64Vector, Int64VectorBuilder, MutableVector, StringVector, + StringVectorBuilder, TimestampMicrosecondVector, TimestampMicrosecondVectorBuilder, + UInt64VectorBuilder, }; use futures::{StreamExt, TryStreamExt}; use partition::manager::PartitionInfo; @@ -127,9 +128,21 @@ impl InformationSchemaPartitions { ColumnSchema::new("max_data_length", ConcreteDataType::int64_datatype(), true), ColumnSchema::new("index_length", ConcreteDataType::int64_datatype(), true), ColumnSchema::new("data_free", ConcreteDataType::int64_datatype(), true), - ColumnSchema::new("create_time", ConcreteDataType::datetime_datatype(), true), - ColumnSchema::new("update_time", ConcreteDataType::datetime_datatype(), true), - ColumnSchema::new("check_time", ConcreteDataType::datetime_datatype(), true), + ColumnSchema::new( + "create_time", + ConcreteDataType::timestamp_microsecond_datatype(), + true, + ), + ColumnSchema::new( + "update_time", + ConcreteDataType::timestamp_microsecond_datatype(), + true, + ), + ColumnSchema::new( + "check_time", + ConcreteDataType::timestamp_microsecond_datatype(), + true, + ), ColumnSchema::new("checksum", ConcreteDataType::int64_datatype(), true), ColumnSchema::new( "partition_comment", @@ -200,7 +213,7 @@ struct InformationSchemaPartitionsBuilder { partition_names: StringVectorBuilder, partition_ordinal_positions: Int64VectorBuilder, partition_expressions: StringVectorBuilder, - create_times: DateTimeVectorBuilder, + create_times: TimestampMicrosecondVectorBuilder, partition_ids: UInt64VectorBuilder, } @@ -220,7 +233,7 @@ impl InformationSchemaPartitionsBuilder { partition_names: StringVectorBuilder::with_capacity(INIT_CAPACITY), partition_ordinal_positions: Int64VectorBuilder::with_capacity(INIT_CAPACITY), partition_expressions: StringVectorBuilder::with_capacity(INIT_CAPACITY), - create_times: DateTimeVectorBuilder::with_capacity(INIT_CAPACITY), + create_times: TimestampMicrosecondVectorBuilder::with_capacity(INIT_CAPACITY), partition_ids: UInt64VectorBuilder::with_capacity(INIT_CAPACITY), } } @@ -324,7 +337,7 @@ impl InformationSchemaPartitionsBuilder { }; self.partition_expressions.push(expressions.as_deref()); - self.create_times.push(Some(DateTime::from( + self.create_times.push(Some(TimestampMicrosecond::from( table_info.meta.created_on.timestamp_millis(), ))); self.partition_ids.push(Some(partition.id.as_u64())); @@ -342,8 +355,8 @@ impl InformationSchemaPartitionsBuilder { Arc::new(Int64Vector::from(vec![None])), rows_num, )); - let null_datetime_vector = Arc::new(ConstantVector::new( - Arc::new(DateTimeVector::from(vec![None])), + let null_timestampmicrosecond_vector = Arc::new(ConstantVector::new( + Arc::new(TimestampMicrosecondVector::from(vec![None])), rows_num, )); let partition_methods = Arc::new(ConstantVector::new( @@ -373,8 +386,8 @@ impl InformationSchemaPartitionsBuilder { null_i64_vector.clone(), Arc::new(self.create_times.finish()), // TODO(dennis): supports update_time - null_datetime_vector.clone(), - null_datetime_vector, + null_timestampmicrosecond_vector.clone(), + null_timestampmicrosecond_vector, null_i64_vector, null_string_vector.clone(), null_string_vector.clone(), diff --git a/src/catalog/src/system_schema/information_schema/tables.rs b/src/catalog/src/system_schema/information_schema/tables.rs index a06eb7ea7d..79c6b59bbd 100644 --- a/src/catalog/src/system_schema/information_schema/tables.rs +++ b/src/catalog/src/system_schema/information_schema/tables.rs @@ -30,7 +30,8 @@ use datatypes::prelude::{ConcreteDataType, ScalarVectorBuilder, VectorRef}; use datatypes::schema::{ColumnSchema, Schema, SchemaRef}; use datatypes::value::Value; use datatypes::vectors::{ - DateTimeVectorBuilder, StringVectorBuilder, UInt32VectorBuilder, UInt64VectorBuilder, + StringVectorBuilder, TimestampMicrosecondVectorBuilder, UInt32VectorBuilder, + UInt64VectorBuilder, }; use futures::TryStreamExt; use snafu::{OptionExt, ResultExt}; @@ -105,9 +106,21 @@ impl InformationSchemaTables { ColumnSchema::new(TABLE_ROWS, ConcreteDataType::uint64_datatype(), true), ColumnSchema::new(DATA_FREE, ConcreteDataType::uint64_datatype(), true), ColumnSchema::new(AUTO_INCREMENT, ConcreteDataType::uint64_datatype(), true), - ColumnSchema::new(CREATE_TIME, ConcreteDataType::datetime_datatype(), true), - ColumnSchema::new(UPDATE_TIME, ConcreteDataType::datetime_datatype(), true), - ColumnSchema::new(CHECK_TIME, ConcreteDataType::datetime_datatype(), true), + ColumnSchema::new( + CREATE_TIME, + ConcreteDataType::timestamp_microsecond_datatype(), + true, + ), + ColumnSchema::new( + UPDATE_TIME, + ConcreteDataType::timestamp_microsecond_datatype(), + true, + ), + ColumnSchema::new( + CHECK_TIME, + ConcreteDataType::timestamp_microsecond_datatype(), + true, + ), ColumnSchema::new(TABLE_COLLATION, ConcreteDataType::string_datatype(), true), ColumnSchema::new(CHECKSUM, ConcreteDataType::uint64_datatype(), true), ColumnSchema::new(CREATE_OPTIONS, ConcreteDataType::string_datatype(), true), @@ -182,9 +195,9 @@ struct InformationSchemaTablesBuilder { max_index_length: UInt64VectorBuilder, data_free: UInt64VectorBuilder, auto_increment: UInt64VectorBuilder, - create_time: DateTimeVectorBuilder, - update_time: DateTimeVectorBuilder, - check_time: DateTimeVectorBuilder, + create_time: TimestampMicrosecondVectorBuilder, + update_time: TimestampMicrosecondVectorBuilder, + check_time: TimestampMicrosecondVectorBuilder, table_collation: StringVectorBuilder, checksum: UInt64VectorBuilder, create_options: StringVectorBuilder, @@ -219,9 +232,9 @@ impl InformationSchemaTablesBuilder { max_index_length: UInt64VectorBuilder::with_capacity(INIT_CAPACITY), data_free: UInt64VectorBuilder::with_capacity(INIT_CAPACITY), auto_increment: UInt64VectorBuilder::with_capacity(INIT_CAPACITY), - create_time: DateTimeVectorBuilder::with_capacity(INIT_CAPACITY), - update_time: DateTimeVectorBuilder::with_capacity(INIT_CAPACITY), - check_time: DateTimeVectorBuilder::with_capacity(INIT_CAPACITY), + create_time: TimestampMicrosecondVectorBuilder::with_capacity(INIT_CAPACITY), + update_time: TimestampMicrosecondVectorBuilder::with_capacity(INIT_CAPACITY), + check_time: TimestampMicrosecondVectorBuilder::with_capacity(INIT_CAPACITY), table_collation: StringVectorBuilder::with_capacity(INIT_CAPACITY), checksum: UInt64VectorBuilder::with_capacity(INIT_CAPACITY), create_options: StringVectorBuilder::with_capacity(INIT_CAPACITY), diff --git a/src/catalog/src/system_schema/utils/tables.rs b/src/catalog/src/system_schema/utils/tables.rs index c645971776..fa71e2df4a 100644 --- a/src/catalog/src/system_schema/utils/tables.rs +++ b/src/catalog/src/system_schema/utils/tables.rs @@ -51,10 +51,10 @@ pub fn bigint_column(name: &str) -> ColumnSchema { ) } -pub fn datetime_column(name: &str) -> ColumnSchema { +pub fn timestamp_micro_column(name: &str) -> ColumnSchema { ColumnSchema::new( str::to_lowercase(name), - ConcreteDataType::datetime_datatype(), + ConcreteDataType::timestamp_microsecond_datatype(), false, ) } diff --git a/src/common/function/src/scalars/date/date_format.rs b/src/common/function/src/scalars/date/date_format.rs index ba1a31b1f6..478447f260 100644 --- a/src/common/function/src/scalars/date/date_format.rs +++ b/src/common/function/src/scalars/date/date_format.rs @@ -43,7 +43,6 @@ impl Function for DateFormatFunction { helper::one_of_sigs2( vec![ ConcreteDataType::date_datatype(), - ConcreteDataType::datetime_datatype(), ConcreteDataType::timestamp_second_datatype(), ConcreteDataType::timestamp_millisecond_datatype(), ConcreteDataType::timestamp_microsecond_datatype(), @@ -105,22 +104,6 @@ impl Function for DateFormatFunction { results.push(result.as_deref()); } } - ConcreteDataType::DateTime(_) => { - for i in 0..size { - let datetime = left.get(i).as_datetime(); - let format = formats.get(i).as_string(); - - let result = match (datetime, format) { - (Some(datetime), Some(fmt)) => datetime - .as_formatted_string(&fmt, Some(&func_ctx.query_ctx.timezone())) - .map_err(BoxedError::new) - .context(error::ExecuteSnafu)?, - _ => None, - }; - - results.push(result.as_deref()); - } - } _ => { return UnsupportedInputDataTypeSnafu { function: NAME, @@ -147,7 +130,7 @@ mod tests { use common_query::prelude::{TypeSignature, Volatility}; use datatypes::prelude::{ConcreteDataType, ScalarVector}; use datatypes::value::Value; - use datatypes::vectors::{DateTimeVector, DateVector, StringVector, TimestampSecondVector}; + use datatypes::vectors::{DateVector, StringVector, TimestampSecondVector}; use super::{DateFormatFunction, *}; @@ -169,16 +152,11 @@ mod tests { ConcreteDataType::string_datatype(), f.return_type(&[ConcreteDataType::date_datatype()]).unwrap() ); - assert_eq!( - ConcreteDataType::string_datatype(), - f.return_type(&[ConcreteDataType::datetime_datatype()]) - .unwrap() - ); assert!(matches!(f.signature(), Signature { type_signature: TypeSignature::OneOf(sigs), volatility: Volatility::Immutable - } if sigs.len() == 6)); + } if sigs.len() == 5)); } #[test] @@ -262,45 +240,4 @@ mod tests { } } } - - #[test] - fn test_datetime_date_format() { - let f = DateFormatFunction; - - let dates = vec![Some(123), None, Some(42), None]; - let formats = vec![ - "%Y-%m-%d %T.%3f", - "%Y-%m-%d %T.%3f", - "%Y-%m-%d %T.%3f", - "%Y-%m-%d %T.%3f", - ]; - let results = [ - Some("1970-01-01 00:00:00.123"), - None, - Some("1970-01-01 00:00:00.042"), - None, - ]; - - let date_vector = DateTimeVector::from(dates.clone()); - let interval_vector = StringVector::from_vec(formats); - let args: Vec = vec![Arc::new(date_vector), Arc::new(interval_vector)]; - let vector = f.eval(&FunctionContext::default(), &args).unwrap(); - - assert_eq!(4, vector.len()); - for (i, _t) in dates.iter().enumerate() { - let v = vector.get(i); - let result = results.get(i).unwrap(); - - if result.is_none() { - assert_eq!(Value::Null, v); - continue; - } - match v { - Value::String(s) => { - assert_eq!(s.as_utf8(), result.unwrap()); - } - _ => unreachable!(), - } - } - } } diff --git a/src/common/function/src/scalars/date/date_sub.rs b/src/common/function/src/scalars/date/date_sub.rs index da1155eebf..33a4596656 100644 --- a/src/common/function/src/scalars/date/date_sub.rs +++ b/src/common/function/src/scalars/date/date_sub.rs @@ -118,11 +118,6 @@ mod tests { ConcreteDataType::date_datatype(), f.return_type(&[ConcreteDataType::date_datatype()]).unwrap() ); - assert_eq!( - ConcreteDataType::datetime_datatype(), - f.return_type(&[ConcreteDataType::datetime_datatype()]) - .unwrap() - ); assert!( matches!(f.signature(), Signature { diff --git a/src/common/function/src/scalars/timestamp/greatest.rs b/src/common/function/src/scalars/timestamp/greatest.rs index 74cd6ad7d7..90b5c3d7bc 100644 --- a/src/common/function/src/scalars/timestamp/greatest.rs +++ b/src/common/function/src/scalars/timestamp/greatest.rs @@ -23,7 +23,7 @@ use datatypes::arrow::array::AsArray; use datatypes::arrow::compute::cast; use datatypes::arrow::compute::kernels::zip; use datatypes::arrow::datatypes::{ - DataType as ArrowDataType, Date32Type, Date64Type, TimestampMicrosecondType, + DataType as ArrowDataType, Date32Type, TimeUnit, TimestampMicrosecondType, TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType, }; use datatypes::prelude::ConcreteDataType; @@ -69,9 +69,8 @@ impl Function for GreatestFunction { ); match &input_types[0] { - ConcreteDataType::String(_) => Ok(ConcreteDataType::datetime_datatype()), + ConcreteDataType::String(_) => Ok(ConcreteDataType::timestamp_millisecond_datatype()), ConcreteDataType::Date(_) => Ok(ConcreteDataType::date_datatype()), - ConcreteDataType::DateTime(_) => Ok(ConcreteDataType::datetime_datatype()), ConcreteDataType::Timestamp(ts_type) => Ok(ConcreteDataType::Timestamp(*ts_type)), _ => UnsupportedInputDataTypeSnafu { function: NAME, @@ -87,7 +86,6 @@ impl Function for GreatestFunction { vec![ ConcreteDataType::string_datatype(), ConcreteDataType::date_datatype(), - ConcreteDataType::datetime_datatype(), ConcreteDataType::timestamp_nanosecond_datatype(), ConcreteDataType::timestamp_microsecond_datatype(), ConcreteDataType::timestamp_millisecond_datatype(), @@ -109,20 +107,24 @@ impl Function for GreatestFunction { ); match columns[0].data_type() { ConcreteDataType::String(_) => { - // Treats string as `DateTime` type. - let column1 = cast(&columns[0].to_arrow_array(), &ArrowDataType::Date64) - .context(ArrowComputeSnafu)?; - let column1 = column1.as_primitive::(); - let column2 = cast(&columns[1].to_arrow_array(), &ArrowDataType::Date64) - .context(ArrowComputeSnafu)?; - let column2 = column2.as_primitive::(); + let column1 = cast( + &columns[0].to_arrow_array(), + &ArrowDataType::Timestamp(TimeUnit::Millisecond, None), + ) + .context(ArrowComputeSnafu)?; + let column1 = column1.as_primitive::(); + let column2 = cast( + &columns[1].to_arrow_array(), + &ArrowDataType::Timestamp(TimeUnit::Millisecond, None), + ) + .context(ArrowComputeSnafu)?; + let column2 = column2.as_primitive::(); let boolean_array = gt(&column1, &column2).context(ArrowComputeSnafu)?; let result = zip::zip(&boolean_array, &column1, &column2).context(ArrowComputeSnafu)?; Ok(Helper::try_into_vector(&result).context(error::FromArrowArraySnafu)?) } ConcreteDataType::Date(_) => gt_time_types!(Date32Type, columns), - ConcreteDataType::DateTime(_) => gt_time_types!(Date64Type, columns), ConcreteDataType::Timestamp(ts_type) => match ts_type { TimestampType::Second(_) => gt_time_types!(TimestampSecondType, columns), TimestampType::Millisecond(_) => { @@ -155,15 +157,15 @@ mod tests { use std::sync::Arc; use common_time::timestamp::TimeUnit; - use common_time::{Date, DateTime, Timestamp}; + use common_time::{Date, Timestamp}; use datatypes::types::{ - DateTimeType, DateType, TimestampMicrosecondType, TimestampMillisecondType, - TimestampNanosecondType, TimestampSecondType, + DateType, TimestampMicrosecondType, TimestampMillisecondType, TimestampNanosecondType, + TimestampSecondType, }; use datatypes::value::Value; use datatypes::vectors::{ - DateTimeVector, DateVector, StringVector, TimestampMicrosecondVector, - TimestampMillisecondVector, TimestampNanosecondVector, TimestampSecondVector, Vector, + DateVector, StringVector, TimestampMicrosecondVector, TimestampMillisecondVector, + TimestampNanosecondVector, TimestampSecondVector, Vector, }; use paste::paste; @@ -178,7 +180,7 @@ mod tests { ConcreteDataType::string_datatype() ]) .unwrap(), - ConcreteDataType::DateTime(DateTimeType) + ConcreteDataType::timestamp_millisecond_datatype() ); let columns = vec![ Arc::new(StringVector::from(vec![ @@ -194,15 +196,18 @@ mod tests { let result = function .eval(&FunctionContext::default(), &columns) .unwrap(); - let result = result.as_any().downcast_ref::().unwrap(); + let result = result + .as_any() + .downcast_ref::() + .unwrap(); assert_eq!(result.len(), 2); assert_eq!( result.get(0), - Value::DateTime(DateTime::from_str("2001-02-01 00:00:00", None).unwrap()) + Value::Timestamp(Timestamp::from_str("2001-02-01 00:00:00", None).unwrap()) ); assert_eq!( result.get(1), - Value::DateTime(DateTime::from_str("2012-12-23 00:00:00", None).unwrap()) + Value::Timestamp(Timestamp::from_str("2012-12-23 00:00:00", None).unwrap()) ); } @@ -245,30 +250,33 @@ mod tests { assert_eq!( function .return_type(&[ - ConcreteDataType::datetime_datatype(), - ConcreteDataType::datetime_datatype() + ConcreteDataType::timestamp_millisecond_datatype(), + ConcreteDataType::timestamp_millisecond_datatype() ]) .unwrap(), - ConcreteDataType::DateTime(DateTimeType) + ConcreteDataType::timestamp_millisecond_datatype() ); let columns = vec![ - Arc::new(DateTimeVector::from_slice(vec![-1, 2])) as _, - Arc::new(DateTimeVector::from_slice(vec![0, 1])) as _, + Arc::new(TimestampMillisecondVector::from_slice(vec![-1, 2])) as _, + Arc::new(TimestampMillisecondVector::from_slice(vec![0, 1])) as _, ]; let result = function .eval(&FunctionContext::default(), &columns) .unwrap(); - let result = result.as_any().downcast_ref::().unwrap(); + let result = result + .as_any() + .downcast_ref::() + .unwrap(); assert_eq!(result.len(), 2); assert_eq!( result.get(0), - Value::DateTime(DateTime::from_str("1970-01-01 00:00:00", None).unwrap()) + Value::Timestamp(Timestamp::from_str("1970-01-01 00:00:00", None).unwrap()) ); assert_eq!( result.get(1), - Value::DateTime(DateTime::from_str("1970-01-01 00:00:00.002", None).unwrap()) + Value::Timestamp(Timestamp::from_str("1970-01-01 00:00:00.002", None).unwrap()) ); } diff --git a/src/common/function/src/scalars/timestamp/to_unixtime.rs b/src/common/function/src/scalars/timestamp/to_unixtime.rs index 11b014839a..6da80519f9 100644 --- a/src/common/function/src/scalars/timestamp/to_unixtime.rs +++ b/src/common/function/src/scalars/timestamp/to_unixtime.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use common_query::error::{InvalidFuncArgsSnafu, Result, UnsupportedInputDataTypeSnafu}; use common_query::prelude::{Signature, Volatility}; -use common_time::{Date, DateTime, Timestamp}; +use common_time::{Date, Timestamp}; use datatypes::prelude::ConcreteDataType; use datatypes::vectors::{Int64Vector, VectorRef}; use snafu::ensure; @@ -32,10 +32,6 @@ const NAME: &str = "to_unixtime"; fn convert_to_seconds(arg: &str, func_ctx: &FunctionContext) -> Option { let timezone = &func_ctx.query_ctx.timezone(); - if let Ok(dt) = DateTime::from_str(arg, Some(timezone)) { - return Some(dt.val() / 1000); - } - if let Ok(ts) = Timestamp::from_str(arg, Some(timezone)) { return Some(ts.split().0); } @@ -59,12 +55,6 @@ fn convert_dates_to_seconds(vector: &VectorRef) -> Vec> { .collect::>>() } -fn convert_datetimes_to_seconds(vector: &VectorRef) -> Vec> { - (0..vector.len()) - .map(|i| vector.get(i).as_datetime().map(|dt| dt.val() / 1000)) - .collect::>>() -} - impl Function for ToUnixtimeFunction { fn name(&self) -> &str { NAME @@ -82,7 +72,6 @@ impl Function for ToUnixtimeFunction { ConcreteDataType::int32_datatype(), ConcreteDataType::int64_datatype(), ConcreteDataType::date_datatype(), - ConcreteDataType::datetime_datatype(), ConcreteDataType::timestamp_second_datatype(), ConcreteDataType::timestamp_millisecond_datatype(), ConcreteDataType::timestamp_microsecond_datatype(), @@ -119,10 +108,6 @@ impl Function for ToUnixtimeFunction { let seconds = convert_dates_to_seconds(vector); Ok(Arc::new(Int64Vector::from(seconds))) } - ConcreteDataType::DateTime(_) => { - let seconds = convert_datetimes_to_seconds(vector); - Ok(Arc::new(Int64Vector::from(seconds))) - } ConcreteDataType::Timestamp(_) => { let seconds = convert_timestamps_to_seconds(vector); Ok(Arc::new(Int64Vector::from(seconds))) @@ -148,7 +133,7 @@ mod tests { use datatypes::prelude::ConcreteDataType; use datatypes::value::Value; use datatypes::vectors::{ - DateTimeVector, DateVector, StringVector, TimestampMillisecondVector, TimestampSecondVector, + DateVector, StringVector, TimestampMillisecondVector, TimestampSecondVector, }; use super::{ToUnixtimeFunction, *}; @@ -171,7 +156,6 @@ mod tests { ConcreteDataType::int32_datatype(), ConcreteDataType::int64_datatype(), ConcreteDataType::date_datatype(), - ConcreteDataType::datetime_datatype(), ConcreteDataType::timestamp_second_datatype(), ConcreteDataType::timestamp_millisecond_datatype(), ConcreteDataType::timestamp_microsecond_datatype(), @@ -253,31 +237,6 @@ mod tests { } } - #[test] - fn test_datetime_to_unixtime() { - let f = ToUnixtimeFunction; - - let times = vec![Some(123000), None, Some(42000), None]; - let results = [Some(123), None, Some(42), None]; - let date_vector = DateTimeVector::from(times.clone()); - let args: Vec = vec![Arc::new(date_vector)]; - let vector = f.eval(&FunctionContext::default(), &args).unwrap(); - assert_eq!(4, vector.len()); - for (i, _t) in times.iter().enumerate() { - let v = vector.get(i); - if i == 1 || i == 3 { - assert_eq!(Value::Null, v); - continue; - } - match v { - Value::Int64(ts) => { - assert_eq!(ts, (*results.get(i).unwrap()).unwrap()); - } - _ => unreachable!(), - } - } - } - #[test] fn test_timestamp_to_unixtime() { let f = ToUnixtimeFunction; diff --git a/src/common/grpc/src/select.rs b/src/common/grpc/src/select.rs index 25fad094e6..1cca03dc0f 100644 --- a/src/common/grpc/src/select.rs +++ b/src/common/grpc/src/select.rs @@ -17,8 +17,8 @@ use api::v1::column::Values; use common_base::BitVec; use datatypes::types::{IntervalType, TimeType, TimestampType, WrapperType}; use datatypes::vectors::{ - BinaryVector, BooleanVector, DateTimeVector, DateVector, Decimal128Vector, Float32Vector, - Float64Vector, Int16Vector, Int32Vector, Int64Vector, Int8Vector, IntervalDayTimeVector, + BinaryVector, BooleanVector, DateVector, Decimal128Vector, Float32Vector, Float64Vector, + Int16Vector, Int32Vector, Int64Vector, Int8Vector, IntervalDayTimeVector, IntervalMonthDayNanoVector, IntervalYearMonthVector, StringVector, TimeMicrosecondVector, TimeMillisecondVector, TimeNanosecondVector, TimeSecondVector, TimestampMicrosecondVector, TimestampMillisecondVector, TimestampNanosecondVector, TimestampSecondVector, UInt16Vector, @@ -141,12 +141,6 @@ pub fn values(arrays: &[VectorRef]) -> Result { (ConcreteDataType::Date(_), DateVector, date_values, |x| { x.val() }), - ( - ConcreteDataType::DateTime(_), - DateTimeVector, - datetime_values, - |x| { x.val() } - ), ( ConcreteDataType::Timestamp(TimestampType::Second(_)), TimestampSecondVector, diff --git a/src/common/time/src/datetime.rs b/src/common/time/src/datetime.rs deleted file mode 100644 index abeae4908a..0000000000 --- a/src/common/time/src/datetime.rs +++ /dev/null @@ -1,407 +0,0 @@ -// Copyright 2023 Greptime Team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::fmt::{Display, Formatter, Write}; - -use chrono::{ - Days, LocalResult, Months, NaiveDateTime, TimeDelta, TimeZone as ChronoTimeZone, Utc, -}; -use serde::{Deserialize, Serialize}; -use snafu::ResultExt; - -use crate::error::{InvalidDateStrSnafu, Result}; -use crate::interval::{IntervalDayTime, IntervalMonthDayNano, IntervalYearMonth}; -use crate::timezone::{get_timezone, Timezone}; -use crate::util::{datetime_to_utc, format_utc_datetime}; -use crate::Date; - -const DATETIME_FORMAT: &str = "%F %H:%M:%S%.f"; -const DATETIME_FORMAT_WITH_TZ: &str = "%F %H:%M:%S%.f%z"; - -/// [DateTime] represents the **milliseconds elapsed since "1970-01-01 00:00:00 UTC" (UNIX Epoch)**. -#[derive( - Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, -)] -pub struct DateTime(i64); - -impl Display for DateTime { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - if let Some(abs_time) = chrono::DateTime::from_timestamp_millis(self.0) { - write!( - f, - "{}", - format_utc_datetime(&abs_time.naive_utc(), DATETIME_FORMAT_WITH_TZ) - ) - } else { - write!(f, "DateTime({})", self.0) - } - } -} - -impl From for serde_json::Value { - fn from(d: DateTime) -> Self { - serde_json::Value::String(d.to_string()) - } -} - -impl From for DateTime { - fn from(value: NaiveDateTime) -> Self { - DateTime::from(value.and_utc().timestamp_millis()) - } -} - -impl From for DateTime { - fn from(v: i64) -> Self { - Self(v) - } -} - -impl From for DateTime { - fn from(value: Date) -> Self { - // It's safe, i32 * 86400000 won't be overflow - Self(value.to_secs() * 1000) - } -} - -impl DateTime { - /// Try parsing a string into [`DateTime`] with the system timezone. - /// See `DateTime::from_str`. - pub fn from_str_system(s: &str) -> Result { - Self::from_str(s, None) - } - - /// Try parsing a string into [`DateTime`] with the given timezone. - /// Supported format: - /// - RFC3339 in the naive UTC timezone. - /// - `%F %T` with the given timezone - /// - `%F %T%z` with the timezone in string - pub fn from_str(s: &str, timezone: Option<&Timezone>) -> Result { - let s = s.trim(); - let timestamp_millis = if let Ok(dt) = chrono::DateTime::parse_from_rfc3339(s) { - dt.naive_utc().and_utc().timestamp_millis() - } else if let Ok(d) = NaiveDateTime::parse_from_str(s, DATETIME_FORMAT) { - match datetime_to_utc(&d, get_timezone(timezone)) { - LocalResult::None => { - return InvalidDateStrSnafu { raw: s }.fail(); - } - LocalResult::Single(t) | LocalResult::Ambiguous(t, _) => { - t.and_utc().timestamp_millis() - } - } - } else if let Ok(v) = chrono::DateTime::parse_from_str(s, DATETIME_FORMAT_WITH_TZ) { - v.timestamp_millis() - } else { - return InvalidDateStrSnafu { raw: s }.fail(); - }; - - Ok(Self(timestamp_millis)) - } - - /// Create a new [DateTime] from milliseconds elapsed since "1970-01-01 00:00:00 UTC" (UNIX Epoch). - pub fn new(millis: i64) -> Self { - Self(millis) - } - - /// Get the milliseconds elapsed since "1970-01-01 00:00:00 UTC" (UNIX Epoch). - pub fn val(&self) -> i64 { - self.0 - } - - /// Convert to [NaiveDateTime]. - pub fn to_chrono_datetime(&self) -> Option { - chrono::DateTime::from_timestamp_millis(self.0).map(|x| x.naive_utc()) - } - - /// Format DateTime for given format and timezone. - /// If `tz==None`, the server default timezone will used. - pub fn as_formatted_string( - self, - pattern: &str, - timezone: Option<&Timezone>, - ) -> Result> { - if let Some(v) = self.to_chrono_datetime() { - let mut formatted = String::new(); - - match get_timezone(timezone) { - Timezone::Offset(offset) => { - write!( - formatted, - "{}", - offset.from_utc_datetime(&v).format(pattern) - ) - .context(crate::error::FormatSnafu { pattern })?; - } - Timezone::Named(tz) => { - write!(formatted, "{}", tz.from_utc_datetime(&v).format(pattern)) - .context(crate::error::FormatSnafu { pattern })?; - } - } - - return Ok(Some(formatted)); - } - - Ok(None) - } - - pub fn to_chrono_datetime_with_timezone(&self, tz: Option<&Timezone>) -> Option { - let datetime = self.to_chrono_datetime(); - datetime.map(|v| match tz { - Some(Timezone::Offset(offset)) => offset.from_utc_datetime(&v).naive_local(), - Some(Timezone::Named(tz)) => tz.from_utc_datetime(&v).naive_local(), - None => Utc.from_utc_datetime(&v).naive_local(), - }) - } - - // FIXME(yingwen): remove add/sub intervals later - /// Adds given [IntervalYearMonth] to the current datetime. - pub fn add_year_month(&self, interval: IntervalYearMonth) -> Option { - let naive_datetime = self.to_chrono_datetime()?; - - naive_datetime - .checked_add_months(Months::new(interval.months as u32)) - .map(Into::into) - } - - /// Adds given [IntervalDayTime] to the current datetime. - pub fn add_day_time(&self, interval: IntervalDayTime) -> Option { - let naive_datetime = self.to_chrono_datetime()?; - - naive_datetime - .checked_add_days(Days::new(interval.days as u64))? - .checked_add_signed(TimeDelta::milliseconds(interval.milliseconds as i64)) - .map(Into::into) - } - - /// Adds given [IntervalMonthDayNano] to the current datetime. - pub fn add_month_day_nano(&self, interval: IntervalMonthDayNano) -> Option { - let naive_datetime = self.to_chrono_datetime()?; - - naive_datetime - .checked_add_months(Months::new(interval.months as u32))? - .checked_add_days(Days::new(interval.days as u64))? - .checked_add_signed(TimeDelta::nanoseconds(interval.nanoseconds)) - .map(Into::into) - } - - /// Subtracts given [IntervalYearMonth] to the current datetime. - pub fn sub_year_month(&self, interval: IntervalYearMonth) -> Option { - let naive_datetime = self.to_chrono_datetime()?; - - naive_datetime - .checked_sub_months(Months::new(interval.months as u32)) - .map(Into::into) - } - - /// Subtracts given [IntervalDayTime] to the current datetime. - pub fn sub_day_time(&self, interval: IntervalDayTime) -> Option { - let naive_datetime = self.to_chrono_datetime()?; - - naive_datetime - .checked_sub_days(Days::new(interval.days as u64))? - .checked_sub_signed(TimeDelta::milliseconds(interval.milliseconds as i64)) - .map(Into::into) - } - - /// Subtracts given [IntervalMonthDayNano] to the current datetime. - pub fn sub_month_day_nano(&self, interval: IntervalMonthDayNano) -> Option { - let naive_datetime = self.to_chrono_datetime()?; - - naive_datetime - .checked_sub_months(Months::new(interval.months as u32))? - .checked_sub_days(Days::new(interval.days as u64))? - .checked_sub_signed(TimeDelta::nanoseconds(interval.nanoseconds)) - .map(Into::into) - } - - /// Convert to [common_time::date]. - pub fn to_date(&self) -> Option { - self.to_chrono_datetime().map(|d| Date::from(d.date())) - } - - pub fn negative(&self) -> Self { - Self(-self.0) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::timezone::set_default_timezone; - - #[test] - pub fn test_new_date_time() { - set_default_timezone(Some("Asia/Shanghai")).unwrap(); - assert_eq!("1970-01-01 08:00:00+0800", DateTime::new(0).to_string()); - assert_eq!("1970-01-01 08:00:01+0800", DateTime::new(1000).to_string()); - assert_eq!("1970-01-01 07:59:59+0800", DateTime::new(-1000).to_string()); - } - - #[test] - pub fn test_parse_from_string() { - set_default_timezone(Some("Asia/Shanghai")).unwrap(); - let time = "1970-01-01 00:00:00+0800"; - let dt = DateTime::from_str(time, None).unwrap(); - assert_eq!(time, &dt.to_string()); - let dt = DateTime::from_str(" 1970-01-01 00:00:00+0800 ", None).unwrap(); - assert_eq!(time, &dt.to_string()); - } - - #[test] - pub fn test_from() { - let d: DateTime = 42.into(); - assert_eq!(42, d.val()); - } - - #[test] - fn test_add_sub_interval() { - let datetime = DateTime::new(1000); - - let interval = IntervalDayTime::new(1, 200); - - let new_datetime = datetime.add_day_time(interval).unwrap(); - assert_eq!(new_datetime.val(), 1000 + 3600 * 24 * 1000 + 200); - - assert_eq!(datetime, new_datetime.sub_day_time(interval).unwrap()); - } - - #[test] - fn test_parse_local_date_time() { - set_default_timezone(Some("Asia/Shanghai")).unwrap(); - assert_eq!( - -28800000, - DateTime::from_str("1970-01-01 00:00:00", None) - .unwrap() - .val() - ); - assert_eq!( - 0, - DateTime::from_str("1970-01-01 08:00:00", None) - .unwrap() - .val() - ); - assert_eq!( - 42, - DateTime::from_str("1970-01-01 08:00:00.042", None) - .unwrap() - .val() - ); - assert_eq!( - 42, - DateTime::from_str("1970-01-01 08:00:00.042424", None) - .unwrap() - .val() - ); - - assert_eq!( - 0, - DateTime::from_str( - "1970-01-01 08:00:00", - Some(&Timezone::from_tz_string("Asia/Shanghai").unwrap()) - ) - .unwrap() - .val() - ); - - assert_eq!( - -28800000, - DateTime::from_str( - "1970-01-01 00:00:00", - Some(&Timezone::from_tz_string("Asia/Shanghai").unwrap()) - ) - .unwrap() - .val() - ); - - assert_eq!( - 28800000, - DateTime::from_str( - "1970-01-01 00:00:00", - Some(&Timezone::from_tz_string("-8:00").unwrap()) - ) - .unwrap() - .val() - ); - } - - #[test] - fn test_parse_local_date_time_with_tz() { - let ts = DateTime::from_str("1970-01-01 08:00:00+0000", None) - .unwrap() - .val(); - assert_eq!(28800000, ts); - let ts = DateTime::from_str("1970-01-01 00:00:00.042+0000", None) - .unwrap() - .val(); - assert_eq!(42, ts); - - // the string has the time zone info, the argument doesn't change the result - let ts = DateTime::from_str( - "1970-01-01 08:00:00+0000", - Some(&Timezone::from_tz_string("-8:00").unwrap()), - ) - .unwrap() - .val(); - assert_eq!(28800000, ts); - } - - #[test] - fn test_as_formatted_string() { - let d: DateTime = DateTime::new(1000); - - assert_eq!( - "1970-01-01", - d.as_formatted_string("%Y-%m-%d", None).unwrap().unwrap() - ); - assert_eq!( - "1970-01-01 00:00:01", - d.as_formatted_string("%Y-%m-%d %H:%M:%S", None) - .unwrap() - .unwrap() - ); - assert_eq!( - "1970-01-01T00:00:01:000", - d.as_formatted_string("%Y-%m-%dT%H:%M:%S:%3f", None) - .unwrap() - .unwrap() - ); - - assert_eq!( - "1970-01-01T08:00:01:000", - d.as_formatted_string( - "%Y-%m-%dT%H:%M:%S:%3f", - Some(&Timezone::from_tz_string("Asia/Shanghai").unwrap()) - ) - .unwrap() - .unwrap() - ); - } - - #[test] - fn test_from_max_date() { - let date = Date::new(i32::MAX); - let datetime = DateTime::from(date); - assert_eq!(datetime.val(), 185542587100800000); - } - - #[test] - fn test_conversion_between_datetime_and_chrono_datetime() { - let cases = [1, 10, 100, 1000, 100000]; - for case in cases { - let dt = DateTime::new(case); - let ndt = dt.to_chrono_datetime().unwrap(); - let dt2 = DateTime::from(ndt); - assert_eq!(dt, dt2); - } - } -} diff --git a/src/common/time/src/lib.rs b/src/common/time/src/lib.rs index feb19cf9a1..66a9f887c1 100644 --- a/src/common/time/src/lib.rs +++ b/src/common/time/src/lib.rs @@ -13,7 +13,6 @@ // limitations under the License. pub mod date; -pub mod datetime; pub mod duration; pub mod error; pub mod interval; @@ -26,7 +25,6 @@ pub mod ttl; pub mod util; pub use date::Date; -pub use datetime::DateTime; pub use duration::Duration; pub use interval::{IntervalDayTime, IntervalMonthDayNano, IntervalYearMonth}; pub use range::RangeMillis; diff --git a/src/datatypes/src/data_type.rs b/src/datatypes/src/data_type.rs index b3342cc6f5..b954a1f2e0 100644 --- a/src/datatypes/src/data_type.rs +++ b/src/datatypes/src/data_type.rs @@ -30,13 +30,13 @@ use serde::{Deserialize, Serialize}; use crate::error::{self, Error, Result}; use crate::type_id::LogicalTypeId; use crate::types::{ - BinaryType, BooleanType, DateTimeType, DateType, Decimal128Type, DictionaryType, - DurationMicrosecondType, DurationMillisecondType, DurationNanosecondType, DurationSecondType, - DurationType, Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, - IntervalDayTimeType, IntervalMonthDayNanoType, IntervalType, IntervalYearMonthType, JsonType, - ListType, NullType, StringType, TimeMillisecondType, TimeType, TimestampMicrosecondType, - TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType, TimestampType, - UInt16Type, UInt32Type, UInt64Type, UInt8Type, VectorType, + BinaryType, BooleanType, DateType, Decimal128Type, DictionaryType, DurationMicrosecondType, + DurationMillisecondType, DurationNanosecondType, DurationSecondType, DurationType, Float32Type, + Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, IntervalDayTimeType, + IntervalMonthDayNanoType, IntervalType, IntervalYearMonthType, JsonType, ListType, NullType, + StringType, TimeMillisecondType, TimeType, TimestampMicrosecondType, TimestampMillisecondType, + TimestampNanosecondType, TimestampSecondType, TimestampType, UInt16Type, UInt32Type, + UInt64Type, UInt8Type, VectorType, }; use crate::value::Value; use crate::vectors::MutableVector; @@ -68,7 +68,6 @@ pub enum ConcreteDataType { // Date and time types: Date(DateType), - DateTime(DateTimeType), Timestamp(TimestampType), Time(TimeType), @@ -107,7 +106,6 @@ impl fmt::Display for ConcreteDataType { ConcreteDataType::Binary(v) => write!(f, "{}", v.name()), ConcreteDataType::String(v) => write!(f, "{}", v.name()), ConcreteDataType::Date(v) => write!(f, "{}", v.name()), - ConcreteDataType::DateTime(v) => write!(f, "{}", v.name()), ConcreteDataType::Timestamp(t) => match t { TimestampType::Second(v) => write!(f, "{}", v.name()), TimestampType::Millisecond(v) => write!(f, "{}", v.name()), @@ -163,7 +161,6 @@ impl ConcreteDataType { self, ConcreteDataType::String(_) | ConcreteDataType::Date(_) - | ConcreteDataType::DateTime(_) | ConcreteDataType::Timestamp(_) | ConcreteDataType::Time(_) | ConcreteDataType::Interval(_) @@ -183,7 +180,6 @@ impl ConcreteDataType { | ConcreteDataType::Int32(_) | ConcreteDataType::Int64(_) | ConcreteDataType::Date(_) - | ConcreteDataType::DateTime(_) | ConcreteDataType::Timestamp(_) | ConcreteDataType::Time(_) | ConcreteDataType::Interval(_) @@ -385,7 +381,7 @@ impl ConcreteDataType { &ConcreteDataType::Binary(_) | &ConcreteDataType::Vector(_) => "BYTEA", &ConcreteDataType::String(_) => "VARCHAR", &ConcreteDataType::Date(_) => "DATE", - &ConcreteDataType::DateTime(_) | &ConcreteDataType::Timestamp(_) => "TIMESTAMP", + &ConcreteDataType::Timestamp(_) => "TIMESTAMP", &ConcreteDataType::Time(_) => "TIME", &ConcreteDataType::Interval(_) => "INTERVAL", &ConcreteDataType::Decimal128(_) => "NUMERIC", @@ -402,7 +398,7 @@ impl ConcreteDataType { &ConcreteDataType::Binary(_) => "_BYTEA", &ConcreteDataType::String(_) => "_VARCHAR", &ConcreteDataType::Date(_) => "_DATE", - &ConcreteDataType::DateTime(_) | &ConcreteDataType::Timestamp(_) => "_TIMESTAMP", + &ConcreteDataType::Timestamp(_) => "_TIMESTAMP", &ConcreteDataType::Time(_) => "_TIME", &ConcreteDataType::Interval(_) => "_INTERVAL", &ConcreteDataType::Decimal128(_) => "_NUMERIC", @@ -441,7 +437,6 @@ impl TryFrom<&ArrowDataType> for ConcreteDataType { ArrowDataType::Float32 => Self::float32_datatype(), ArrowDataType::Float64 => Self::float64_datatype(), ArrowDataType::Date32 => Self::date_datatype(), - ArrowDataType::Date64 => Self::datetime_datatype(), ArrowDataType::Timestamp(u, _) => ConcreteDataType::from_arrow_time_unit(u), ArrowDataType::Interval(u) => ConcreteDataType::from_arrow_interval_unit(u), ArrowDataType::Binary | ArrowDataType::LargeBinary => Self::binary_datatype(), @@ -490,7 +485,7 @@ macro_rules! impl_new_concrete_type_functions { impl_new_concrete_type_functions!( Null, Boolean, UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Float32, Float64, - Binary, Date, DateTime, String, Json + Binary, Date, String, Json ); impl ConcreteDataType { @@ -814,7 +809,6 @@ mod tests { assert!(ConcreteDataType::string_datatype().is_stringifiable()); assert!(ConcreteDataType::binary_datatype().is_stringifiable()); assert!(ConcreteDataType::date_datatype().is_stringifiable()); - assert!(ConcreteDataType::datetime_datatype().is_stringifiable()); assert!(ConcreteDataType::timestamp_second_datatype().is_stringifiable()); assert!(ConcreteDataType::timestamp_millisecond_datatype().is_stringifiable()); assert!(ConcreteDataType::timestamp_microsecond_datatype().is_stringifiable()); @@ -843,7 +837,6 @@ mod tests { assert!(ConcreteDataType::int32_datatype().is_signed()); assert!(ConcreteDataType::int64_datatype().is_signed()); assert!(ConcreteDataType::date_datatype().is_signed()); - assert!(ConcreteDataType::datetime_datatype().is_signed()); assert!(ConcreteDataType::timestamp_second_datatype().is_signed()); assert!(ConcreteDataType::timestamp_millisecond_datatype().is_signed()); assert!(ConcreteDataType::timestamp_microsecond_datatype().is_signed()); @@ -878,7 +871,6 @@ mod tests { assert!(!ConcreteDataType::int32_datatype().is_unsigned()); assert!(!ConcreteDataType::int64_datatype().is_unsigned()); assert!(!ConcreteDataType::date_datatype().is_unsigned()); - assert!(!ConcreteDataType::datetime_datatype().is_unsigned()); assert!(!ConcreteDataType::timestamp_second_datatype().is_unsigned()); assert!(!ConcreteDataType::timestamp_millisecond_datatype().is_unsigned()); assert!(!ConcreteDataType::timestamp_microsecond_datatype().is_unsigned()); diff --git a/src/datatypes/src/scalars.rs b/src/datatypes/src/scalars.rs index 2db5bcd3cd..4ac823704c 100644 --- a/src/datatypes/src/scalars.rs +++ b/src/datatypes/src/scalars.rs @@ -15,7 +15,7 @@ use std::any::Any; use common_decimal::Decimal128; -use common_time::{Date, DateTime}; +use common_time::Date; use crate::types::{ Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, UInt16Type, UInt32Type, @@ -23,8 +23,8 @@ use crate::types::{ }; use crate::value::{ListValue, ListValueRef, Value}; use crate::vectors::{ - BinaryVector, BooleanVector, DateTimeVector, DateVector, Decimal128Vector, ListVector, - MutableVector, PrimitiveVector, StringVector, Vector, + BinaryVector, BooleanVector, DateVector, Decimal128Vector, ListVector, MutableVector, + PrimitiveVector, StringVector, Vector, }; fn get_iter_capacity>(iter: &I) -> usize { @@ -302,27 +302,6 @@ impl ScalarRef<'_> for Decimal128 { } } -impl Scalar for DateTime { - type VectorType = DateTimeVector; - type RefType<'a> = DateTime; - - fn as_scalar_ref(&self) -> Self::RefType<'_> { - *self - } - - fn upcast_gat<'short, 'long: 'short>(long: Self::RefType<'long>) -> Self::RefType<'short> { - long - } -} - -impl ScalarRef<'_> for DateTime { - type ScalarType = DateTime; - - fn to_owned_scalar(&self) -> Self::ScalarType { - *self - } -} - // Timestamp types implement Scalar and ScalarRef in `src/timestamp.rs`. impl Scalar for ListValue { @@ -428,13 +407,6 @@ mod tests { assert_eq!(decimal, decimal.to_owned_scalar()); } - #[test] - fn test_datetime_scalar() { - let dt = DateTime::new(123); - assert_eq!(dt, dt.as_scalar_ref()); - assert_eq!(dt, dt.to_owned_scalar()); - } - #[test] fn test_list_value_scalar() { let list_value = diff --git a/src/datatypes/src/type_id.rs b/src/datatypes/src/type_id.rs index eafb0202d9..3fa3bb9b9e 100644 --- a/src/datatypes/src/type_id.rs +++ b/src/datatypes/src/type_id.rs @@ -40,9 +40,6 @@ pub enum LogicalTypeId { /// Date representing the elapsed time since UNIX epoch (1970-01-01) /// in days (32 bits). Date, - /// Datetime representing the elapsed time since UNIX epoch (1970-01-01) in - /// seconds/milliseconds/microseconds/nanoseconds, determined by precision. - DateTime, TimestampSecond, TimestampMillisecond, @@ -100,7 +97,6 @@ impl LogicalTypeId { LogicalTypeId::String => ConcreteDataType::string_datatype(), LogicalTypeId::Binary => ConcreteDataType::binary_datatype(), LogicalTypeId::Date => ConcreteDataType::date_datatype(), - LogicalTypeId::DateTime => ConcreteDataType::datetime_datatype(), LogicalTypeId::TimestampSecond => ConcreteDataType::timestamp_second_datatype(), LogicalTypeId::TimestampMillisecond => { ConcreteDataType::timestamp_millisecond_datatype() diff --git a/src/datatypes/src/types.rs b/src/datatypes/src/types.rs index af7016ff82..6f7213be49 100644 --- a/src/datatypes/src/types.rs +++ b/src/datatypes/src/types.rs @@ -16,7 +16,6 @@ mod binary_type; mod boolean_type; pub mod cast; mod date_type; -mod datetime_type; mod decimal_type; mod dictionary_type; mod duration_type; @@ -34,7 +33,6 @@ pub use binary_type::BinaryType; pub use boolean_type::BooleanType; pub use cast::{cast, cast_with_opt}; pub use date_type::DateType; -pub use datetime_type::DateTimeType; pub use decimal_type::Decimal128Type; pub use dictionary_type::DictionaryType; pub use duration_type::{ diff --git a/src/datatypes/src/types/cast.rs b/src/datatypes/src/types/cast.rs index c369baa4ae..2330814f81 100644 --- a/src/datatypes/src/types/cast.rs +++ b/src/datatypes/src/types/cast.rs @@ -119,10 +119,6 @@ pub fn can_cast_type(src_value: &Value, dest_type: &ConcreteDataType) -> bool { (Date(_), Int32(_) | Timestamp(_) | String(_)) => true, (Int32(_) | String(_) | Timestamp(_), Date(_)) => true, (Date(_), Date(_)) => true, - // DateTime type - (DateTime(_), Int64(_) | Timestamp(_) | String(_)) => true, - (Int64(_) | Timestamp(_) | String(_), DateTime(_)) => true, - (DateTime(_), DateTime(_)) => true, // Timestamp type (Timestamp(_), Int64(_) | String(_)) => true, (Int64(_) | String(_), Timestamp(_)) => true, @@ -175,7 +171,7 @@ mod tests { use common_base::bytes::StringBytes; use common_time::time::Time; use common_time::timezone::set_default_timezone; - use common_time::{Date, DateTime, Timestamp}; + use common_time::{Date, Timestamp}; use ordered_float::OrderedFloat; use super::*; @@ -274,7 +270,6 @@ mod tests { null_datatype, boolean_datatype, date_datatype, - datetime_datatype, timestamp_second_datatype, binary_datatype ); @@ -287,23 +282,12 @@ mod tests { timestamp_second_datatype, string_datatype ); - - // datetime -> other types - test_can_cast!( - Value::DateTime(DateTime::from_str_system("2021-01-01 00:00:00").unwrap()), - null_datatype, - int64_datatype, - timestamp_second_datatype, - string_datatype - ); - // timestamp -> other types test_can_cast!( Value::Timestamp(Timestamp::from_str_utc("2021-01-01 00:00:00").unwrap()), null_datatype, int64_datatype, date_datatype, - datetime_datatype, string_datatype ); diff --git a/src/datatypes/src/types/date_type.rs b/src/datatypes/src/types/date_type.rs index 5481b6fa5b..7c60222529 100644 --- a/src/datatypes/src/types/date_type.rs +++ b/src/datatypes/src/types/date_type.rs @@ -55,7 +55,6 @@ impl DataType for DateType { Value::Int32(v) => Some(Value::Date(Date::from(v))), Value::String(v) => Date::from_str_utc(v.as_utf8()).map(Value::Date).ok(), Value::Timestamp(v) => v.to_chrono_date().map(|date| Value::Date(date.into())), - Value::DateTime(v) => Some(Value::DateTime(v)), _ => None, } } diff --git a/src/datatypes/src/types/datetime_type.rs b/src/datatypes/src/types/datetime_type.rs deleted file mode 100644 index 10e55000c2..0000000000 --- a/src/datatypes/src/types/datetime_type.rs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2023 Greptime Team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use arrow::datatypes::{DataType as ArrowDataType, Date64Type}; -use common_time::DateTime; -use serde::{Deserialize, Serialize}; -use snafu::OptionExt; - -use crate::data_type::{ConcreteDataType, DataType}; -use crate::error::{self, Result}; -use crate::prelude::{LogicalTypeId, MutableVector, ScalarVectorBuilder, Value, ValueRef, Vector}; -use crate::types::LogicalPrimitiveType; -use crate::vectors::{DateTimeVector, DateTimeVectorBuilder, PrimitiveVector}; - -const MILLISECOND_VARIATION: u64 = 3; -/// Data type for [`DateTime`]. -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] -pub struct DateTimeType; - -impl DateTimeType { - pub fn precision(&self) -> u64 { - MILLISECOND_VARIATION - } -} - -impl DataType for DateTimeType { - fn name(&self) -> String { - "DateTime".to_string() - } - - fn logical_type_id(&self) -> LogicalTypeId { - LogicalTypeId::DateTime - } - - fn default_value(&self) -> Value { - Value::DateTime(DateTime::default()) - } - - fn as_arrow_type(&self) -> ArrowDataType { - ArrowDataType::Date64 - } - - fn create_mutable_vector(&self, capacity: usize) -> Box { - Box::new(DateTimeVectorBuilder::with_capacity(capacity)) - } - - fn try_cast(&self, from: Value) -> Option { - match from { - Value::Int64(v) => Some(Value::DateTime(DateTime::from(v))), - Value::Timestamp(v) => v.to_chrono_datetime().map(|d| Value::DateTime(d.into())), - Value::String(v) => DateTime::from_str_system(v.as_utf8()) - .map(Value::DateTime) - .ok(), - _ => None, - } - } -} - -impl LogicalPrimitiveType for DateTimeType { - type ArrowPrimitive = Date64Type; - type Native = i64; - type Wrapper = DateTime; - type LargestType = Self; - - fn build_data_type() -> ConcreteDataType { - ConcreteDataType::datetime_datatype() - } - - fn type_name() -> &'static str { - "DateTime" - } - - fn cast_vector(vector: &dyn Vector) -> Result<&PrimitiveVector> { - vector - .as_any() - .downcast_ref::() - .with_context(|| error::CastTypeSnafu { - msg: format!( - "Failed to cast {} to DateTimeVector", - vector.vector_type_name() - ), - }) - } - - fn cast_value_ref(value: ValueRef) -> Result> { - match value { - ValueRef::Null => Ok(None), - ValueRef::DateTime(v) => Ok(Some(v)), - other => error::CastTypeSnafu { - msg: format!("Failed to cast value {other:?} to DateTime"), - } - .fail(), - } - } -} - -#[cfg(test)] -mod tests { - - use common_time::timezone::set_default_timezone; - use common_time::Timestamp; - - use super::*; - - #[test] - fn test_datetime_cast() { - // cast from Int64 - let val = Value::Int64(1000); - let dt = ConcreteDataType::datetime_datatype().try_cast(val).unwrap(); - assert_eq!(dt, Value::DateTime(DateTime::from(1000))); - - // cast from String - set_default_timezone(Some("Asia/Shanghai")).unwrap(); - let val = Value::String("1970-01-01 00:00:00+0800".into()); - let dt = ConcreteDataType::datetime_datatype().try_cast(val).unwrap(); - assert_eq!( - dt, - Value::DateTime(DateTime::from_str_system("1970-01-01 00:00:00+0800").unwrap()) - ); - - // cast from Timestamp - let val = Value::Timestamp(Timestamp::from_str_utc("2020-09-08 21:42:29+0800").unwrap()); - let dt = ConcreteDataType::datetime_datatype().try_cast(val).unwrap(); - assert_eq!( - dt, - Value::DateTime(DateTime::from_str_system("2020-09-08 21:42:29+0800").unwrap()) - ); - } -} diff --git a/src/datatypes/src/types/primitive_type.rs b/src/datatypes/src/types/primitive_type.rs index cc41f3099f..9b074eea32 100644 --- a/src/datatypes/src/types/primitive_type.rs +++ b/src/datatypes/src/types/primitive_type.rs @@ -16,7 +16,7 @@ use std::cmp::Ordering; use std::fmt; use arrow::datatypes::{ArrowNativeType, ArrowPrimitiveType, DataType as ArrowDataType}; -use common_time::{Date, DateTime}; +use common_time::Date; use serde::{Deserialize, Serialize}; use snafu::OptionExt; @@ -25,7 +25,7 @@ use crate::error::{self, Result}; use crate::scalars::{Scalar, ScalarRef, ScalarVectorBuilder}; use crate::type_id::LogicalTypeId; use crate::types::boolean_type::bool_to_numeric; -use crate::types::{DateTimeType, DateType}; +use crate::types::DateType; use crate::value::{Value, ValueRef}; use crate::vectors::{MutableVector, PrimitiveVector, PrimitiveVectorBuilder, Vector}; @@ -157,19 +157,6 @@ impl WrapperType for Date { } } -impl WrapperType for DateTime { - type LogicalType = DateTimeType; - type Native = i64; - - fn from_native(value: Self::Native) -> Self { - DateTime::new(value) - } - - fn into_native(self) -> Self::Native { - self.val() - } -} - macro_rules! define_logical_primitive_type { ($Native: ident, $TypeId: ident, $DataType: ident, $Largest: ident) => { // We need to define it as an empty struct `struct DataType {}` instead of a struct-unit @@ -362,7 +349,6 @@ impl DataType for Int64Type { Value::Float32(v) => num::cast::cast(v).map(Value::Int64), Value::Float64(v) => num::cast::cast(v).map(Value::Int64), Value::String(v) => v.as_utf8().parse::().map(Value::Int64).ok(), - Value::DateTime(v) => Some(Value::Int64(v.val())), Value::Timestamp(v) => Some(Value::Int64(v.value())), Value::Time(v) => Some(Value::Int64(v.value())), // We don't allow casting interval type to int. diff --git a/src/datatypes/src/types/string_type.rs b/src/datatypes/src/types/string_type.rs index 06a5e7c7f6..4cf0522b1f 100644 --- a/src/datatypes/src/types/string_type.rs +++ b/src/datatypes/src/types/string_type.rs @@ -75,7 +75,6 @@ impl DataType for StringType { Value::Float64(v) => Some(Value::String(StringBytes::from(v.to_string()))), Value::String(v) => Some(Value::String(v)), Value::Date(v) => Some(Value::String(StringBytes::from(v.to_string()))), - Value::DateTime(v) => Some(Value::String(StringBytes::from(v.to_string()))), Value::Timestamp(v) => Some(Value::String(StringBytes::from(v.to_iso8601_string()))), Value::Time(v) => Some(Value::String(StringBytes::from(v.to_iso8601_string()))), Value::IntervalYearMonth(v) => { diff --git a/src/datatypes/src/types/timestamp_type.rs b/src/datatypes/src/types/timestamp_type.rs index cda1c2603a..7e12c89d37 100644 --- a/src/datatypes/src/types/timestamp_type.rs +++ b/src/datatypes/src/types/timestamp_type.rs @@ -132,7 +132,6 @@ macro_rules! impl_data_type_for_timestamp { Value::Timestamp(v) => v.convert_to(TimeUnit::$unit).map(Value::Timestamp), Value::String(v) => Timestamp::from_str_utc(v.as_utf8()).map(Value::Timestamp).ok(), Value::Int64(v) => Some(Value::Timestamp(Timestamp::new(v, TimeUnit::$unit))), - Value::DateTime(v) => Timestamp::new_second(v.val()).convert_to(TimeUnit::$unit).map(Value::Timestamp), Value::Date(v) => Timestamp::new_second(v.to_secs()).convert_to(TimeUnit::$unit).map(Value::Timestamp), _ => None } @@ -202,7 +201,7 @@ impl_data_type_for_timestamp!(Microsecond); #[cfg(test)] mod tests { use common_time::timezone::set_default_timezone; - use common_time::{Date, DateTime}; + use common_time::Date; use super::*; @@ -249,13 +248,6 @@ mod tests { .unwrap(); assert_eq!(ts, Value::Timestamp(Timestamp::new_second(1694589525))); - // Datetime -> TimestampSecond - let dt = Value::DateTime(DateTime::from(1234567)); - let ts = ConcreteDataType::timestamp_second_datatype() - .try_cast(dt) - .unwrap(); - assert_eq!(ts, Value::Timestamp(Timestamp::new_second(1234567))); - // Date -> TimestampMillisecond let d = Value::Date(Date::from_str_utc("1970-01-01").unwrap()); let ts = ConcreteDataType::timestamp_millisecond_datatype() diff --git a/src/datatypes/src/value.rs b/src/datatypes/src/value.rs index 25aa9045e8..bf41d2b764 100644 --- a/src/datatypes/src/value.rs +++ b/src/datatypes/src/value.rs @@ -24,7 +24,6 @@ use common_base::bytes::{Bytes, StringBytes}; use common_decimal::Decimal128; use common_telemetry::error; use common_time::date::Date; -use common_time::datetime::DateTime; use common_time::interval::IntervalUnit; use common_time::time::Time; use common_time::timestamp::{TimeUnit, Timestamp}; @@ -75,7 +74,6 @@ pub enum Value { // Date & Time types: Date(Date), - DateTime(DateTime), Timestamp(Timestamp), Time(Time), Duration(Duration), @@ -112,7 +110,6 @@ impl Display for Value { write!(f, "{hex}") } Value::Date(v) => write!(f, "{v}"), - Value::DateTime(v) => write!(f, "{v}"), Value::Timestamp(v) => write!(f, "{}", v.to_iso8601_string()), Value::Time(t) => write!(f, "{}", t.to_iso8601_string()), Value::IntervalYearMonth(v) => { @@ -162,7 +159,6 @@ macro_rules! define_data_type_func { $struct::String(_) => ConcreteDataType::string_datatype(), $struct::Binary(_) => ConcreteDataType::binary_datatype(), $struct::Date(_) => ConcreteDataType::date_datatype(), - $struct::DateTime(_) => ConcreteDataType::datetime_datatype(), $struct::Time(t) => ConcreteDataType::time_datatype(*t.unit()), $struct::Timestamp(v) => ConcreteDataType::timestamp_datatype(v.unit()), $struct::IntervalYearMonth(_) => { @@ -222,7 +218,6 @@ impl Value { Value::String(v) => ValueRef::String(v.as_utf8()), Value::Binary(v) => ValueRef::Binary(v), Value::Date(v) => ValueRef::Date(*v), - Value::DateTime(v) => ValueRef::DateTime(*v), Value::List(v) => ValueRef::List(ListValueRef::Ref { val: v }), Value::Timestamp(v) => ValueRef::Timestamp(*v), Value::Time(v) => ValueRef::Time(*v), @@ -258,14 +253,6 @@ impl Value { } } - /// Cast Value to DateTime. Return None if value is not a valid datetime data type. - pub fn as_datetime(&self) -> Option { - match self { - Value::DateTime(t) => Some(*t), - _ => None, - } - } - /// Cast Value to [Time]. Return None if value is not a valid time data type. pub fn as_time(&self) -> Option