From a4cdca49add85c90483e731f8ab12e41e16537aa Mon Sep 17 00:00:00 2001 From: Kould <2435992353@qq.com> Date: Mon, 2 Sep 2024 01:57:33 +0800 Subject: [PATCH] Fix/integer cast (#218) * fix: add `natual_join.slt` & fix `Integer` cast & `Wildcard` resulting in early exit * chore: `assert!` -> `debug_assert!` --- src/binder/copy.rs | 2 +- src/binder/create_table.rs | 14 +- src/binder/mod.rs | 16 +- src/binder/select.rs | 9 +- src/catalog/table.rs | 16 +- src/db.rs | 58 ++++++-- src/execution/dml/copy_from_file.rs | 2 +- src/execution/dql/aggregate/hash_agg.rs | 6 +- src/execution/dql/aggregate/sum.rs | 2 +- src/execution/dql/join/hash_join.rs | 54 +++---- src/execution/dql/join/nested_loop_join.rs | 10 +- src/execution/dql/sort.rs | 82 +++++------ src/expression/range_detacher.rs | 106 ++++++------- src/optimizer/core/cm_sketch.rs | 10 +- src/optimizer/core/histogram.rs | 48 +++--- src/optimizer/core/memo.rs | 12 +- src/optimizer/core/statistics_meta.rs | 4 +- src/optimizer/heuristic/graph.rs | 48 +++--- src/optimizer/heuristic/matcher.rs | 6 +- .../rule/normalization/column_pruning.rs | 12 +- .../rule/normalization/combine_operators.rs | 6 +- .../rule/normalization/pushdown_limit.rs | 4 +- .../rule/normalization/pushdown_predicates.rs | 2 +- .../rule/normalization/simplification.rs | 56 +++---- src/storage/mod.rs | 8 +- src/storage/rocksdb.rs | 14 +- src/storage/table_codec.rs | 58 ++++---- src/types/evaluator/mod.rs | 136 ++++++++--------- src/types/tuple.rs | 12 +- src/types/value.rs | 68 +++++++-- src/utils/bit_vector.rs | 8 +- src/utils/lru.rs | 36 ++--- tests/slt/crdb/natural_join.slt | 139 ++++++++++++++++++ 33 files changed, 643 insertions(+), 421 deletions(-) create mode 100644 tests/slt/crdb/natural_join.slt diff --git a/src/binder/copy.rs b/src/binder/copy.rs index f9a973bd..4810e8f8 100644 --- a/src/binder/copy.rs +++ b/src/binder/copy.rs @@ -112,7 +112,7 @@ impl FileFormat { for opt in options { match opt { CopyOption::Format(fmt) => { - assert_eq!(fmt.value.to_lowercase(), "csv", "only support CSV format") + debug_assert_eq!(fmt.value.to_lowercase(), "csv", "only support CSV format") } CopyOption::Delimiter(c) => delimiter = *c, CopyOption::Header(b) => header = *b, diff --git a/src/binder/create_table.rs b/src/binder/create_table.rs index d3038670..903dd88c 100644 --- a/src/binder/create_table.rs +++ b/src/binder/create_table.rs @@ -177,16 +177,16 @@ mod tests { match plan1.operator { Operator::CreateTable(op) => { - assert_eq!(op.table_name, Arc::new("t1".to_string())); - assert_eq!(op.columns[0].name(), "id"); - assert_eq!(op.columns[0].nullable, false); - assert_eq!( + debug_assert_eq!(op.table_name, Arc::new("t1".to_string())); + debug_assert_eq!(op.columns[0].name(), "id"); + debug_assert_eq!(op.columns[0].nullable, false); + debug_assert_eq!( op.columns[0].desc, ColumnDesc::new(LogicalType::Integer, true, false, None) ); - assert_eq!(op.columns[1].name(), "name"); - assert_eq!(op.columns[1].nullable, true); - assert_eq!( + debug_assert_eq!(op.columns[1].name(), "name"); + debug_assert_eq!(op.columns[1].nullable, true); + debug_assert_eq!( op.columns[1].desc, ColumnDesc::new( LogicalType::Varchar(Some(10), CharLengthUnits::Characters), diff --git a/src/binder/mod.rs b/src/binder/mod.rs index 9461f1b3..9a5535c2 100644 --- a/src/binder/mod.rs +++ b/src/binder/mod.rs @@ -467,13 +467,13 @@ pub mod test { #[test] pub fn test_valid_identifier() { - assert!(is_valid_identifier("valid_table")); - assert!(is_valid_identifier("valid_column")); - assert!(is_valid_identifier("_valid_column")); - assert!(is_valid_identifier("valid_column_1")); - - assert!(!is_valid_identifier("invalid_name&")); - assert!(!is_valid_identifier("1_invalid_name")); - assert!(!is_valid_identifier("____")); + debug_assert!(is_valid_identifier("valid_table")); + debug_assert!(is_valid_identifier("valid_column")); + debug_assert!(is_valid_identifier("_valid_column")); + debug_assert!(is_valid_identifier("valid_column_1")); + + debug_assert!(!is_valid_identifier("invalid_name&")); + debug_assert!(!is_valid_identifier("1_invalid_name")); + debug_assert!(!is_valid_identifier("____")); } } diff --git a/src/binder/select.rs b/src/binder/select.rs index 81942c6a..896a403a 100644 --- a/src/binder/select.rs +++ b/src/binder/select.rs @@ -411,8 +411,8 @@ impl<'a: 'b, 'b, T: Transaction> Binder<'a, 'b, T> { ) -> Result, DatabaseError> { let mut select_items = vec![]; - for item in items.iter().enumerate() { - match item.1 { + for item in items.iter() { + match item { SelectItem::UnnamedExpr(expr) => select_items.push(self.bind_expr(expr)?), SelectItem::ExprWithAlias { expr, alias } => { let expr = self.bind_expr(expr)?; @@ -428,7 +428,10 @@ impl<'a: 'b, 'b, T: Transaction> Binder<'a, 'b, T> { } SelectItem::Wildcard(_) => { if let Operator::Project(op) = &plan.operator { - return Ok(op.exprs.clone()); + for expr in op.exprs.iter() { + select_items.push(expr.clone()); + } + continue; } let mut join_used = HashSet::with_capacity(self.context.using.len()); diff --git a/src/catalog/table.rs b/src/catalog/table.rs index bfa30bd6..b4d5ba30 100644 --- a/src/catalog/table.rs +++ b/src/catalog/table.rs @@ -203,9 +203,9 @@ mod tests { let col_catalogs = vec![col0, col1]; let table_catalog = TableCatalog::new(Arc::new("test".to_string()), col_catalogs).unwrap(); - assert_eq!(table_catalog.contains_column(&"a".to_string()), true); - assert_eq!(table_catalog.contains_column(&"b".to_string()), true); - assert_eq!(table_catalog.contains_column(&"c".to_string()), false); + debug_assert_eq!(table_catalog.contains_column(&"a".to_string()), true); + debug_assert_eq!(table_catalog.contains_column(&"b".to_string()), true); + debug_assert_eq!(table_catalog.contains_column(&"c".to_string()), false); let col_a_id = table_catalog .get_column_id_by_name(&"a".to_string()) @@ -213,14 +213,14 @@ mod tests { let col_b_id = table_catalog .get_column_id_by_name(&"b".to_string()) .unwrap(); - assert!(col_a_id < col_b_id); + debug_assert!(col_a_id < col_b_id); let column_catalog = table_catalog.get_column_by_id(&col_a_id).unwrap(); - assert_eq!(column_catalog.name(), "a"); - assert_eq!(*column_catalog.datatype(), LogicalType::Integer,); + debug_assert_eq!(column_catalog.name(), "a"); + debug_assert_eq!(*column_catalog.datatype(), LogicalType::Integer,); let column_catalog = table_catalog.get_column_by_id(&col_b_id).unwrap(); - assert_eq!(column_catalog.name(), "b"); - assert_eq!(*column_catalog.datatype(), LogicalType::Boolean,); + debug_assert_eq!(column_catalog.name(), "b"); + debug_assert_eq!(*column_catalog.datatype(), LogicalType::Boolean,); } } diff --git a/src/db.rs b/src/db.rs index 7de6990a..9b916b1d 100644 --- a/src/db.rs +++ b/src/db.rs @@ -306,9 +306,10 @@ mod test { use crate::catalog::{ColumnCatalog, ColumnDesc}; use crate::db::{DataBaseBuilder, DatabaseError}; use crate::storage::{Storage, TableCache, Transaction}; - use crate::types::tuple::create_table; + use crate::types::tuple::{create_table, Tuple}; use crate::types::value::DataValue; use crate::types::LogicalType; + use chrono::{Datelike, Local}; use std::sync::Arc; use tempfile::TempDir; @@ -356,6 +357,23 @@ mod test { let (schema, tuples) = fnck_sql.run("select current_date()")?; println!("{}", create_table(&schema, &tuples)); + debug_assert_eq!( + schema, + Arc::new(vec![Arc::new(ColumnCatalog::new( + "current_date()".to_string(), + true, + ColumnDesc::new(LogicalType::Date, false, false, None) + ))]) + ); + debug_assert_eq!( + tuples, + vec![Tuple { + id: None, + values: vec![Arc::new(DataValue::Date32(Some( + Local::now().num_days_from_ce() + )))], + }] + ); Ok(()) } @@ -369,6 +387,28 @@ mod test { )?; println!("{}", create_table(&schema, &tuples)); + let mut column = ColumnCatalog::new( + "number".to_string(), + true, + ColumnDesc::new(LogicalType::Integer, false, false, None), + ); + column.set_table_name(Arc::new("a".to_string())); + column.set_id(0); + + debug_assert_eq!(schema, Arc::new(vec![Arc::new(column)])); + debug_assert_eq!( + tuples, + vec![ + Tuple { + id: None, + values: vec![Arc::new(DataValue::Int32(Some(3)))], + }, + Tuple { + id: None, + values: vec![Arc::new(DataValue::Int32(Some(4)))], + }, + ] + ); Ok(()) } @@ -391,17 +431,17 @@ mod test { let (_, tuples_1) = tx_1.run("select * from t1")?; let (_, tuples_2) = tx_2.run("select * from t1")?; - assert_eq!(tuples_1.len(), 2); - assert_eq!(tuples_2.len(), 2); + debug_assert_eq!(tuples_1.len(), 2); + debug_assert_eq!(tuples_2.len(), 2); - assert_eq!( + debug_assert_eq!( tuples_1[0].values, vec![ Arc::new(DataValue::Int32(Some(0))), Arc::new(DataValue::Int32(Some(0))) ] ); - assert_eq!( + debug_assert_eq!( tuples_1[1].values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -409,14 +449,14 @@ mod test { ] ); - assert_eq!( + debug_assert_eq!( tuples_2[0].values, vec![ Arc::new(DataValue::Int32(Some(0))), Arc::new(DataValue::Int32(Some(0))) ] ); - assert_eq!( + debug_assert_eq!( tuples_2[1].values, vec![ Arc::new(DataValue::Int32(Some(3))), @@ -426,11 +466,11 @@ mod test { tx_1.commit()?; - assert!(tx_2.commit().is_err()); + debug_assert!(tx_2.commit().is_err()); let mut tx_3 = fnck_sql.new_transaction()?; let res = tx_3.run("create table t2 (a int primary key, b int)"); - assert!(res.is_err()); + debug_assert!(res.is_err()); Ok(()) } diff --git a/src/execution/dml/copy_from_file.rs b/src/execution/dml/copy_from_file.rs index 2b642663..0c5b5949 100644 --- a/src/execution/dml/copy_from_file.rs +++ b/src/execution/dml/copy_from_file.rs @@ -196,7 +196,7 @@ mod tests { CoroutineState::Complete(()) => unreachable!(), } .unwrap(); - assert_eq!( + debug_assert_eq!( tuple, TupleBuilder::build_result(format!("import {} rows", 2)) ); diff --git a/src/execution/dql/aggregate/hash_agg.rs b/src/execution/dql/aggregate/hash_agg.rs index d31572f5..f3810b92 100644 --- a/src/execution/dql/aggregate/hash_agg.rs +++ b/src/execution/dql/aggregate/hash_agg.rs @@ -252,12 +252,12 @@ mod test { ) ); - assert_eq!(tuples.len(), 2); + debug_assert_eq!(tuples.len(), 2); let vec_values = tuples.into_iter().map(|tuple| tuple.values).collect_vec(); - assert!(vec_values.contains(&build_integers(vec![Some(3), Some(0)]))); - assert!(vec_values.contains(&build_integers(vec![Some(5), Some(1)]))); + debug_assert!(vec_values.contains(&build_integers(vec![Some(3), Some(0)]))); + debug_assert!(vec_values.contains(&build_integers(vec![Some(5), Some(1)]))); Ok(()) } diff --git a/src/execution/dql/aggregate/sum.rs b/src/execution/dql/aggregate/sum.rs index ae67a556..3537ccf4 100644 --- a/src/execution/dql/aggregate/sum.rs +++ b/src/execution/dql/aggregate/sum.rs @@ -15,7 +15,7 @@ pub struct SumAccumulator { impl SumAccumulator { pub fn new(ty: &LogicalType) -> Result { - assert!(ty.is_numeric()); + debug_assert!(ty.is_numeric()); Ok(Self { result: DataValue::none(ty), diff --git a/src/execution/dql/join/hash_join.rs b/src/execution/dql/join/hash_join.rs index c19f014e..be8d4cd1 100644 --- a/src/execution/dql/join/hash_join.rs +++ b/src/execution/dql/join/hash_join.rs @@ -137,8 +137,8 @@ impl HashJoinStatus { if on_left_keys.is_empty() || on_right_keys.is_empty() { todo!("`NestLoopJoin` should be used when there is no equivalent condition") } - assert!(!on_left_keys.is_empty()); - assert!(!on_right_keys.is_empty()); + debug_assert!(!on_left_keys.is_empty()); + debug_assert!(!on_right_keys.is_empty()); let fn_process = |schema: &mut Vec, force_nullable| { for column in schema.iter_mut() { @@ -543,17 +543,17 @@ mod test { HashJoin::from((op, left, right)).execute((&table_cache, &meta_cache), &transaction); let tuples = try_collect(executor)?; - assert_eq!(tuples.len(), 3); + debug_assert_eq!(tuples.len(), 3); - assert_eq!( + debug_assert_eq!( tuples[0].values, build_integers(vec![Some(0), Some(2), Some(4), Some(0), Some(2), Some(4)]) ); - assert_eq!( + debug_assert_eq!( tuples[1].values, build_integers(vec![Some(1), Some(3), Some(5), Some(1), Some(3), Some(5)]) ); - assert_eq!( + debug_assert_eq!( tuples[2].values, build_integers(vec![Some(1), Some(3), Some(5), Some(1), Some(1), Some(1)]) ); @@ -582,21 +582,21 @@ mod test { let executor = HashJoin::from((op.clone(), left.clone(), right.clone())); let tuples = try_collect(executor.execute((&table_cache, &meta_cache), &transaction))?; - assert_eq!(tuples.len(), 4); + debug_assert_eq!(tuples.len(), 4); - assert_eq!( + debug_assert_eq!( tuples[0].values, build_integers(vec![Some(0), Some(2), Some(4), Some(0), Some(2), Some(4)]) ); - assert_eq!( + debug_assert_eq!( tuples[1].values, build_integers(vec![Some(1), Some(3), Some(5), Some(1), Some(3), Some(5)]) ); - assert_eq!( + debug_assert_eq!( tuples[2].values, build_integers(vec![Some(1), Some(3), Some(5), Some(1), Some(1), Some(1)]) ); - assert_eq!( + debug_assert_eq!( tuples[3].values, build_integers(vec![Some(3), Some(5), Some(7), None, None, None]) ); @@ -608,18 +608,18 @@ mod test { let mut tuples = try_collect(executor.execute((&table_cache, &meta_cache), &transaction))?; - assert_eq!(tuples.len(), 2); + debug_assert_eq!(tuples.len(), 2); tuples.sort_by_key(|tuple| { let mut bytes = Vec::new(); tuple.values[0].memcomparable_encode(&mut bytes).unwrap(); bytes }); - assert_eq!( + debug_assert_eq!( tuples[0].values, build_integers(vec![Some(0), Some(2), Some(4)]) ); - assert_eq!( + debug_assert_eq!( tuples[1].values, build_integers(vec![Some(1), Some(3), Some(5)]) ); @@ -630,8 +630,8 @@ mod test { executor.ty = JoinType::LeftAnti; let tuples = try_collect(executor.execute((&table_cache, &meta_cache), &transaction))?; - assert_eq!(tuples.len(), 1); - assert_eq!( + debug_assert_eq!(tuples.len(), 1); + debug_assert_eq!( tuples[0].values, build_integers(vec![Some(3), Some(5), Some(7)]) ); @@ -660,21 +660,21 @@ mod test { HashJoin::from((op, left, right)).execute((&table_cache, &meta_cache), &transaction); let tuples = try_collect(executor)?; - assert_eq!(tuples.len(), 4); + debug_assert_eq!(tuples.len(), 4); - assert_eq!( + debug_assert_eq!( tuples[0].values, build_integers(vec![Some(0), Some(2), Some(4), Some(0), Some(2), Some(4)]) ); - assert_eq!( + debug_assert_eq!( tuples[1].values, build_integers(vec![Some(1), Some(3), Some(5), Some(1), Some(3), Some(5)]) ); - assert_eq!( + debug_assert_eq!( tuples[2].values, build_integers(vec![None, None, None, Some(4), Some(6), Some(8)]) ); - assert_eq!( + debug_assert_eq!( tuples[3].values, build_integers(vec![Some(1), Some(3), Some(5), Some(1), Some(1), Some(1)]) ); @@ -702,25 +702,25 @@ mod test { HashJoin::from((op, left, right)).execute((&table_cache, &meta_cache), &transaction); let tuples = try_collect(executor)?; - assert_eq!(tuples.len(), 5); + debug_assert_eq!(tuples.len(), 5); - assert_eq!( + debug_assert_eq!( tuples[0].values, build_integers(vec![Some(0), Some(2), Some(4), Some(0), Some(2), Some(4)]) ); - assert_eq!( + debug_assert_eq!( tuples[1].values, build_integers(vec![Some(1), Some(3), Some(5), Some(1), Some(3), Some(5)]) ); - assert_eq!( + debug_assert_eq!( tuples[2].values, build_integers(vec![None, None, None, Some(4), Some(6), Some(8)]) ); - assert_eq!( + debug_assert_eq!( tuples[3].values, build_integers(vec![Some(1), Some(3), Some(5), Some(1), Some(1), Some(1)]) ); - assert_eq!( + debug_assert_eq!( tuples[4].values, build_integers(vec![Some(3), Some(5), Some(7), None, None, None]) ); diff --git a/src/execution/dql/join/nested_loop_join.rs b/src/execution/dql/join/nested_loop_join.rs index 07096d43..8ead58a4 100644 --- a/src/execution/dql/join/nested_loop_join.rs +++ b/src/execution/dql/join/nested_loop_join.rs @@ -478,7 +478,7 @@ mod test { } fn valid_result(expected: &mut HashSet>>, actual: &[Tuple]) { - assert_eq!(actual.len(), expected.len()); + debug_assert_eq!(actual.len(), expected.len()); for tuple in actual { let values = tuple @@ -492,10 +492,10 @@ mod test { } }) .collect_vec(); - assert!(expected.remove(&values)); + debug_assert!(expected.remove(&values)); } - assert!(expected.is_empty()); + debug_assert!(expected.is_empty()); } #[test] @@ -545,7 +545,7 @@ mod test { .execute((&table_cache, &meta_cache), &transaction); let tuples = try_collect(executor)?; - assert_eq!( + debug_assert_eq!( tuples[0].values, build_integers(vec![Some(0), Some(2), Some(4), None, None, None]) ); @@ -646,7 +646,7 @@ mod test { .execute((&table_cache, &meta_cache), &transaction); let tuples = try_collect(executor)?; - assert_eq!(tuples.len(), 16); + debug_assert_eq!(tuples.len(), 16); Ok(()) } diff --git a/src/execution/dql/sort.rs b/src/execution/dql/sort.rs index 7e766a3c..502d30d4 100644 --- a/src/execution/dql/sort.rs +++ b/src/execution/dql/sort.rs @@ -105,7 +105,7 @@ impl SortBy { let mut sort_keys = Vec::with_capacity(tuples.len()); for (i, tuple) in tuples.0.iter().enumerate() { - assert!(tuple.is_some()); + debug_assert!(tuple.is_some()); let mut full_key = Vec::new(); @@ -151,7 +151,7 @@ impl SortBy { for (x, SortField { expr, .. }) in sort_fields.iter().enumerate() { for tuple in tuples.0.iter() { - assert!(tuple.is_some()); + debug_assert!(tuple.is_some()); let (_, tuple) = tuple.as_ref().unwrap(); eval_values[x].push(expr.eval(tuple, schema)?); @@ -159,8 +159,8 @@ impl SortBy { } tuples.0.sort_by(|tuple_1, tuple_2| { - assert!(tuple_1.is_some()); - assert!(tuple_2.is_some()); + debug_assert!(tuple_1.is_some()); + debug_assert!(tuple_2.is_some()); let (i_1, _) = tuple_1.as_ref().unwrap(); let (i_2, _) = tuple_2.as_ref().unwrap(); @@ -289,7 +289,7 @@ mod test { (3, "abcd".as_bytes().to_vec()), ]; - assert_eq!(radix_sort(indices), vec![0, 3, 2, 1]) + debug_assert_eq!(radix_sort(indices), vec![0, 3, 2, 1]) } #[test] @@ -335,68 +335,68 @@ mod test { let fn_asc_and_nulls_last_eq = |mut iter: Box>| { if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(0)))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(0)))]) } else { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(1)))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(1)))]) } else { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(None))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(None))]) } else { unreachable!() } }; let fn_desc_and_nulls_last_eq = |mut iter: Box>| { if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(1)))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(1)))]) } else { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(0)))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(0)))]) } else { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(None))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(None))]) } else { unreachable!() } }; let fn_asc_and_nulls_first_eq = |mut iter: Box>| { if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(None))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(None))]) } else { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(0)))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(0)))]) } else { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(1)))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(1)))]) } else { unreachable!() } }; let fn_desc_and_nulls_first_eq = |mut iter: Box>| { if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(None))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(None))]) } else { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(1)))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(1)))]) } else { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(0)))]) + debug_assert_eq!(tuple.values, vec![Arc::new(DataValue::Int32(Some(0)))]) } else { unreachable!() } @@ -549,7 +549,7 @@ mod test { let fn_asc_1_and_nulls_first_1_and_asc_2_and_nulls_first_2_eq = |mut iter: Box>| { if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(None)), @@ -560,7 +560,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(None)), @@ -571,7 +571,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(0))), @@ -582,7 +582,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(0))), @@ -593,7 +593,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -604,7 +604,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -618,7 +618,7 @@ mod test { let fn_asc_1_and_nulls_last_1_and_asc_2_and_nulls_first_2_eq = |mut iter: Box>| { if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(0))), @@ -629,7 +629,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(0))), @@ -640,7 +640,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -651,7 +651,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -662,7 +662,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(None)), @@ -673,7 +673,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(None)), @@ -687,7 +687,7 @@ mod test { let fn_desc_1_and_nulls_first_1_and_asc_2_and_nulls_first_2_eq = |mut iter: Box>| { if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(None)), @@ -698,7 +698,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(None)), @@ -709,7 +709,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -720,7 +720,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -731,7 +731,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(0))), @@ -742,7 +742,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(0))), @@ -756,7 +756,7 @@ mod test { let fn_desc_1_and_nulls_last_1_and_asc_2_and_nulls_first_2_eq = |mut iter: Box>| { if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -767,7 +767,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), @@ -778,7 +778,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(0))), @@ -789,7 +789,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(0))), @@ -800,7 +800,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(None)), @@ -811,7 +811,7 @@ mod test { unreachable!() } if let Some(tuple) = iter.next() { - assert_eq!( + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(None)), diff --git a/src/expression/range_detacher.rs b/src/expression/range_detacher.rs index c9e964e3..f10bbe0d 100644 --- a/src/expression/range_detacher.rs +++ b/src/expression/range_detacher.rs @@ -819,21 +819,21 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = 1 => {}", range); - assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(Some(1))))) + debug_assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(Some(1))))) } { let plan = select_sql_run("select * from t1 where c1 != 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("c1 != 1 => {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } { let plan = select_sql_run("select * from t1 where c1 > 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 > 1 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(1)))), @@ -846,7 +846,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 >= 1 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Included(Arc::new(DataValue::Int32(Some(1)))), @@ -859,7 +859,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 < 1 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Unbounded, @@ -872,7 +872,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 <= 1 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Unbounded, @@ -885,7 +885,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 < 1 and c1 >= 0 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Included(Arc::new(DataValue::Int32(Some(0)))), @@ -898,7 +898,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 < 1 or c1 >= 0 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Unbounded, @@ -912,14 +912,14 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = 1 and c1 = 0 => c1: {}", range); - assert_eq!(range, Range::Dummy) + debug_assert_eq!(range, Range::Dummy) } { let plan = select_sql_run("select * from t1 where c1 = 1 or c1 = 0")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = 1 or c1 = 0 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Eq(Arc::new(DataValue::Int32(Some(0)))), @@ -932,14 +932,14 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = 1 and c1 = 1 => c1: {}", range); - assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(Some(1))))) + debug_assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(Some(1))))) } { let plan = select_sql_run("select * from t1 where c1 = 1 or c1 = 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = 1 or c1 = 1 => c1: {}", range); - assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(Some(1))))) + debug_assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(Some(1))))) } { @@ -947,21 +947,21 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 > 1 and c1 = 1 => c1: {}", range); - assert_eq!(range, Range::Dummy) + debug_assert_eq!(range, Range::Dummy) } { let plan = select_sql_run("select * from t1 where c1 >= 1 and c1 = 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 >= 1 and c1 = 1 => c1: {}", range); - assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(Some(1))))) + debug_assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(Some(1))))) } { let plan = select_sql_run("select * from t1 where c1 > 1 or c1 = 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 > 1 or c1 = 1 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Included(Arc::new(DataValue::Int32(Some(1)))), @@ -974,7 +974,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 >= 1 or c1 = 1 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Included(Arc::new(DataValue::Int32(Some(1)))), @@ -993,7 +993,7 @@ mod test { "(c1 > 0 and c1 < 3) and (c1 > 1 and c1 < 4) => c1: {}", range ); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(1)))), @@ -1011,7 +1011,7 @@ mod test { "(c1 > 0 and c1 < 3) or (c1 > 1 and c1 < 4) => c1: {}", range ); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(0)))), @@ -1030,7 +1030,7 @@ mod test { "((c1 > 0 and c1 < 3) and (c1 > 1 and c1 < 4)) and c1 = 0 => c1: {}", range ); - assert_eq!(range, Range::Dummy) + debug_assert_eq!(range, Range::Dummy) } { let plan = select_sql_run( @@ -1042,7 +1042,7 @@ mod test { "((c1 > 0 and c1 < 3) or (c1 > 1 and c1 < 4)) and c1 = 0 => c1: {}", range ); - assert_eq!(range, Range::Dummy) + debug_assert_eq!(range, Range::Dummy) } { let plan = select_sql_run( @@ -1054,7 +1054,7 @@ mod test { "((c1 > 0 and c1 < 3) and (c1 > 1 and c1 < 4)) or c1 = 0 => c1: {}", range ); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Eq(Arc::new(DataValue::Int32(Some(0)))), @@ -1075,7 +1075,7 @@ mod test { "((c1 > 0 and c1 < 3) or (c1 > 1 and c1 < 4)) or c1 = 0 => c1: {}", range ); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Included(Arc::new(DataValue::Int32(Some(0)))), @@ -1089,14 +1089,14 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("(((c1 > 0 and c1 < 3) and (c1 > 1 and c1 < 4)) and c1 = 0) and (c1 >= 0 and c1 <= 2) => c1: {}", range); - assert_eq!(range, Range::Dummy) + debug_assert_eq!(range, Range::Dummy) } { let plan = select_sql_run("select * from t1 where (((c1 > 0 and c1 < 3) and (c1 > 1 and c1 < 4)) and c1 = 0) or (c1 >= 0 and c1 <= 2)")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("(((c1 > 0 and c1 < 3) and (c1 > 1 and c1 < 4)) and c1 = 0) or (c1 >= 0 and c1 <= 2) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Included(Arc::new(DataValue::Int32(Some(0)))), @@ -1110,7 +1110,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("((c1 < 2 and c1 > 0) or (c1 < 6 and c1 > 4)) and ((c1 < 3 and c1 > 1) or (c1 < 7 and c1 > 5)) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Scope { @@ -1129,7 +1129,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("((c1 < 2 and c1 > 0) or (c1 < 6 and c1 > 4)) or ((c1 < 3 and c1 > 1) or (c1 < 7 and c1 > 5)) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Scope { @@ -1149,7 +1149,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("empty => c1: {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } // other column { @@ -1157,21 +1157,21 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("c2 = 1 => c1: {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } { let plan = select_sql_run("select * from t1 where c1 > 1 or c2 > 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("c1 > 1 or c2 > 1 => c1: {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } { let plan = select_sql_run("select * from t1 where c1 > c2 or c2 > 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("c1 > c2 or c2 > 1 => c1: {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } // case 1 { @@ -1184,7 +1184,7 @@ mod test { "c1 = 5 or (c1 > 5 and (c1 > 6 or c1 < 8) and c1 < 12) => c1: {}", range ); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Included(Arc::new(DataValue::Int32(Some(5)))), @@ -1203,7 +1203,7 @@ mod test { "((c2 >= -8 and -4 >= c1) or (c1 >= 0 and 5 > c2)) and ((c2 > 0 and c1 <= 1) or (c1 > -8 and c2 < -6)) => c1: {}", range ); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Scope { @@ -1230,14 +1230,14 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = null => c1: {}", range); - assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(None)))) + debug_assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(None)))) } { let plan = select_sql_run("select * from t1 where c1 = null or c1 = 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = null or c1 = 1 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Eq(Arc::new(DataValue::Int32(None))), @@ -1250,7 +1250,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = null or c1 < 5 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Unbounded, @@ -1263,7 +1263,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = null or (c1 > 1 and c1 < 5) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Eq(Arc::new(DataValue::Int32(None))), @@ -1279,14 +1279,14 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = null and c1 < 5 => c1: {}", range); - assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(None)))) + debug_assert_eq!(range, Range::Eq(Arc::new(DataValue::Int32(None)))) } { let plan = select_sql_run("select * from t1 where c1 = null and (c1 > 1 and c1 < 5)")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 = null and (c1 > 1 and c1 < 5) => c1: {}", range); - assert_eq!(range, Range::Dummy) + debug_assert_eq!(range, Range::Dummy) } // noteq { @@ -1294,35 +1294,35 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("c1 != null => c1: {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } { let plan = select_sql_run("select * from t1 where c1 = null or c1 != 1")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("c1 = null or c1 != 1 => c1: {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } { let plan = select_sql_run("select * from t1 where c1 != null or c1 < 5")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("c1 != null or c1 < 5 => c1: {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } { let plan = select_sql_run("select * from t1 where c1 != null or (c1 > 1 and c1 < 5)")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate); println!("c1 != null or (c1 > 1 and c1 < 5) => c1: {:#?}", range); - assert_eq!(range, None) + debug_assert_eq!(range, None) } { let plan = select_sql_run("select * from t1 where c1 != null and c1 < 5")?; let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 != null and c1 < 5 => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Unbounded, @@ -1335,7 +1335,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("c1 != null and (c1 > 1 and c1 < 5) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(1)))), @@ -1348,7 +1348,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("(c1 = null or (c1 < 2 and c1 > 0) or (c1 < 6 and c1 > 4)) or ((c1 < 3 and c1 > 1) or (c1 < 7 and c1 > 5)) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Eq(Arc::new(DataValue::Int32(None))), @@ -1368,7 +1368,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("((c1 < 2 and c1 > 0) or (c1 < 6 and c1 > 4)) or (c1 = null or (c1 < 3 and c1 > 1) or (c1 < 7 and c1 > 5)) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Eq(Arc::new(DataValue::Int32(None))), @@ -1388,7 +1388,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("(c1 = null or (c1 < 2 and c1 > 0) or (c1 < 6 and c1 > 4)) and ((c1 < 3 and c1 > 1) or (c1 < 7 and c1 > 5)) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Scope { @@ -1407,7 +1407,7 @@ mod test { let op = plan_filter(plan)?.unwrap(); let range = RangeDetacher::new("t1", &0).detach(&op.predicate).unwrap(); println!("((c1 < 2 and c1 > 0) or (c1 < 6 and c1 > 4)) and (c1 = null or (c1 < 3 and c1 > 1) or (c1 < 7 and c1 > 5)) => c1: {}", range); - assert_eq!( + debug_assert_eq!( range, Range::SortedRanges(vec![ Range::Scope { @@ -1446,7 +1446,7 @@ mod test { } .combining_eqs(&eqs_ranges); - assert_eq!( + debug_assert_eq!( range, Some(Range::Scope { min: Bound::Included(Arc::new(DataValue::Tuple(Some(vec![ @@ -1465,7 +1465,7 @@ mod test { } .combining_eqs(&eqs_ranges); - assert_eq!( + debug_assert_eq!( range, Some(Range::Scope { min: Bound::Unbounded, @@ -1484,7 +1484,7 @@ mod test { } .combining_eqs(&eqs_ranges); - assert_eq!( + debug_assert_eq!( range, Some(Range::SortedRanges(vec![ Range::Scope { @@ -1606,7 +1606,7 @@ mod test { } .combining_eqs(&eqs_ranges_2); - assert_eq!(range_1, None); - assert_eq!(range_2, None); + debug_assert_eq!(range_1, None); + debug_assert_eq!(range_2, None); } } diff --git a/src/optimizer/core/cm_sketch.rs b/src/optimizer/core/cm_sketch.rs index c232bbfe..bee9a75a 100644 --- a/src/optimizer/core/cm_sketch.rs +++ b/src/optimizer/core/cm_sketch.rs @@ -125,8 +125,8 @@ impl CountMinSketch { } fn mask(width: usize) -> usize { - assert!(width > 1); - assert_eq!(width & (width - 1), 0); + debug_assert!(width > 1); + debug_assert_eq!(width & (width - 1), 0); width - 1 } @@ -171,7 +171,7 @@ mod tests { for _ in 0..300 { cms.increment("key"); } - assert_eq!(cms.estimate("key"), 300); + debug_assert_eq!(cms.estimate("key"), 300); } #[test] @@ -181,7 +181,7 @@ mod tests { cms.increment(&(i % 100)); } for key in 0..100 { - assert!(cms.estimate(&key) >= 9_000); + debug_assert!(cms.estimate(&key) >= 9_000); } } @@ -191,7 +191,7 @@ mod tests { for _ in 0..300 { cms.increment(&DataValue::Int32(Some(300))); } - assert_eq!( + debug_assert_eq!( cms.collect_count(&vec![ Range::Eq(Arc::new(DataValue::Int32(Some(300)))), Range::Scope { diff --git a/src/optimizer/core/histogram.rs b/src/optimizer/core/histogram.rs index 1ae135af..04b79b0f 100644 --- a/src/optimizer/core/histogram.rs +++ b/src/optimizer/core/histogram.rs @@ -504,14 +504,14 @@ mod tests { builder.append(&Arc::new(DataValue::Null))?; builder.append(&Arc::new(DataValue::Int32(None)))?; - // assert!(matches!(builder.build(10), Err(DataBaseError::TooManyBuckets))); + // debug_assert!(matches!(builder.build(10), Err(DataBaseError::TooManyBuckets))); let (histogram, _) = builder.build(5)?; - assert_eq!(histogram.correlation, 1.0); - assert_eq!(histogram.null_count, 2); - assert_eq!(histogram.buckets.len(), 5); - assert_eq!( + debug_assert_eq!(histogram.correlation, 1.0); + debug_assert_eq!(histogram.null_count, 2); + debug_assert_eq!(histogram.buckets.len(), 5); + debug_assert_eq!( histogram.buckets, vec![ Bucket { @@ -572,10 +572,10 @@ mod tests { let (histogram, _) = builder.build(5)?; - assert_eq!(histogram.correlation, -1.0); - assert_eq!(histogram.null_count, 2); - assert_eq!(histogram.buckets.len(), 5); - assert_eq!( + debug_assert_eq!(histogram.correlation, -1.0); + debug_assert_eq!(histogram.null_count, 2); + debug_assert_eq!(histogram.buckets.len(), 5); + debug_assert_eq!( histogram.buckets, vec![ Bucket { @@ -636,10 +636,10 @@ mod tests { let (histogram, _) = builder.build(4)?; - assert!(histogram.correlation < 0.0); - assert_eq!(histogram.null_count, 2); - assert_eq!(histogram.buckets.len(), 4); - assert_eq!( + debug_assert!(histogram.correlation < 0.0); + debug_assert_eq!(histogram.null_count, 2); + debug_assert_eq!(histogram.buckets.len(), 4); + debug_assert_eq!( histogram.buckets, vec![ Bucket { @@ -706,7 +706,7 @@ mod tests { &sketch, )?; - assert_eq!(count_1, 9); + debug_assert_eq!(count_1, 9); let count_2 = histogram.collect_count( &vec![Range::Scope { @@ -716,7 +716,7 @@ mod tests { &sketch, )?; - assert_eq!(count_2, 11); + debug_assert_eq!(count_2, 11); let count_3 = histogram.collect_count( &vec![Range::Scope { @@ -726,7 +726,7 @@ mod tests { &sketch, )?; - assert_eq!(count_3, 7); + debug_assert_eq!(count_3, 7); let count_4 = histogram.collect_count( &vec![Range::Scope { @@ -736,7 +736,7 @@ mod tests { &sketch, )?; - assert_eq!(count_4, 12); + debug_assert_eq!(count_4, 12); let count_5 = histogram.collect_count( &vec![Range::Scope { @@ -746,7 +746,7 @@ mod tests { &sketch, )?; - assert_eq!(count_5, 8); + debug_assert_eq!(count_5, 8); let count_6 = histogram.collect_count( &vec![Range::Scope { @@ -756,7 +756,7 @@ mod tests { &sketch, )?; - assert_eq!(count_6, 13); + debug_assert_eq!(count_6, 13); let count_7 = histogram.collect_count( &vec![Range::Scope { @@ -766,7 +766,7 @@ mod tests { &sketch, )?; - assert_eq!(count_7, 13); + debug_assert_eq!(count_7, 13); let count_8 = histogram.collect_count( &vec![Range::Scope { @@ -776,7 +776,7 @@ mod tests { &sketch, )?; - assert_eq!(count_8, 13); + debug_assert_eq!(count_8, 13); let count_9 = histogram.collect_count( &vec![Range::Scope { @@ -786,7 +786,7 @@ mod tests { &sketch, )?; - assert_eq!(count_9, 13); + debug_assert_eq!(count_9, 13); let count_10 = histogram.collect_count( &vec![Range::Scope { @@ -796,7 +796,7 @@ mod tests { &sketch, )?; - assert_eq!(count_10, 2); + debug_assert_eq!(count_10, 2); let count_11 = histogram.collect_count( &vec![Range::Scope { @@ -806,7 +806,7 @@ mod tests { &sketch, )?; - assert_eq!(count_11, 2); + debug_assert_eq!(count_11, 2); Ok(()) } diff --git a/src/optimizer/core/memo.rs b/src/optimizer/core/memo.rs index 04ac32ad..de555014 100644 --- a/src/optimizer/core/memo.rs +++ b/src/optimizer/core/memo.rs @@ -165,12 +165,12 @@ mod tests { let best_plan = graph.into_plan(Some(&memo)); let exprs = &memo.groups.get(&NodeIndex::new(3)).unwrap(); - assert_eq!(exprs.exprs.len(), 2); - assert_eq!(exprs.exprs[0].cost, Some(1000)); - assert_eq!(exprs.exprs[0].op, PhysicalOption::SeqScan); - assert!(exprs.exprs[1].cost.unwrap() >= 960); - assert!(matches!(exprs.exprs[1].op, PhysicalOption::IndexScan(_))); - assert_eq!( + debug_assert_eq!(exprs.exprs.len(), 2); + debug_assert_eq!(exprs.exprs[0].cost, Some(1000)); + debug_assert_eq!(exprs.exprs[0].op, PhysicalOption::SeqScan); + debug_assert!(exprs.exprs[1].cost.unwrap() >= 960); + debug_assert!(matches!(exprs.exprs[1].op, PhysicalOption::IndexScan(_))); + debug_assert_eq!( best_plan.as_ref().unwrap().childrens[0].childrens[0].childrens[0].physical_option, Some(PhysicalOption::IndexScan(IndexInfo { meta: Arc::new(IndexMeta { diff --git a/src/optimizer/core/statistics_meta.rs b/src/optimizer/core/statistics_meta.rs index e5eab3db..4a9ef8d8 100644 --- a/src/optimizer/core/statistics_meta.rs +++ b/src/optimizer/core/statistics_meta.rs @@ -154,8 +154,8 @@ mod tests { StatisticsMeta::new(histogram.clone(), sketch.clone()).to_file(path.clone())?; let statistics_meta = StatisticsMeta::from_file(path)?; - assert_eq!(histogram, statistics_meta.histogram); - assert_eq!( + debug_assert_eq!(histogram, statistics_meta.histogram); + debug_assert_eq!( sketch.estimate(&DataValue::Null), statistics_meta.cm_sketch.estimate(&DataValue::Null) ); diff --git a/src/optimizer/heuristic/graph.rs b/src/optimizer/heuristic/graph.rs index acc46260..20e5b41e 100644 --- a/src/optimizer/heuristic/graph.rs +++ b/src/optimizer/heuristic/graph.rs @@ -120,7 +120,7 @@ impl HepGraph { } } } else { - assert!(children_ids.len() < 2); + debug_assert!(children_ids.len() < 2); self.root_index = children_ids[0]; } } @@ -226,19 +226,19 @@ mod tests { let plan = select_sql_run("select * from t1 left join t2 on c1 = c3")?; let graph = HepGraph::new(plan); - assert!(graph + debug_assert!(graph .graph .contains_edge(NodeIndex::new(1), NodeIndex::new(2))); - assert!(graph + debug_assert!(graph .graph .contains_edge(NodeIndex::new(1), NodeIndex::new(3))); - assert!(graph + debug_assert!(graph .graph .contains_edge(NodeIndex::new(0), NodeIndex::new(1))); - assert_eq!(graph.graph.edge_weight(EdgeIndex::new(0)), Some(&0)); - assert_eq!(graph.graph.edge_weight(EdgeIndex::new(1)), Some(&1)); - assert_eq!(graph.graph.edge_weight(EdgeIndex::new(2)), Some(&0)); + debug_assert_eq!(graph.graph.edge_weight(EdgeIndex::new(0)), Some(&0)); + debug_assert_eq!(graph.graph.edge_weight(EdgeIndex::new(1)), Some(&1)); + debug_assert_eq!(graph.graph.edge_weight(EdgeIndex::new(2)), Some(&0)); Ok(()) } @@ -254,19 +254,19 @@ mod tests { graph.add_node(HepNodeId::new(5), None, Operator::Dummy); - assert!(graph + debug_assert!(graph .graph .contains_edge(NodeIndex::new(5), NodeIndex::new(4))); - assert!(graph + debug_assert!(graph .graph .contains_edge(NodeIndex::new(1), NodeIndex::new(5))); - assert!(graph + debug_assert!(graph .graph .contains_edge(NodeIndex::new(5), NodeIndex::new(6))); - assert_eq!(graph.graph.edge_weight(EdgeIndex::new(3)), Some(&0)); - assert_eq!(graph.graph.edge_weight(EdgeIndex::new(4)), Some(&2)); - assert_eq!(graph.graph.edge_weight(EdgeIndex::new(5)), Some(&1)); + debug_assert_eq!(graph.graph.edge_weight(EdgeIndex::new(3)), Some(&0)); + debug_assert_eq!(graph.graph.edge_weight(EdgeIndex::new(4)), Some(&2)); + debug_assert_eq!(graph.graph.edge_weight(EdgeIndex::new(5)), Some(&1)); Ok(()) } @@ -278,7 +278,7 @@ mod tests { graph.replace_node(HepNodeId::new(1), Operator::Dummy); - assert!(matches!(graph.operator(HepNodeId::new(1)), Operator::Dummy)); + debug_assert!(matches!(graph.operator(HepNodeId::new(1)), Operator::Dummy)); Ok(()) } @@ -290,12 +290,12 @@ mod tests { graph.remove_node(HepNodeId::new(1), false); - assert_eq!(graph.graph.edge_count(), 2); + debug_assert_eq!(graph.graph.edge_count(), 2); - assert!(graph + debug_assert!(graph .graph .contains_edge(NodeIndex::new(0), NodeIndex::new(2))); - assert!(graph + debug_assert!(graph .graph .contains_edge(NodeIndex::new(0), NodeIndex::new(3))); @@ -309,7 +309,7 @@ mod tests { graph.remove_node(HepNodeId::new(1), true); - assert_eq!(graph.graph.edge_count(), 0); + debug_assert_eq!(graph.graph.edge_count(), 0); Ok(()) } @@ -327,8 +327,8 @@ mod tests { let op_0 = graph.operator(HepNodeId::new(0)); let op_1 = graph.operator(HepNodeId::new(1)); - assert_eq!(op_0, &before_op_1); - assert_eq!(op_1, &before_op_0); + debug_assert_eq!(op_0, &before_op_1); + debug_assert_eq!(op_1, &before_op_0); Ok(()) } @@ -340,11 +340,11 @@ mod tests { graph.add_root(Operator::Dummy); - assert_eq!(graph.graph.edge_count(), 4); - assert!(graph + debug_assert_eq!(graph.graph.edge_count(), 4); + debug_assert!(graph .graph .contains_edge(NodeIndex::new(4), NodeIndex::new(0))); - assert_eq!(graph.graph.edge_weight(EdgeIndex::new(3)), Some(&0)); + debug_assert_eq!(graph.graph.edge_weight(EdgeIndex::new(3)), Some(&0)); Ok(()) } @@ -365,7 +365,7 @@ mod tests { let plan_for_graph = graph.into_plan(None).unwrap(); - assert_eq!(plan, plan_for_graph); + debug_assert_eq!(plan, plan_for_graph); Ok(()) } diff --git a/src/optimizer/heuristic/matcher.rs b/src/optimizer/heuristic/matcher.rs index bb264a02..b0777c11 100644 --- a/src/optimizer/heuristic/matcher.rs +++ b/src/optimizer/heuristic/matcher.rs @@ -84,7 +84,7 @@ mod tests { }]), }; - assert!( + debug_assert!( HepMatcher::new(&project_into_table_scan_pattern, HepNodeId::new(0), &graph) .match_opt_expr() ); @@ -128,6 +128,8 @@ mod tests { children: PatternChildrenPredicate::Recursive, }; - assert!(HepMatcher::new(&only_dummy_pattern, HepNodeId::new(0), &graph).match_opt_expr()); + debug_assert!( + HepMatcher::new(&only_dummy_pattern, HepNodeId::new(0), &graph).match_opt_expr() + ); } } diff --git a/src/optimizer/rule/normalization/column_pruning.rs b/src/optimizer/rule/normalization/column_pruning.rs index 9f0e9e31..3e91193a 100644 --- a/src/optimizer/rule/normalization/column_pruning.rs +++ b/src/optimizer/rule/normalization/column_pruning.rs @@ -214,30 +214,30 @@ mod tests { ) .find_best::(None)?; - assert_eq!(best_plan.childrens.len(), 1); + debug_assert_eq!(best_plan.childrens.len(), 1); match best_plan.operator { Operator::Project(op) => { - assert_eq!(op.exprs.len(), 2); + debug_assert_eq!(op.exprs.len(), 2); } _ => unreachable!("Should be a project operator"), } match &best_plan.childrens[0].operator { Operator::Join(op) => match &op.on { JoinCondition::On { on, filter } => { - assert_eq!(on.len(), 1); - assert!(filter.is_none()); + debug_assert_eq!(on.len(), 1); + debug_assert!(filter.is_none()); } _ => unreachable!("Should be a on condition"), }, _ => unreachable!("Should be a join operator"), } - assert_eq!(best_plan.childrens[0].childrens.len(), 2); + debug_assert_eq!(best_plan.childrens[0].childrens.len(), 2); for grandson_plan in &best_plan.childrens[0].childrens { match &grandson_plan.operator { Operator::TableScan(op) => { - assert_eq!(op.columns.len(), 1); + debug_assert_eq!(op.columns.len(), 1); } _ => unreachable!("Should be a scan operator"), } diff --git a/src/optimizer/rule/normalization/combine_operators.rs b/src/optimizer/rule/normalization/combine_operators.rs index 941d2bd4..64e05142 100644 --- a/src/optimizer/rule/normalization/combine_operators.rs +++ b/src/optimizer/rule/normalization/combine_operators.rs @@ -182,13 +182,13 @@ mod tests { let best_plan = optimizer.find_best::(None)?; if let Operator::Project(op) = &best_plan.operator { - assert_eq!(op.exprs.len(), 1); + debug_assert_eq!(op.exprs.len(), 1); } else { unreachable!("Should be a project operator") } if let Operator::TableScan(_) = &best_plan.childrens[0].operator { - assert_eq!(best_plan.childrens[0].childrens.len(), 0) + debug_assert_eq!(best_plan.childrens[0].childrens.len(), 0) } else { unreachable!("Should be a scan operator") } @@ -228,7 +228,7 @@ mod tests { if let Operator::Filter(op) = &best_plan.childrens[0].operator { if let ScalarExpression::Binary { op, .. } = &op.predicate { - assert_eq!(op, &BinaryOperator::And); + debug_assert_eq!(op, &BinaryOperator::And); } else { unreachable!("Should be a and operator") } diff --git a/src/optimizer/rule/normalization/pushdown_limit.rs b/src/optimizer/rule/normalization/pushdown_limit.rs index d3f421ab..82009917 100644 --- a/src/optimizer/rule/normalization/pushdown_limit.rs +++ b/src/optimizer/rule/normalization/pushdown_limit.rs @@ -193,7 +193,7 @@ mod tests { } if let Operator::Limit(op) = &best_plan.childrens[0].childrens[0].childrens[0].operator { - assert_eq!(op.limit, Some(1)); + debug_assert_eq!(op.limit, Some(1)); } else { unreachable!("Should be a limit operator") } @@ -217,7 +217,7 @@ mod tests { .find_best::(None)?; if let Operator::TableScan(op) = &best_plan.childrens[0].operator { - assert_eq!(op.limit, (Some(1), Some(1))) + debug_assert_eq!(op.limit, (Some(1), Some(1))) } else { unreachable!("Should be a project operator") } diff --git a/src/optimizer/rule/normalization/pushdown_predicates.rs b/src/optimizer/rule/normalization/pushdown_predicates.rs index 1985974d..6867ff34 100644 --- a/src/optimizer/rule/normalization/pushdown_predicates.rs +++ b/src/optimizer/rule/normalization/pushdown_predicates.rs @@ -303,7 +303,7 @@ mod tests { max: Bound::Unbounded, }; - assert_eq!(op.index_infos[1].range, Some(mock_range)); + debug_assert_eq!(op.index_infos[1].range, Some(mock_range)); } else { unreachable!("Should be a filter operator") } diff --git a/src/optimizer/rule/normalization/simplification.rs b/src/optimizer/rule/normalization/simplification.rs index a048795e..0779a7aa 100644 --- a/src/optimizer/rule/normalization/simplification.rs +++ b/src/optimizer/rule/normalization/simplification.rs @@ -146,11 +146,11 @@ mod test { if let Operator::Project(project_op) = best_plan.clone().operator { let constant_expr = ScalarExpression::Constant(Arc::new(DataValue::Int32(Some(3)))); if let ScalarExpression::Binary { right_expr, .. } = &project_op.exprs[0] { - assert_eq!(right_expr.as_ref(), &constant_expr); + debug_assert_eq!(right_expr.as_ref(), &constant_expr); } else { unreachable!(); } - assert_eq!(&project_op.exprs[1], &constant_expr); + debug_assert_eq!(&project_op.exprs[1], &constant_expr); } else { unreachable!(); } @@ -158,7 +158,7 @@ mod test { let range = RangeDetacher::new("t1", &0) .detach(&filter_op.predicate) .unwrap(); - assert_eq!( + debug_assert_eq!( range, Range::Scope { min: Bound::Unbounded, @@ -217,17 +217,17 @@ mod test { let op_4 = op(plan_4)?; let op_5 = op(plan_9)?; - assert!(op_1.is_some()); - assert!(op_2.is_some()); - assert!(op_3.is_some()); - assert!(op_4.is_some()); - assert!(op_5.is_some()); + debug_assert!(op_1.is_some()); + debug_assert!(op_2.is_some()); + debug_assert!(op_3.is_some()); + debug_assert!(op_4.is_some()); + debug_assert!(op_5.is_some()); - assert_eq!(op_1, op(plan_5)?); - assert_eq!(op_2, op(plan_6)?); - assert_eq!(op_3, op(plan_7)?); - assert_eq!(op_4, op(plan_8)?); - assert_eq!(op_5, op(plan_10)?); + debug_assert_eq!(op_1, op(plan_5)?); + debug_assert_eq!(op_2, op(plan_6)?); + debug_assert_eq!(op_3, op(plan_7)?); + debug_assert_eq!(op_4, op(plan_8)?); + debug_assert_eq!(op_5, op(plan_10)?); Ok(()) } @@ -274,7 +274,7 @@ mod test { }; // -(c1 + 1) > c2 => c1 < -c2 - 1 - assert_eq!( + debug_assert_eq!( filter_op.predicate, ScalarExpression::Binary { op: BinaryOperator::Gt, @@ -345,56 +345,56 @@ mod test { let range_4_c1 = plan_filter(&plan_4, &0)?.unwrap(); let range_4_c2 = plan_filter(&plan_4, &1)?.unwrap(); - assert_eq!( + debug_assert_eq!( range_1_c1, Range::Scope { min: Bound::Unbounded, max: Bound::Excluded(Arc::new(DataValue::Int32(Some(-2)))) } ); - assert_eq!( + debug_assert_eq!( range_1_c2, Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(2)))), max: Bound::Unbounded } ); - assert_eq!( + debug_assert_eq!( range_2_c1, Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(2)))), max: Bound::Unbounded } ); - assert_eq!( + debug_assert_eq!( range_2_c2, Range::Scope { min: Bound::Unbounded, max: Bound::Excluded(Arc::new(DataValue::Int32(Some(-2)))) } ); - assert_eq!( + debug_assert_eq!( range_3_c1, Range::Scope { min: Bound::Unbounded, max: Bound::Excluded(Arc::new(DataValue::Int32(Some(-1)))) } ); - assert_eq!( + debug_assert_eq!( range_3_c2, Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(0)))), max: Bound::Unbounded } ); - assert_eq!( + debug_assert_eq!( range_4_c1, Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(0)))), max: Bound::Unbounded } ); - assert_eq!( + debug_assert_eq!( range_4_c2, Range::Scope { min: Bound::Unbounded, @@ -410,7 +410,7 @@ mod test { // c1 > c2 or c1 > 1 let plan_1 = select_sql_run("select * from t1 where c1 > c2 or c1 > 1")?; - assert_eq!(plan_filter(&plan_1, &0)?, None); + debug_assert_eq!(plan_filter(&plan_1, &0)?, None); Ok(()) } @@ -419,7 +419,7 @@ mod test { fn test_simplify_filter_multiple_dispersed_same_column_in_or() -> Result<(), DatabaseError> { let plan_1 = select_sql_run("select * from t1 where c1 = 4 and c1 > c2 or c1 > 1")?; - assert_eq!( + debug_assert_eq!( plan_filter(&plan_1, &0)?, Some(Range::Scope { min: Bound::Excluded(Arc::new(DataValue::Int32(Some(1)))), @@ -434,7 +434,7 @@ mod test { fn test_simplify_filter_column_is_null() -> Result<(), DatabaseError> { let plan_1 = select_sql_run("select * from t1 where c1 is null")?; - assert_eq!( + debug_assert_eq!( plan_filter(&plan_1, &0)?, Some(Range::Eq(Arc::new(DataValue::Null))) ); @@ -446,7 +446,7 @@ mod test { fn test_simplify_filter_column_is_not_null() -> Result<(), DatabaseError> { let plan_1 = select_sql_run("select * from t1 where c1 is not null")?; - assert_eq!(plan_filter(&plan_1, &0)?, None); + debug_assert_eq!(plan_filter(&plan_1, &0)?, None); Ok(()) } @@ -455,7 +455,7 @@ mod test { fn test_simplify_filter_column_in() -> Result<(), DatabaseError> { let plan_1 = select_sql_run("select * from t1 where c1 in (1, 2, 3)")?; - assert_eq!( + debug_assert_eq!( plan_filter(&plan_1, &0)?, Some(Range::SortedRanges(vec![ Range::Eq(Arc::new(DataValue::Int32(Some(1)))), @@ -471,7 +471,7 @@ mod test { fn test_simplify_filter_column_not_in() -> Result<(), DatabaseError> { let plan_1 = select_sql_run("select * from t1 where c1 not in (1, 2, 3)")?; - assert_eq!(plan_filter(&plan_1, &0)?, None); + debug_assert_eq!(plan_filter(&plan_1, &0)?, None); Ok(()) } diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 95d5bd85..c3ba7fba 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -47,8 +47,8 @@ pub trait Transaction: Sized { bounds: Bounds, mut columns: Vec<(usize, ColumnRef)>, ) -> Result, DatabaseError> { - assert!(columns.is_sorted_by_key(|(i, _)| i)); - assert!(columns.iter().map(|(i, _)| i).all_unique()); + debug_assert!(columns.is_sorted_by_key(|(i, _)| i)); + debug_assert!(columns.iter().map(|(i, _)| i).all_unique()); let table = self .table(table_cache, table_name.clone()) @@ -87,8 +87,8 @@ pub trait Transaction: Sized { index_meta: IndexMetaRef, ranges: Vec, ) -> Result, DatabaseError> { - assert!(columns.is_sorted_by_key(|(i, _)| i)); - assert!(columns.iter().map(|(i, _)| i).all_unique()); + debug_assert!(columns.is_sorted_by_key(|(i, _)| i)); + debug_assert!(columns.iter().map(|(i, _)| i).all_unique()); let table = self .table(table_cache, table_name.clone()) diff --git a/src/storage/rocksdb.rs b/src/storage/rocksdb.rs index d1c7a7b4..0568887b 100644 --- a/src/storage/rocksdb.rs +++ b/src/storage/rocksdb.rs @@ -179,8 +179,8 @@ mod test { )?; let table_catalog = transaction.table(&table_cache, Arc::new("test".to_string())); - assert!(table_catalog.is_some()); - assert!(table_catalog + debug_assert!(table_catalog.is_some()); + debug_assert!(table_catalog .unwrap() .get_column_id_by_name(&"c1".to_string()) .is_some()); @@ -218,13 +218,13 @@ mod test { )?; let option_1 = iter.next_tuple()?; - assert_eq!( + debug_assert_eq!( option_1.unwrap().id, Some(Arc::new(DataValue::Int32(Some(2)))) ); let option_2 = iter.next_tuple()?; - assert_eq!(option_2, None); + debug_assert_eq!(option_2, None); Ok(()) } @@ -283,7 +283,7 @@ mod test { result.push(tuple.id.unwrap()); } - assert_eq!(result, tuple_ids); + debug_assert_eq!(result, tuple_ids); Ok(()) } @@ -316,8 +316,8 @@ mod test { .unwrap(); while let Some(tuple) = iter.next_tuple()? { - assert_eq!(tuple.id, Some(Arc::new(DataValue::Int32(Some(1))))); - assert_eq!( + debug_assert_eq!(tuple.id, Some(Arc::new(DataValue::Int32(Some(1))))); + debug_assert_eq!( tuple.values, vec![ Arc::new(DataValue::Int32(Some(1))), diff --git a/src/storage/table_codec.rs b/src/storage/table_codec.rs index 3295e97b..8ab429e7 100644 --- a/src/storage/table_codec.rs +++ b/src/storage/table_codec.rs @@ -401,7 +401,7 @@ mod tests { )?; let schema = table_catalog.schema_ref(); - assert_eq!( + debug_assert_eq!( TableCodec::decode_tuple(&table_catalog.types(), &[0, 1], schema, &bytes), tuple ); @@ -419,7 +419,7 @@ mod tests { let table_meta = TableCodec::decode_root_table(&bytes).unwrap(); - assert_eq!(table_meta.table_name.as_str(), table_catalog.name.as_str()); + debug_assert_eq!(table_meta.table_name.as_str(), table_catalog.name.as_str()); } #[test] @@ -428,7 +428,7 @@ mod tests { let (_, bytes) = TableCodec::encode_statistics_path("t1", 0, path.clone()); let decode_path = TableCodec::decode_statistics_path(&bytes).unwrap(); - assert_eq!(path, decode_path); + debug_assert_eq!(path, decode_path); } #[test] @@ -443,7 +443,7 @@ mod tests { }; let (_, bytes) = TableCodec::encode_index_meta(&"T1".to_string(), &index_meta)?; - assert_eq!(TableCodec::decode_index_meta(&bytes)?, index_meta); + debug_assert_eq!(TableCodec::decode_index_meta(&bytes)?, index_meta); Ok(()) } @@ -456,7 +456,7 @@ mod tests { let tuple_id = Arc::new(DataValue::Int32(Some(0))); let (_, bytes) = TableCodec::encode_index(&table_catalog.name, &index, &tuple_id)?; - assert_eq!( + debug_assert_eq!( TableCodec::decode_index(&bytes, &tuple_id.logical_type()), tuple_id ); @@ -472,7 +472,7 @@ mod tests { let (_, bytes) = TableCodec::encode_column(&table_catalog.name, &col).unwrap(); let decode_col = TableCodec::decode_column(&bytes).unwrap(); - assert_eq!(&decode_col, col.as_ref()); + debug_assert_eq!(&decode_col, col.as_ref()); } #[test] @@ -517,11 +517,11 @@ mod tests { )) .collect_vec(); - assert_eq!(vec.len(), 3); + debug_assert_eq!(vec.len(), 3); - assert_eq!(vec[0], &op(0, "T1")); - assert_eq!(vec[1], &op(1, "T1")); - assert_eq!(vec[2], &op(2, "T1")); + debug_assert_eq!(vec[0], &op(0, "T1")); + debug_assert_eq!(vec[1], &op(1, "T1")); + debug_assert_eq!(vec[2], &op(2, "T1")); } #[test] @@ -563,11 +563,11 @@ mod tests { )) .collect_vec(); - assert_eq!(vec.len(), 3); + debug_assert_eq!(vec.len(), 3); - assert_eq!(vec[0], &op(0, "T1")); - assert_eq!(vec[1], &op(1, "T1")); - assert_eq!(vec[2], &op(2, "T1")); + debug_assert_eq!(vec[0], &op(0, "T1")); + debug_assert_eq!(vec[1], &op(1, "T1")); + debug_assert_eq!(vec[2], &op(2, "T1")); } #[test] @@ -617,17 +617,17 @@ mod tests { )) .collect_vec(); - assert_eq!(vec.len(), 3); + debug_assert_eq!(vec.len(), 3); - assert_eq!( + debug_assert_eq!( vec[0], &op(DataValue::Int32(Some(0)), 1, &table_catalog.name) ); - assert_eq!( + debug_assert_eq!( vec[1], &op(DataValue::Int32(Some(1)), 1, &table_catalog.name) ); - assert_eq!( + debug_assert_eq!( vec[2], &op(DataValue::Int32(Some(2)), 1, &table_catalog.name) ); @@ -668,11 +668,11 @@ mod tests { )) .collect_vec(); - assert_eq!(vec.len(), 3); + debug_assert_eq!(vec.len(), 3); - assert_eq!(vec[0], &op(DataValue::Int32(Some(0)), 0, "T1")); - assert_eq!(vec[1], &op(DataValue::Int32(Some(1)), 0, "T1")); - assert_eq!(vec[2], &op(DataValue::Int32(Some(2)), 0, "T1")); + debug_assert_eq!(vec[0], &op(DataValue::Int32(Some(0)), 0, "T1")); + debug_assert_eq!(vec[1], &op(DataValue::Int32(Some(1)), 0, "T1")); + debug_assert_eq!(vec[2], &op(DataValue::Int32(Some(2)), 0, "T1")); } #[test] @@ -703,11 +703,11 @@ mod tests { )) .collect_vec(); - assert_eq!(vec.len(), 3); + debug_assert_eq!(vec.len(), 3); - assert_eq!(vec[0], &op(DataValue::Int32(Some(0)), "T1")); - assert_eq!(vec[1], &op(DataValue::Int32(Some(1)), "T1")); - assert_eq!(vec[2], &op(DataValue::Int32(Some(2)), "T1")); + debug_assert_eq!(vec[0], &op(DataValue::Int32(Some(0)), "T1")); + debug_assert_eq!(vec[1], &op(DataValue::Int32(Some(1)), "T1")); + debug_assert_eq!(vec[2], &op(DataValue::Int32(Some(2)), "T1")); } #[test] @@ -732,8 +732,8 @@ mod tests { )) .collect_vec(); - assert_eq!(vec[0], &op("T0")); - assert_eq!(vec[1], &op("T1")); - assert_eq!(vec[2], &op("T2")); + debug_assert_eq!(vec[0], &op("T0")); + debug_assert_eq!(vec[1], &op("T1")); + debug_assert_eq!(vec[2], &op("T2")); } } diff --git a/src/types/evaluator/mod.rs b/src/types/evaluator/mod.rs index c86c59b2..8ffd5358 100644 --- a/src/types/evaluator/mod.rs +++ b/src/types/evaluator/mod.rs @@ -562,9 +562,9 @@ mod test { .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(1))); - assert_eq!(plus_i32_1, plus_i32_2); - assert_eq!(plus_i32_2, plus_i32_3); - assert_eq!(plus_i32_4, DataValue::Int32(Some(2))); + debug_assert_eq!(plus_i32_1, plus_i32_2); + debug_assert_eq!(plus_i32_2, plus_i32_3); + debug_assert_eq!(plus_i32_4, DataValue::Int32(Some(2))); let plus_evaluator = EvaluatorFactory::binary_create(LogicalType::Bigint, BinaryOperator::Plus)?; @@ -581,9 +581,9 @@ mod test { .0 .binary_eval(&DataValue::Int64(Some(1)), &DataValue::Int64(Some(1))); - assert_eq!(plus_i64_1, plus_i64_2); - assert_eq!(plus_i64_2, plus_i64_3); - assert_eq!(plus_i64_4, DataValue::Int64(Some(2))); + debug_assert_eq!(plus_i64_1, plus_i64_2); + debug_assert_eq!(plus_i64_2, plus_i64_3); + debug_assert_eq!(plus_i64_4, DataValue::Int64(Some(2))); let plus_evaluator = EvaluatorFactory::binary_create(LogicalType::Double, BinaryOperator::Plus)?; @@ -601,9 +601,9 @@ mod test { &DataValue::Float64(Some(1.0)), ); - assert_eq!(plus_f64_1, plus_f64_2); - assert_eq!(plus_f64_2, plus_f64_3); - assert_eq!(plus_f64_4, DataValue::Float64(Some(2.0))); + debug_assert_eq!(plus_f64_1, plus_f64_2); + debug_assert_eq!(plus_f64_2, plus_f64_3); + debug_assert_eq!(plus_f64_4, DataValue::Float64(Some(2.0))); Ok(()) } @@ -625,9 +625,9 @@ mod test { .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(1))); - assert_eq!(minus_i32_1, minus_i32_2); - assert_eq!(minus_i32_2, minus_i32_3); - assert_eq!(minus_i32_4, DataValue::Int32(Some(0))); + debug_assert_eq!(minus_i32_1, minus_i32_2); + debug_assert_eq!(minus_i32_2, minus_i32_3); + debug_assert_eq!(minus_i32_4, DataValue::Int32(Some(0))); let minus_evaluator = EvaluatorFactory::binary_create(LogicalType::Bigint, BinaryOperator::Minus)?; @@ -644,9 +644,9 @@ mod test { .0 .binary_eval(&DataValue::Int64(Some(1)), &DataValue::Int64(Some(1))); - assert_eq!(minus_i64_1, minus_i64_2); - assert_eq!(minus_i64_2, minus_i64_3); - assert_eq!(minus_i64_4, DataValue::Int64(Some(0))); + debug_assert_eq!(minus_i64_1, minus_i64_2); + debug_assert_eq!(minus_i64_2, minus_i64_3); + debug_assert_eq!(minus_i64_4, DataValue::Int64(Some(0))); let minus_evaluator = EvaluatorFactory::binary_create(LogicalType::Double, BinaryOperator::Minus)?; @@ -664,9 +664,9 @@ mod test { &DataValue::Float64(Some(1.0)), ); - assert_eq!(minus_f64_1, minus_f64_2); - assert_eq!(minus_f64_2, minus_f64_3); - assert_eq!(minus_f64_4, DataValue::Float64(Some(0.0))); + debug_assert_eq!(minus_f64_1, minus_f64_2); + debug_assert_eq!(minus_f64_2, minus_f64_3); + debug_assert_eq!(minus_f64_4, DataValue::Float64(Some(0.0))); Ok(()) } @@ -688,9 +688,9 @@ mod test { .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(1))); - assert_eq!(multiply_i32_1, multiply_i32_2); - assert_eq!(multiply_i32_2, multiply_i32_3); - assert_eq!(multiply_i32_4, DataValue::Int32(Some(1))); + debug_assert_eq!(multiply_i32_1, multiply_i32_2); + debug_assert_eq!(multiply_i32_2, multiply_i32_3); + debug_assert_eq!(multiply_i32_4, DataValue::Int32(Some(1))); let multiply_evaluator = EvaluatorFactory::binary_create(LogicalType::Bigint, BinaryOperator::Multiply)?; @@ -707,9 +707,9 @@ mod test { .0 .binary_eval(&DataValue::Int64(Some(1)), &DataValue::Int64(Some(1))); - assert_eq!(multiply_i64_1, multiply_i64_2); - assert_eq!(multiply_i64_2, multiply_i64_3); - assert_eq!(multiply_i64_4, DataValue::Int64(Some(1))); + debug_assert_eq!(multiply_i64_1, multiply_i64_2); + debug_assert_eq!(multiply_i64_2, multiply_i64_3); + debug_assert_eq!(multiply_i64_4, DataValue::Int64(Some(1))); let multiply_evaluator = EvaluatorFactory::binary_create(LogicalType::Double, BinaryOperator::Multiply)?; @@ -727,9 +727,9 @@ mod test { &DataValue::Float64(Some(1.0)), ); - assert_eq!(multiply_f64_1, multiply_f64_2); - assert_eq!(multiply_f64_2, multiply_f64_3); - assert_eq!(multiply_f64_4, DataValue::Float64(Some(1.0))); + debug_assert_eq!(multiply_f64_1, multiply_f64_2); + debug_assert_eq!(multiply_f64_2, multiply_f64_3); + debug_assert_eq!(multiply_f64_4, DataValue::Float64(Some(1.0))); Ok(()) } @@ -751,9 +751,9 @@ mod test { .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(1))); - assert_eq!(divide_i32_1, divide_i32_2); - assert_eq!(divide_i32_2, divide_i32_3); - assert_eq!(divide_i32_4, DataValue::Float64(Some(1.0))); + debug_assert_eq!(divide_i32_1, divide_i32_2); + debug_assert_eq!(divide_i32_2, divide_i32_3); + debug_assert_eq!(divide_i32_4, DataValue::Float64(Some(1.0))); let divide_evaluator = EvaluatorFactory::binary_create(LogicalType::Bigint, BinaryOperator::Divide)?; @@ -770,9 +770,9 @@ mod test { .0 .binary_eval(&DataValue::Int64(Some(1)), &DataValue::Int64(Some(1))); - assert_eq!(divide_i64_1, divide_i64_2); - assert_eq!(divide_i64_2, divide_i64_3); - assert_eq!(divide_i64_4, DataValue::Float64(Some(1.0))); + debug_assert_eq!(divide_i64_1, divide_i64_2); + debug_assert_eq!(divide_i64_2, divide_i64_3); + debug_assert_eq!(divide_i64_4, DataValue::Float64(Some(1.0))); let divide_evaluator = EvaluatorFactory::binary_create(LogicalType::Double, BinaryOperator::Divide)?; @@ -790,9 +790,9 @@ mod test { &DataValue::Float64(Some(1.0)), ); - assert_eq!(divide_f64_1, divide_f64_2); - assert_eq!(divide_f64_2, divide_f64_3); - assert_eq!(divide_f64_4, DataValue::Float64(Some(1.0))); + debug_assert_eq!(divide_f64_1, divide_f64_2); + debug_assert_eq!(divide_f64_2, divide_f64_3); + debug_assert_eq!(divide_f64_4, DataValue::Float64(Some(1.0))); Ok(()) } @@ -800,14 +800,14 @@ mod test { #[test] fn test_binary_op_i32_compare() -> Result<(), DatabaseError> { let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::Gt)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(0)),), DataValue::Boolean(Some(true)) ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::Lt)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(0)),), @@ -815,7 +815,7 @@ mod test { ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::GtEq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(1)),), @@ -823,7 +823,7 @@ mod test { ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::LtEq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(1)),), @@ -831,28 +831,28 @@ mod test { ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::NotEq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(1)),), DataValue::Boolean(Some(false)) ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::Eq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(Some(1)), &DataValue::Int32(Some(1)),), DataValue::Boolean(Some(true)) ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::Gt)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(None), &DataValue::Int32(Some(0)),), DataValue::Boolean(None) ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::Lt)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(None), &DataValue::Int32(Some(0)),), @@ -860,7 +860,7 @@ mod test { ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::GtEq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(None), &DataValue::Int32(Some(1)),), @@ -868,7 +868,7 @@ mod test { ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::LtEq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(None), &DataValue::Int32(Some(1)),), @@ -876,21 +876,21 @@ mod test { ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::NotEq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(None), &DataValue::Int32(Some(1)),), DataValue::Boolean(None) ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::Eq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(None), &DataValue::Int32(Some(1)),), DataValue::Boolean(None) ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::Eq)?; - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Int32(None), &DataValue::Int32(None),), @@ -903,56 +903,56 @@ mod test { #[test] fn test_binary_op_bool_compare() -> Result<(), DatabaseError> { let evaluator = EvaluatorFactory::binary_create(LogicalType::Boolean, BinaryOperator::And)?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Boolean(Some(true)), &DataValue::Boolean(Some(true)), ), DataValue::Boolean(Some(true)) ); - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Boolean(Some(false)), &DataValue::Boolean(Some(true)), ), DataValue::Boolean(Some(false)) ); - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Boolean(Some(false)), &DataValue::Boolean(Some(false)), ), DataValue::Boolean(Some(false)) ); - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Boolean(None), &DataValue::Boolean(Some(true)),), DataValue::Boolean(None) ); let evaluator = EvaluatorFactory::binary_create(LogicalType::Boolean, BinaryOperator::Or)?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Boolean(Some(true)), &DataValue::Boolean(Some(true)), ), DataValue::Boolean(Some(true)) ); - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Boolean(Some(false)), &DataValue::Boolean(Some(true)), ), DataValue::Boolean(Some(true)) ); - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Boolean(Some(false)), &DataValue::Boolean(Some(false)), ), DataValue::Boolean(Some(false)) ); - assert_eq!( + debug_assert_eq!( evaluator .0 .binary_eval(&DataValue::Boolean(None), &DataValue::Boolean(Some(true)),), @@ -968,7 +968,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::Gt, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: Some("a".to_string()), @@ -987,7 +987,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::Lt, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: Some("a".to_string()), @@ -1006,7 +1006,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::GtEq, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: Some("a".to_string()), @@ -1025,7 +1025,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::LtEq, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: Some("a".to_string()), @@ -1044,7 +1044,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::NotEq, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: Some("a".to_string()), @@ -1063,7 +1063,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::Eq, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: Some("a".to_string()), @@ -1082,7 +1082,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::Gt, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: None, @@ -1101,7 +1101,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::Lt, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: None, @@ -1120,7 +1120,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::GtEq, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: None, @@ -1139,7 +1139,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::LtEq, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: None, @@ -1158,7 +1158,7 @@ mod test { LogicalType::Varchar(None, CharLengthUnits::Characters), BinaryOperator::NotEq, )?; - assert_eq!( + debug_assert_eq!( evaluator.0.binary_eval( &DataValue::Utf8 { value: None, diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 5b852b96..faf1aea1 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -40,8 +40,8 @@ impl Tuple { schema: &Schema, bytes: &[u8], ) -> Self { - assert!(!schema.is_empty()); - assert_eq!(projections.len(), schema.len()); + debug_assert!(!schema.is_empty()); + debug_assert_eq!(projections.len(), schema.len()); fn is_none(bits: u8, i: usize) -> bool { bits & (1 << (7 - i)) > 0 @@ -110,7 +110,7 @@ impl Tuple { /// e.g.: bits(u8)..|data_0(len for utf8_1)|utf8_0|data_1| /// Tips: all len is u32 pub fn serialize_to(&self, types: &[LogicalType]) -> Result, DatabaseError> { - assert_eq!(self.values.len(), types.len()); + debug_assert_eq!(self.values.len(), types.len()); fn flip_bit(bits: u8, i: usize) -> u8 { bits | (1 << (7 - i)) @@ -153,7 +153,7 @@ pub fn create_table(schema: &Schema, tuples: &[Tuple]) -> Table { table.set_header(header); for tuple in tuples { - assert_eq!(schema.len(), tuple.values.len()); + debug_assert_eq!(schema.len(), tuple.values.len()); let cells = tuple .values @@ -378,7 +378,7 @@ mod tests { &tuples[1].serialize_to(&types).unwrap(), ); - assert_eq!(tuples[0], tuple_0); - assert_eq!(tuples[1], tuple_1); + debug_assert_eq!(tuples[0], tuple_0); + debug_assert_eq!(tuples[1], tuple_1); } } diff --git a/src/types/value.rs b/src/types/value.rs index 5f775cdc..a0cf6798 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -570,7 +570,7 @@ impl DataValue { let mut string_bytes = v.clone().into_bytes(); string_bytes.resize(octets_len, b' '); - assert_eq!(octets_len, string_bytes.len()); + debug_assert_eq!(octets_len, string_bytes.len()); bytes.append(&mut string_bytes); return Ok(octets_len); } @@ -975,6 +975,7 @@ impl DataValue { LogicalType::UBigint => { Ok(DataValue::UInt64(value.map(u64::try_from).transpose()?)) } + LogicalType::Tinyint => Ok(DataValue::Int8(value.map(i8::try_from).transpose()?)), LogicalType::Smallint => Ok(DataValue::Int16(value)), LogicalType::Integer => Ok(DataValue::Int32(value.map(|v| v.into()))), LogicalType::Bigint => Ok(DataValue::Int64(value.map(|v| v.into()))), @@ -1007,6 +1008,10 @@ impl DataValue { LogicalType::UBigint => { Ok(DataValue::UInt64(value.map(u64::try_from).transpose()?)) } + LogicalType::Tinyint => Ok(DataValue::Int8(value.map(i8::try_from).transpose()?)), + LogicalType::Smallint => { + Ok(DataValue::Int16(value.map(i16::try_from).transpose()?)) + } LogicalType::Integer => Ok(DataValue::Int32(value)), LogicalType::Bigint => Ok(DataValue::Int64(value.map(|v| v.into()))), LogicalType::Float => Ok(DataValue::Float32(value.map(|v| v as f32))), @@ -1038,6 +1043,11 @@ impl DataValue { LogicalType::UBigint => { Ok(DataValue::UInt64(value.map(u64::try_from).transpose()?)) } + LogicalType::Tinyint => Ok(DataValue::Int8(value.map(i8::try_from).transpose()?)), + LogicalType::Smallint => { + Ok(DataValue::Int16(value.map(i16::try_from).transpose()?)) + } + LogicalType::Integer => Ok(DataValue::Int32(value.map(i32::try_from).transpose()?)), LogicalType::Bigint => Ok(DataValue::Int64(value)), LogicalType::Float => Ok(DataValue::Float32(value.map(|v| v as f32))), LogicalType::Double => Ok(DataValue::Float64(value.map(|v| v as f64))), @@ -1058,6 +1068,7 @@ impl DataValue { }, DataValue::UInt8(value) => match to { LogicalType::SqlNull => Ok(DataValue::Null), + LogicalType::Tinyint => Ok(DataValue::Int8(value.map(i8::try_from).transpose()?)), LogicalType::UTinyint => Ok(DataValue::UInt8(value)), LogicalType::Smallint => Ok(DataValue::Int16(value.map(|v| v.into()))), LogicalType::USmallint => Ok(DataValue::UInt16(value.map(|v| v.into()))), @@ -1084,6 +1095,11 @@ impl DataValue { }, DataValue::UInt16(value) => match to { LogicalType::SqlNull => Ok(DataValue::Null), + LogicalType::Tinyint => Ok(DataValue::Int8(value.map(i8::try_from).transpose()?)), + LogicalType::UTinyint => Ok(DataValue::UInt8(value.map(u8::try_from).transpose()?)), + LogicalType::Smallint => { + Ok(DataValue::Int16(value.map(i16::try_from).transpose()?)) + } LogicalType::USmallint => Ok(DataValue::UInt16(value)), LogicalType::Integer => Ok(DataValue::Int32(value.map(|v| v.into()))), LogicalType::UInteger => Ok(DataValue::UInt32(value.map(|v| v.into()))), @@ -1108,6 +1124,15 @@ impl DataValue { }, DataValue::UInt32(value) => match to { LogicalType::SqlNull => Ok(DataValue::Null), + LogicalType::Tinyint => Ok(DataValue::Int8(value.map(i8::try_from).transpose()?)), + LogicalType::UTinyint => Ok(DataValue::UInt8(value.map(u8::try_from).transpose()?)), + LogicalType::Smallint => { + Ok(DataValue::Int16(value.map(i16::try_from).transpose()?)) + } + LogicalType::USmallint => { + Ok(DataValue::UInt16(value.map(u16::try_from).transpose()?)) + } + LogicalType::Integer => Ok(DataValue::Int32(value.map(i32::try_from).transpose()?)), LogicalType::UInteger => Ok(DataValue::UInt32(value)), LogicalType::Bigint => Ok(DataValue::Int64(value.map(|v| v.into()))), LogicalType::UBigint => Ok(DataValue::UInt64(value.map(|v| v.into()))), @@ -1130,6 +1155,19 @@ impl DataValue { }, DataValue::UInt64(value) => match to { LogicalType::SqlNull => Ok(DataValue::Null), + LogicalType::Tinyint => Ok(DataValue::Int8(value.map(i8::try_from).transpose()?)), + LogicalType::UTinyint => Ok(DataValue::UInt8(value.map(u8::try_from).transpose()?)), + LogicalType::Smallint => { + Ok(DataValue::Int16(value.map(i16::try_from).transpose()?)) + } + LogicalType::USmallint => { + Ok(DataValue::UInt16(value.map(u16::try_from).transpose()?)) + } + LogicalType::Integer => Ok(DataValue::Int32(value.map(i32::try_from).transpose()?)), + LogicalType::UInteger => { + Ok(DataValue::UInt32(value.map(u32::try_from).transpose()?)) + } + LogicalType::Bigint => Ok(DataValue::Int64(value.map(i64::try_from).transpose()?)), LogicalType::UBigint => Ok(DataValue::UInt64(value)), LogicalType::Float => Ok(DataValue::Float32(value.map(|v| v as f32))), LogicalType::Double => Ok(DataValue::Float64(value.map(|v| v as f64))), @@ -1589,8 +1627,8 @@ mod test { println!("{:?} < {:?}", key_i8_1, key_i8_2); println!("{:?} < {:?}", key_i8_2, key_i8_3); - assert!(key_i8_1 < key_i8_2); - assert!(key_i8_2 < key_i8_3); + debug_assert!(key_i8_1 < key_i8_2); + debug_assert!(key_i8_2 < key_i8_3); let mut key_i16_1 = Vec::new(); let mut key_i16_2 = Vec::new(); @@ -1602,8 +1640,8 @@ mod test { println!("{:?} < {:?}", key_i16_1, key_i16_2); println!("{:?} < {:?}", key_i16_2, key_i16_3); - assert!(key_i16_1 < key_i16_2); - assert!(key_i16_2 < key_i16_3); + debug_assert!(key_i16_1 < key_i16_2); + debug_assert!(key_i16_2 < key_i16_3); let mut key_i32_1 = Vec::new(); let mut key_i32_2 = Vec::new(); @@ -1615,8 +1653,8 @@ mod test { println!("{:?} < {:?}", key_i32_1, key_i32_2); println!("{:?} < {:?}", key_i32_2, key_i32_3); - assert!(key_i32_1 < key_i32_2); - assert!(key_i32_2 < key_i32_3); + debug_assert!(key_i32_1 < key_i32_2); + debug_assert!(key_i32_2 < key_i32_3); let mut key_i64_1 = Vec::new(); let mut key_i64_2 = Vec::new(); @@ -1628,8 +1666,8 @@ mod test { println!("{:?} < {:?}", key_i64_1, key_i64_2); println!("{:?} < {:?}", key_i64_2, key_i64_3); - assert!(key_i64_1 < key_i64_2); - assert!(key_i64_2 < key_i64_3); + debug_assert!(key_i64_1 < key_i64_2); + debug_assert!(key_i64_2 < key_i64_3); Ok(()) } @@ -1646,8 +1684,8 @@ mod test { println!("{:?} < {:?}", key_f32_1, key_f32_2); println!("{:?} < {:?}", key_f32_2, key_f32_3); - assert!(key_f32_1 < key_f32_2); - assert!(key_f32_2 < key_f32_3); + debug_assert!(key_f32_1 < key_f32_2); + debug_assert!(key_f32_2 < key_f32_3); let mut key_f64_1 = Vec::new(); let mut key_f64_2 = Vec::new(); @@ -1659,8 +1697,8 @@ mod test { println!("{:?} < {:?}", key_f64_1, key_f64_2); println!("{:?} < {:?}", key_f64_2, key_f64_3); - assert!(key_f64_1 < key_f64_2); - assert!(key_f64_2 < key_f64_3); + debug_assert!(key_f64_1 < key_f64_2); + debug_assert!(key_f64_2 < key_f64_3); Ok(()) } @@ -1692,8 +1730,8 @@ mod test { println!("{:?} < {:?}", key_tuple_1, key_tuple_2); println!("{:?} < {:?}", key_tuple_2, key_tuple_3); - assert!(key_tuple_1 < key_tuple_2); - assert!(key_tuple_2 < key_tuple_3); + debug_assert!(key_tuple_1 < key_tuple_2); + debug_assert!(key_tuple_2 < key_tuple_3); Ok(()) } diff --git a/src/utils/bit_vector.rs b/src/utils/bit_vector.rs index c0c0be17..887e23a1 100644 --- a/src/utils/bit_vector.rs +++ b/src/utils/bit_vector.rs @@ -79,9 +79,9 @@ mod tests { let vector = BitVector::from_raw(&bytes); for i in 0..98 { - assert!(!vector.get_bit(i)); + debug_assert!(!vector.get_bit(i)); } - assert!(vector.get_bit(99)); + debug_assert!(vector.get_bit(99)); } #[test] @@ -91,8 +91,8 @@ mod tests { vector.set_bit(99, true); for i in 0..98 { - assert!(!vector.get_bit(i)); + debug_assert!(!vector.get_bit(i)); } - assert!(vector.get_bit(99)); + debug_assert!(vector.get_bit(99)); } } diff --git a/src/utils/lru.rs b/src/utils/lru.rs index 07566566..97cd073f 100644 --- a/src/utils/lru.rs +++ b/src/utils/lru.rs @@ -400,35 +400,35 @@ mod tests { #[test] fn test_lru_cache() { let mut lru = LruCache::new(3).unwrap(); - assert!(lru.is_empty()); - assert_eq!(lru.put(1, 10), None); - assert_eq!(lru.put(2, 20), None); - assert_eq!(lru.put(3, 30), None); - assert_eq!(lru.get(&1), Some(&10)); - assert_eq!(lru.put(2, 200), Some(20)); - assert_eq!(lru.put(4, 40), None); - assert_eq!(lru.get(&2), Some(&200)); - assert_eq!(lru.get(&3), None); + debug_assert!(lru.is_empty()); + debug_assert_eq!(lru.put(1, 10), None); + debug_assert_eq!(lru.put(2, 20), None); + debug_assert_eq!(lru.put(3, 30), None); + debug_assert_eq!(lru.get(&1), Some(&10)); + debug_assert_eq!(lru.put(2, 200), Some(20)); + debug_assert_eq!(lru.put(4, 40), None); + debug_assert_eq!(lru.get(&2), Some(&200)); + debug_assert_eq!(lru.get(&3), None); - assert_eq!(lru.get_or_insert(9, |_| Ok(9)).unwrap(), &9); + debug_assert_eq!(lru.get_or_insert(9, |_| Ok(9)).unwrap(), &9); - assert_eq!(lru.len(), 3); - assert!(!lru.is_empty()); + debug_assert_eq!(lru.len(), 3); + debug_assert!(!lru.is_empty()); let mut set = HashSet::from([(&9, &9), (&2, &200), (&4, &40)]); for item in lru.iter() { - assert!(set.remove(&item)) + debug_assert!(set.remove(&item)) } } #[test] fn test_sharding_cache() { let lru = ShardingLruCache::new(4, 2, RandomState::default()).unwrap(); - assert!(lru.is_empty()); - assert_eq!(lru.put(1, 10), None); - assert_eq!(lru.get(&1), Some(&10)); - assert!(!lru.is_empty()); - assert_eq!(lru.get_or_insert(9, |_| Ok(9)).unwrap(), &9); + debug_assert!(lru.is_empty()); + debug_assert_eq!(lru.put(1, 10), None); + debug_assert_eq!(lru.get(&1), Some(&10)); + debug_assert!(!lru.is_empty()); + debug_assert_eq!(lru.get_or_insert(9, |_| Ok(9)).unwrap(), &9); } } diff --git a/tests/slt/crdb/natural_join.slt b/tests/slt/crdb/natural_join.slt new file mode 100644 index 00000000..a7a699c4 --- /dev/null +++ b/tests/slt/crdb/natural_join.slt @@ -0,0 +1,139 @@ +control sortmode rowsort + +statement ok +drop table if exists t1 + +statement ok +CREATE TABLE t1 (t1_id INT PRIMARY KEY, k INT, v INT) + +statement ok +INSERT INTO t1 VALUES (0, -1, -1), (1, 0, 4), (2, 2, 1), (3, 3, 4), (4, 5, 4) + +statement ok +drop table if exists t2 + +statement ok +CREATE TABLE t2 (t2_id INT PRIMARY KEY, x INT, y INT) + +statement ok +INSERT INTO t2 VALUES (0, 0, 5), (1, 1, 3), (2, 1, 4), (3, 3, 2), (4, 3, 3), (5, 4, 6) + +query IIII +SELECT k, v, x, y FROM t1 NATURAL JOIN t2 ORDER BY k, v, x, y +---- +-1 -1 0 5 +-1 -1 1 3 +-1 -1 1 4 +-1 -1 3 2 +-1 -1 3 3 +-1 -1 4 6 +0 4 0 5 +0 4 1 3 +0 4 1 4 +0 4 3 2 +0 4 3 3 +0 4 4 6 +2 1 0 5 +2 1 1 3 +2 1 1 4 +2 1 3 2 +2 1 3 3 +2 1 4 6 +3 4 0 5 +3 4 1 3 +3 4 1 4 +3 4 3 2 +3 4 3 3 +3 4 4 6 +5 4 0 5 +5 4 1 3 +5 4 1 4 +5 4 3 2 +5 4 3 3 +5 4 4 6 + +query IIII +SELECT k, v, x, y FROM t1 JOIN t2 ON k = x +---- +0 4 0 5 +3 4 3 2 +3 4 3 3 + +statement ok +DROP TABLE t1 + +statement ok +DROP TABLE t2 + +statement ok +CREATE TABLE t1 (t1_id INT PRIMARY KEY, k INT NULL) + +statement ok +INSERT INTO t1 VALUES (0, 0), (1, null) + +statement ok +CREATE TABLE t2 (t2_id INT PRIMARY KEY, x INT NULL) + +statement ok +INSERT INTO t2 VALUES (0, 0), (1, null) + +query II +SELECT k, x FROM t1 NATURAL JOIN t2 +---- +0 0 +0 null +null 0 +null null + +query II +SELECT k, x FROM t1 JOIN t2 ON k = x +---- +0 0 + +statement ok +drop table if exists t44798_0 + +statement ok +drop table if exists t44798_1 + +#TODO: different types on joins +# statement ok +# CREATE TABLE t44798_0(c0 TINYINT PRIMARY KEY) + +# statement ok +# CREATE TABLE t44798_1(c0 SMALLINT PRIMARY KEY) + +# statement ok +# INSERT INTO t44798_0(c0) VALUES(0), (1), (2) + +# statement ok +# INSERT INTO t44798_1(c0) VALUES(0), (2), (4) + +# query I +# SELECT * FROM t44798_0 NATURAL JOIN t44798_1 order by c0 +# ---- +# 0 +# 2 + +statement ok +drop table if exists l + +statement ok +drop table if exists r + +statement ok +CREATE TABLE l (l INT PRIMARY KEY) + +statement ok +INSERT INTO l VALUES (1), (2) + +statement ok +CREATE TABLE r (r INT PRIMARY KEY) + +statement ok +INSERT INTO r VALUES (1) + +query II +SELECT *, true FROM (SELECT l FROM l WHERE l NOT IN (SELECT r FROM r)) +---- +2 true \ No newline at end of file