From c26cb665fa50e7fffb9cdf919c1ae983f131f64a Mon Sep 17 00:00:00 2001 From: Kould <2435992353@qq.com> Date: Sun, 24 Sep 2023 02:17:27 +0800 Subject: [PATCH] fix: resolve merge conflicts --- src/catalog/column.rs | 4 +- src/db.rs | 8 ++-- src/execution/executor/show/show_table.rs | 4 +- src/expression/value_compute.rs | 2 +- src/storage/kip.rs | 8 ++-- src/storage/mod.rs | 4 -- src/storage/table_codec.rs | 18 +++---- src/types/mod.rs | 57 ----------------------- src/types/tuple.rs | 2 +- 9 files changed, 23 insertions(+), 84 deletions(-) diff --git a/src/catalog/column.rs b/src/catalog/column.rs index 38691c69..4dcea4be 100644 --- a/src/catalog/column.rs +++ b/src/catalog/column.rs @@ -29,11 +29,11 @@ impl ColumnCatalog { pub(crate) fn new_dummy(column_name: String)-> ColumnCatalog { ColumnCatalog { - id: 0, + id: Some(0), name: column_name, table_name: None, nullable: false, - desc: ColumnDesc::new(LogicalType::Varchar(None), false), + desc: ColumnDesc::new(LogicalType::Varchar(None), false, false), } } diff --git a/src/db.rs b/src/db.rs index 6c94eabf..d49e528e 100644 --- a/src/db.rs +++ b/src/db.rs @@ -201,6 +201,10 @@ mod test { let _ = kipsql.run("insert into t1 (a, b, k) values (-99, 1, 1), (-1, 2, 2), (5, 3, 2)").await?; let _ = kipsql.run("insert into t2 (d, c, e) values (2, 1, '2021-05-20 21:00:00'), (3, 4, '2023-09-10 00:00:00')").await?; + println!("show tables:"); + let tuples_show_tables = kipsql.run("show tables").await?; + println!("{}", create_table(&tuples_show_tables)); + println!("full t1:"); let tuples_full_fields_t1 = kipsql.run("select * from t1").await?; println!("{}", create_table(&tuples_full_fields_t1)); @@ -317,10 +321,6 @@ mod test { println!("drop t1:"); let _ = kipsql.run("drop table t1").await?; - println!("show tables:"); - let tuples_show_tables = kipsql.run("show tables").await?; - println!("{}", create_table(&tuples_show_tables)); - Ok(()) } } diff --git a/src/execution/executor/show/show_table.rs b/src/execution/executor/show/show_table.rs index cf424a01..4ca19c01 100644 --- a/src/execution/executor/show/show_table.rs +++ b/src/execution/executor/show/show_table.rs @@ -10,13 +10,13 @@ use std::sync::Arc; use crate::types::value::{DataValue, ValueRef}; pub struct ShowTables { - op: ShowTablesOperator, + _op: ShowTablesOperator, } impl From for ShowTables { fn from(op: ShowTablesOperator) -> Self { ShowTables { - op + _op: op } } } diff --git a/src/expression/value_compute.rs b/src/expression/value_compute.rs index 3c0b2b1d..3a2f6dfc 100644 --- a/src/expression/value_compute.rs +++ b/src/expression/value_compute.rs @@ -1184,7 +1184,7 @@ mod test { } #[test] - fn test_binary_op_Utf8_compare()->Result<(),TypeError>{ + fn test_binary_op_utf8_compare()->Result<(),TypeError>{ assert_eq!(binary_op(&DataValue::Utf8(Some("a".to_string())), &DataValue::Utf8(Some("b".to_string())), &BinaryOperator::Gt)?, DataValue::Boolean(Some(false))); assert_eq!(binary_op(&DataValue::Utf8(Some("a".to_string())), &DataValue::Utf8(Some("b".to_string())), &BinaryOperator::Lt)?, DataValue::Boolean(Some(true))); assert_eq!(binary_op(&DataValue::Utf8(Some("a".to_string())), &DataValue::Utf8(Some("a".to_string())), &BinaryOperator::GtEq)?, DataValue::Boolean(Some(true))); diff --git a/src/storage/kip.rs b/src/storage/kip.rs index 350d4a16..0facf1f6 100644 --- a/src/storage/kip.rs +++ b/src/storage/kip.rs @@ -9,6 +9,7 @@ use kip_db::kernel::lsm::mvcc::TransactionIter; use kip_db::kernel::lsm::{mvcc, storage}; use kip_db::kernel::lsm::iterator::Iter as KipDBIter; use kip_db::kernel::lsm::storage::Config; +use kip_db::kernel::Storage as KipDBStorage; use kip_db::kernel::utils::lru_cache::ShardingLruCache; use crate::catalog::{ColumnCatalog, TableCatalog, TableName}; use crate::expression::simplify::ConstantBinary; @@ -133,8 +134,7 @@ impl Storage for KipStorage { } } - let (k, v)= TableCodec::encode_root_table(table_name.as_str(), columns.len()) - .ok_or(StorageError::Serialization)?; + let (k, v)= TableCodec::encode_root_table(table_name.as_str(), columns.len())?; self.inner.set(k, v).await?; tx.commit().await?; @@ -165,9 +165,7 @@ impl Storage for KipStorage { for col_key in col_keys { tx.remove(&col_key)? } - let (k, _) = TableCodec::encode_root_table(name.as_str(),0) - .ok_or(StorageError::Serialization)?; - tx.remove(&k)?; + tx.remove(&TableCodec::encode_root_table_key(name.as_str()))?; tx.commit().await?; let _ = self.cache.remove(name); diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 7f3553e9..20b05daf 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -145,10 +145,6 @@ pub enum StorageError { #[error("The column has been declared unique and the value already exists")] DuplicateUniqueValue, - - #[error("Serialization error")] - Serialization, - } impl From for StorageError { diff --git a/src/storage/table_codec.rs b/src/storage/table_codec.rs index f53acc0e..58a5a9c5 100644 --- a/src/storage/table_codec.rs +++ b/src/storage/table_codec.rs @@ -188,17 +188,19 @@ impl TableCodec { /// Key: RootCatalog_0_TableName /// Value: ColumnCount - pub fn encode_root_table(table_name: &str,column_count:usize) -> Option<(Bytes, Bytes)> { - let key = format!( + pub fn encode_root_table(table_name: &str,column_count:usize) -> Result<(Bytes, Bytes), TypeError> { + let key = Self::encode_root_table_key(table_name); + let bytes = bincode::serialize(&column_count)?; + + Ok((Bytes::from(key), Bytes::from(bytes))) + } + + pub fn encode_root_table_key(table_name: &str) -> Vec { + format!( "RootCatalog_{}_{}", BOUND_MIN_TAG, table_name, - ); - - bincode::serialize(&column_count).ok() - .map(|bytes| { - (Bytes::from(key.into_bytes()), Bytes::from(bytes)) - }) + ).into_bytes() } // TODO: value is reserved for saving meta-information diff --git a/src/types/mod.rs b/src/types/mod.rs index f43da94c..b0443b5e 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -3,39 +3,11 @@ pub mod value; pub mod tuple; pub mod index; -use std::sync::atomic::AtomicU32; -use std::sync::atomic::Ordering::{Acquire, Release}; use serde::{Deserialize, Serialize}; - -use integer_encoding::FixedInt; use strum_macros::AsRefStr; use crate::types::errors::TypeError; -static ID_BUF: AtomicU32 = AtomicU32::new(0); - -pub(crate) struct IdGenerator { } - -impl IdGenerator { - pub(crate) fn encode_to_raw() -> Vec { - ID_BUF - .load(Acquire) - .encode_fixed_vec() - } - - pub(crate) fn from_raw(buf: &[u8]) { - Self::init(u32::decode_fixed(buf)) - } - - pub(crate) fn init(init_value: u32) { - ID_BUF.store(init_value, Release) - } - - pub(crate) fn build() -> u32 { - ID_BUF.fetch_add(1, Release) - } -} - pub type ColumnId = u32; /// Sqlrs type conversion: @@ -309,32 +281,3 @@ impl std::fmt::Display for LogicalType { write!(f, "{}", self.as_ref()) } } - -#[cfg(test)] -mod test { - use std::sync::atomic::Ordering::Release; - - use crate::types::{IdGenerator, ID_BUF}; - - /// Tips: 由于IdGenerator为static全局性质生成的id,因此需要单独测试避免其他测试方法干扰 - #[test] - #[ignore] - fn test_id_generator() { - assert_eq!(IdGenerator::build(), 0); - assert_eq!(IdGenerator::build(), 1); - - let buf = IdGenerator::encode_to_raw(); - test_id_generator_reset(); - - assert_eq!(IdGenerator::build(), 0); - - IdGenerator::from_raw(&buf); - - assert_eq!(IdGenerator::build(), 2); - assert_eq!(IdGenerator::build(), 3); - } - - fn test_id_generator_reset() { - ID_BUF.store(0, Release) - } -} diff --git a/src/types/tuple.rs b/src/types/tuple.rs index f1628e40..dc6db97c 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -135,7 +135,7 @@ mod tests { Arc::new(ColumnCatalog::new( "c3".to_string(), false, - ColumnDesc::new(LogicalType::Varchar(Some(2)), false) + ColumnDesc::new(LogicalType::Varchar(Some(2)), false, false) )), Arc::new(ColumnCatalog::new( "c4".to_string(),