diff --git a/src/storage/table_codec.rs b/src/storage/table_codec.rs index c74aba96..bbe954ff 100644 --- a/src/storage/table_codec.rs +++ b/src/storage/table_codec.rs @@ -211,7 +211,7 @@ impl TableCodec { } /// NonUnique Index: - /// Key: {TableName}{INDEX_TAG}{BOUND_MIN_TAG}{IndexID}{BOUND_MIN_TAG}{DataValue1}{DataValue2} .. {TupleId} + /// Key: {TableName}{INDEX_TAG}{BOUND_MIN_TAG}{IndexID}{BOUND_MIN_TAG}{DataValue1}{BOUND_MIN_TAG}{DataValue2} .. {TupleId} /// Value: TupleID /// /// Unique Index: diff --git a/src/types/mod.rs b/src/types/mod.rs index 53aec131..1ec599b7 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -3,7 +3,7 @@ pub mod tuple; pub mod tuple_builder; pub mod value; -use chrono::{NaiveDate, NaiveDateTime}; +use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use std::any::TypeId; @@ -72,6 +72,8 @@ impl LogicalType { Some(LogicalType::Date) } else if type_id == TypeId::of::() { Some(LogicalType::DateTime) + } else if type_id == TypeId::of::() { + Some(LogicalType::Time) } else if type_id == TypeId::of::() { Some(LogicalType::Decimal(None, None)) } else if type_id == TypeId::of::() { diff --git a/src/types/value.rs b/src/types/value.rs index 0768b46c..e91f437f 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -807,6 +807,7 @@ impl DataValue { DataValue::Tuple(Some(values)) => { for v in values.iter() { v.memcomparable_encode(b)?; + b.push(0u8); } } value => { @@ -1573,6 +1574,7 @@ impl fmt::Debug for DataValue { mod test { use crate::errors::DatabaseError; use crate::types::value::DataValue; + use std::sync::Arc; #[test] fn test_mem_comparable_int() -> Result<(), DatabaseError> { @@ -1661,4 +1663,37 @@ mod test { Ok(()) } + + #[test] + fn test_mem_comparable_tuple() -> Result<(), DatabaseError> { + let mut key_tuple_1 = Vec::new(); + let mut key_tuple_2 = Vec::new(); + let mut key_tuple_3 = Vec::new(); + + DataValue::Tuple(Some(vec![ + Arc::new(DataValue::Int8(None)), + Arc::new(DataValue::Int8(Some(0))), + Arc::new(DataValue::Int8(Some(1))), + ])) + .memcomparable_encode(&mut key_tuple_1)?; + DataValue::Tuple(Some(vec![ + Arc::new(DataValue::Int8(Some(0))), + Arc::new(DataValue::Int8(Some(0))), + Arc::new(DataValue::Int8(Some(1))), + ])) + .memcomparable_encode(&mut key_tuple_2)?; + DataValue::Tuple(Some(vec![ + Arc::new(DataValue::Int8(Some(0))), + Arc::new(DataValue::Int8(Some(0))), + Arc::new(DataValue::Int8(Some(2))), + ])) + .memcomparable_encode(&mut key_tuple_3)?; + + println!("{:?} < {:?}", key_tuple_1, key_tuple_2); + println!("{:?} < {:?}", key_tuple_2, key_tuple_3); + assert!(key_tuple_1 < key_tuple_2); + assert!(key_tuple_2 < key_tuple_3); + + Ok(()) + } }