From 8ba1b7856511aa4446a9fea34036412a58ebaf2e Mon Sep 17 00:00:00 2001 From: Kould Date: Tue, 8 Oct 2024 02:40:08 +0800 Subject: [PATCH] chore: codefmt --- src/macros/mod.rs | 2 +- src/serdes/mod.rs | 8 ++++++++ src/storage/mod.rs | 1 + src/storage/table_codec.rs | 14 +------------- tests/macros-test/src/main.rs | 22 +++++++++++++--------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/macros/mod.rs b/src/macros/mod.rs index 2e35fe7f..39e1ff64 100644 --- a/src/macros/mod.rs +++ b/src/macros/mod.rs @@ -154,7 +154,7 @@ macro_rules! table_function { let mut columns = Vec::new(); $({ - columns.push(::fnck_sql::catalog::column::ColumnCatalog::new(stringify!($output_name).to_lowercase(), true, ::fnck_sql::catalog::column::ColumnDesc::new($output_ty, false, false, None))); + columns.push(::fnck_sql::catalog::column::ColumnCatalog::new(stringify!($output_name).to_lowercase(), true, ::fnck_sql::catalog::column::ColumnDesc::new($output_ty, false, false, None).unwrap())); })* ::fnck_sql::catalog::table::TableCatalog::new(Arc::new(stringify!($function_name).to_lowercase()), columns).unwrap() }; 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, diff --git a/tests/macros-test/src/main.rs b/tests/macros-test/src/main.rs index c35e0e6b..216e7129 100644 --- a/tests/macros-test/src/main.rs +++ b/tests/macros-test/src/main.rs @@ -2,7 +2,7 @@ fn main() {} #[cfg(test)] mod test { - use fnck_sql::catalog::column::{ColumnCatalog, ColumnDesc}; + use fnck_sql::catalog::column::{ColumnCatalog, ColumnDesc, ColumnRelation}; use fnck_sql::errors::DatabaseError; use fnck_sql::expression::function::scala::ScalarFunctionImpl; use fnck_sql::expression::function::table::TableFunctionImpl; @@ -23,7 +23,7 @@ mod test { Arc::new(ColumnCatalog::new( "c1".to_string(), false, - ColumnDesc::new(LogicalType::Integer, true, false, None), + ColumnDesc::new(LogicalType::Integer, true, false, None).unwrap(), )), Arc::new(ColumnCatalog::new( "c2".to_string(), @@ -33,7 +33,7 @@ mod test { false, false, None, - ), + ).unwrap(), )), ]); let values = vec![ @@ -174,17 +174,21 @@ mod test { let mut c1 = ColumnCatalog::new( "c1".to_string(), true, - ColumnDesc::new(LogicalType::Integer, false, false, None), + ColumnDesc::new(LogicalType::Integer, false, false, None)?, ); - c1.set_id(0); - c1.set_table_name(table_name.clone()); + c1.summary.relation = ColumnRelation::Table { + column_id: 0, + table_name: table_name.clone(), + }; let mut c2 = ColumnCatalog::new( "c2".to_string(), true, - ColumnDesc::new(LogicalType::Integer, false, false, None), + ColumnDesc::new(LogicalType::Integer, false, false, None)?, ); - c2.set_id(1); - c2.set_table_name(table_name.clone()); + c2.summary.relation = ColumnRelation::Table { + column_id: 1, + table_name: table_name.clone(), + }; assert_eq!( function.output_schema(),