Skip to content

Commit

Permalink
chore: suggested changes and corresponding test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePieWw committed Apr 25, 2024
1 parent e9ec132 commit f569e32
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions tests-fuzz/src/generator/create_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::generator::{ColumnOptionGenerator, ConcreteDataTypeGenerator, Random}
use crate::ir::create_expr::{ColumnOption, CreateDatabaseExprBuilder, CreateTableExprBuilder};
use crate::ir::{
column_options_generator, generate_columns, generate_random_value,
partible_column_options_generator, primary_key_column_options_generator,
partible_column_options_generator, primary_key_and_not_null_column_options_generator,
ts_column_options_generator, Column, ColumnTypeGenerator, CreateDatabaseExpr, CreateTableExpr,
Ident, PartibleColumnTypeGenerator, StringColumnTypeGenerator, TsColumnTypeGenerator,
};
Expand Down Expand Up @@ -246,12 +246,9 @@ impl<R: Rng + 'static> Generator<CreateTableExpr, R> for CreatePhysicalTableExpr
pub struct CreateLogicalTableExprGenerator<R: Rng + 'static> {
physical_table_ctx: TableContextRef,
labels: usize,
#[builder(default = "false")]
if_not_exists: bool,
#[builder(default = "Box::new(WordGenerator)")]
name_generator: Box<dyn Random<Ident, R>>,
#[builder(default = "Box::new(StringColumnTypeGenerator)")]
label_column_type_generator: ConcreteDataTypeGenerator<R>,
}

impl<R: Rng + 'static> Generator<CreateTableExpr, R> for CreateLogicalTableExprGenerator<R> {
Expand Down Expand Up @@ -288,8 +285,8 @@ impl<R: Rng + 'static> Generator<CreateTableExpr, R> for CreateLogicalTableExprG
logical_table.columns.extend(generate_columns(
rng,
column_names,
self.label_column_type_generator.as_ref(),
Box::new(primary_key_column_options_generator),
&StringColumnTypeGenerator,
Box::new(primary_key_and_not_null_column_options_generator),
));

logical_table.columns.iter_mut().for_each(|column| {
Expand Down Expand Up @@ -420,6 +417,7 @@ mod tests {
let mut rng = rand::thread_rng();

let physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
.if_not_exists(false)
.build()
.unwrap()
.generate(&mut rng)
Expand All @@ -443,6 +441,7 @@ mod tests {
let logical_table_expr = CreateLogicalTableExprGeneratorBuilder::default()
.physical_table_ctx(physical_table_ctx)
.labels(5)
.if_not_exists(false)
.build()
.unwrap()
.generate(&mut rng)
Expand Down Expand Up @@ -477,6 +476,7 @@ mod tests {
fn test_create_logical_table_expr_generator_deterministic() {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0);
let physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
.if_not_exists(false)
.build()
.unwrap()
.generate(&mut rng)
Expand All @@ -490,6 +490,7 @@ mod tests {
let logical_table_expr = CreateLogicalTableExprGeneratorBuilder::default()
.physical_table_ctx(physical_table_ctx)
.labels(5)
.if_not_exists(false)
.build()
.unwrap()
.generate(&mut rng)
Expand Down
4 changes: 2 additions & 2 deletions tests-fuzz/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ lazy_static! {
ConcreteDataType::datetime_datatype(),
];
pub static ref STRING_DATA_TYPES: Vec<ConcreteDataType> =
vec![ConcreteDataType::string_datatype(),];
vec![ConcreteDataType::string_datatype()];
}

impl_random!(ConcreteDataType, ColumnTypeGenerator, DATA_TYPES);
Expand Down Expand Up @@ -326,7 +326,7 @@ pub fn ts_column_options_generator<R: Rng + 'static>(
vec![ColumnOption::TimeIndex]
}

pub fn primary_key_column_options_generator<R: Rng + 'static>(
pub fn primary_key_and_not_null_column_options_generator<R: Rng + 'static>(
_: &mut R,
_: &ConcreteDataType,
) -> Vec<ColumnOption> {
Expand Down
6 changes: 3 additions & 3 deletions tests-fuzz/targets/fuzz_create_logical_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use tests_fuzz::generator::create_expr::{
CreateLogicalTableExprGeneratorBuilder, CreatePhysicalTableExprGeneratorBuilder,
};
use tests_fuzz::generator::Generator;
use tests_fuzz::ir::{primary_key_column_options_generator, Column};
use tests_fuzz::ir::{primary_key_and_not_null_column_options_generator, Column};
use tests_fuzz::translator::mysql::create_expr::CreateTableExprTranslator;
use tests_fuzz::translator::DslTranslator;
use tests_fuzz::utils::{init_greptime_connections, Connections};
Expand Down Expand Up @@ -88,7 +88,7 @@ async fn execute_create_logic_table(ctx: FuzzContext, input: FuzzInput) -> Resul
let mut physical_table_columns = create_physical_table_expr.columns.clone();
physical_table_columns.push({
let column_type = ConcreteDataType::uint64_datatype();
let options = primary_key_column_options_generator(&mut rng, &column_type);
let options = primary_key_and_not_null_column_options_generator(&mut rng, &column_type);
Column {
name: "__tsid".into(),
column_type,
Expand All @@ -97,7 +97,7 @@ async fn execute_create_logic_table(ctx: FuzzContext, input: FuzzInput) -> Resul
});
physical_table_columns.push({
let column_type = ConcreteDataType::uint32_datatype();
let options = primary_key_column_options_generator(&mut rng, &column_type);
let options = primary_key_and_not_null_column_options_generator(&mut rng, &column_type);
Column {
name: "__table_id".into(),
column_type,
Expand Down

0 comments on commit f569e32

Please sign in to comment.