Skip to content

Commit

Permalink
fix: resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Sep 23, 2023
1 parent 602ef4c commit c26cb66
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 84 deletions.
4 changes: 2 additions & 2 deletions src/catalog/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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(())
}
}
4 changes: 2 additions & 2 deletions src/execution/executor/show/show_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use std::sync::Arc;
use crate::types::value::{DataValue, ValueRef};

pub struct ShowTables {
op: ShowTablesOperator,
_op: ShowTablesOperator,
}

impl From<ShowTablesOperator> for ShowTables {
fn from(op: ShowTablesOperator) -> Self {
ShowTables {
op
_op: op
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/expression/value_compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
8 changes: 3 additions & 5 deletions src/storage/kip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KernelError> for StorageError {
Expand Down
18 changes: 10 additions & 8 deletions src/storage/table_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
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
Expand Down
57 changes: 0 additions & 57 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
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:
Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/types/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit c26cb66

Please sign in to comment.