Skip to content

Commit

Permalink
chore: codefmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Oct 7, 2024
1 parent 5e00745 commit 8ba1b78
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
8 changes: 8 additions & 0 deletions src/serdes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
1 change: 1 addition & 0 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 1 addition & 13 deletions src/storage/table_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 13 additions & 9 deletions tests/macros-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand All @@ -33,7 +33,7 @@ mod test {
false,
false,
None,
),
).unwrap(),
)),
]);
let values = vec![
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 8ba1b78

Please sign in to comment.