Skip to content

Commit

Permalink
chore: apply suggestions from CR
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Jul 3, 2024
1 parent b9d414d commit 3b76af8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 42 deletions.
12 changes: 8 additions & 4 deletions tests-fuzz/src/ir/insert_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ impl InsertIntoExpr {
self.columns
.iter()
.enumerate()
.find(|(_, c)| c.is_time_index())
.map(|(idx, _)| idx)
.find_map(|(idx, c)| if c.is_time_index() { Some(idx) } else { None })
}

/// Returns a vector of columns that are primary keys or time indices.
Expand All @@ -54,8 +53,13 @@ impl InsertIntoExpr {
self.columns
.iter()
.enumerate()
.filter(|(_, c)| c.is_primary_key() || c.is_time_index())
.map(|(i, _)| i)
.filter_map(|(i, c)| {
if c.is_primary_key() || c.is_time_index() {
Some(i)
} else {
None
}
})
.collect::<Vec<_>>()
}
}
Expand Down
22 changes: 3 additions & 19 deletions tests-fuzz/targets/fuzz_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use tests_fuzz::generator::create_expr::CreateTableExprGeneratorBuilder;
use tests_fuzz::generator::insert_expr::InsertExprGeneratorBuilder;
use tests_fuzz::generator::Generator;
use tests_fuzz::ir::{
generate_random_timestamp_for_mysql, generate_random_value, replace_default, CreateTableExpr,
InsertIntoExpr, MySQLTsColumnTypeGenerator,
generate_random_timestamp_for_mysql, generate_random_value, replace_default,
sort_by_primary_keys, CreateTableExpr, InsertIntoExpr, MySQLTsColumnTypeGenerator,
};
use tests_fuzz::translator::mysql::create_expr::CreateTableExprTranslator;
use tests_fuzz::translator::mysql::insert_expr::InsertIntoExprTranslator;
Expand Down Expand Up @@ -184,23 +184,7 @@ async fn execute_insert(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
);
let fetched_rows = validator::row::fetch_values(&ctx.greptime, select_sql.as_str()).await?;
let mut expected_rows = replace_default(&insert_expr.values_list, &table_ctx, &insert_expr);
expected_rows.sort_by(|a, b| {
let a_keys: Vec<_> = primary_keys_idxs_in_insert_expr
.iter()
.map(|&i| &a[i])
.collect();
let b_keys: Vec<_> = primary_keys_idxs_in_insert_expr
.iter()
.map(|&i| &b[i])
.collect();
for (a_key, b_key) in a_keys.iter().zip(b_keys.iter()) {
match a_key.cmp(b_key) {
Some(std::cmp::Ordering::Equal) => continue,
non_eq => return non_eq.unwrap(),
}
}
std::cmp::Ordering::Equal
});
sort_by_primary_keys(&mut expected_rows, primary_keys_idxs_in_insert_expr);
validator::row::assert_eq::<MySql>(&insert_expr.columns, &fetched_rows, &expected_rows)?;

// Cleans up
Expand Down
22 changes: 3 additions & 19 deletions tests-fuzz/targets/fuzz_insert_logical_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use tests_fuzz::generator::create_expr::{
use tests_fuzz::generator::insert_expr::InsertExprGeneratorBuilder;
use tests_fuzz::generator::Generator;
use tests_fuzz::ir::{
generate_random_timestamp_for_mysql, generate_random_value, replace_default, CreateTableExpr,
InsertIntoExpr,
generate_random_timestamp_for_mysql, generate_random_value, replace_default,
sort_by_primary_keys, CreateTableExpr, InsertIntoExpr,
};
use tests_fuzz::translator::mysql::create_expr::CreateTableExprTranslator;
use tests_fuzz::translator::mysql::insert_expr::InsertIntoExprTranslator;
Expand Down Expand Up @@ -181,23 +181,7 @@ async fn validate_values(
let fetched_rows = validator::row::fetch_values(&ctx.greptime, select_sql.as_str()).await?;
let mut expected_rows =
replace_default(&insert_expr.values_list, &logical_table_ctx, insert_expr);
expected_rows.sort_by(|a, b| {
let a_keys: Vec<_> = primary_keys_idxs_in_insert_expr
.iter()
.map(|&i| &a[i])
.collect();
let b_keys: Vec<_> = primary_keys_idxs_in_insert_expr
.iter()
.map(|&i| &b[i])
.collect();
for (a_key, b_key) in a_keys.iter().zip(b_keys.iter()) {
match a_key.cmp(b_key) {
Some(std::cmp::Ordering::Equal) => continue,
non_eq => return non_eq.unwrap(),
}
}
std::cmp::Ordering::Equal
});
sort_by_primary_keys(&mut expected_rows, primary_keys_idxs_in_insert_expr);
validator::row::assert_eq::<MySql>(&insert_expr.columns, &fetched_rows, &expected_rows)?;

Ok(())
Expand Down

0 comments on commit 3b76af8

Please sign in to comment.