diff --git a/src/serdes/mod.rs b/src/serdes/mod.rs index 6eb7450c..c7fb649d 100644 --- a/src/serdes/mod.rs +++ b/src/serdes/mod.rs @@ -55,6 +55,14 @@ impl ReferenceTables { ReferenceTables { tables: vec![] } } + pub fn is_empty(&self) -> bool { + self.tables.is_empty() + } + + pub fn len(&self) -> usize { + self.tables.len() + } + pub fn get(&self, i: usize) -> &TableName { &self.tables[i] } diff --git a/src/storage/mod.rs b/src/storage/mod.rs index e6e43218..788cb50c 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -312,6 +312,7 @@ pub trait Transaction: Sized { let (key, value) = TableCodec::encode_column(column, &mut reference_tables)?; self.set(key, value)?; } + debug_assert_eq!(reference_tables.len(), 1); table_cache.put(table_name.to_string(), table_catalog); Ok(table_name) diff --git a/src/storage/table_codec.rs b/src/storage/table_codec.rs index 29780e59..69b9b3f5 100644 --- a/src/storage/table_codec.rs +++ b/src/storage/table_codec.rs @@ -385,27 +385,22 @@ impl TableCodec { #[cfg(test)] mod tests { use crate::catalog::{ColumnCatalog, ColumnDesc, ColumnRelation, TableCatalog, TableMeta}; - use crate::db::test::build_table; use crate::errors::DatabaseError; use crate::serdes::ReferenceTables; - use crate::storage::rocksdb::{RocksStorage, RocksTransaction}; + use crate::storage::rocksdb::RocksTransaction; use crate::storage::table_codec::TableCodec; - use crate::storage::Storage; use crate::types::index::{Index, IndexMeta, IndexType}; use crate::types::tuple::Tuple; use crate::types::value::DataValue; use crate::types::LogicalType; - use crate::utils::lru::ShardingLruCache; use bytes::Bytes; use itertools::Itertools; use rust_decimal::Decimal; use std::collections::BTreeSet; - use std::hash::RandomState; use std::io::Cursor; use std::ops::Bound; use std::slice; use std::sync::Arc; - use tempfile::TempDir; fn build_table_codec() -> TableCatalog { let columns = vec![ @@ -506,13 +501,6 @@ mod tests { #[test] fn test_table_codec_column() -> Result<(), DatabaseError> { - let temp_dir = TempDir::new().expect("unable to create temporary working directory"); - let storage = RocksStorage::new(temp_dir.path())?; - let mut transaction = storage.transaction()?; - let table_cache = Arc::new(ShardingLruCache::new(4, 1, RandomState::new())?); - - build_table(&table_cache, &mut transaction)?; - let mut col: ColumnCatalog = ColumnCatalog::new( "c2".to_string(), false,