From f569e32e0e58a99dd4cbe3d22159eb3b29270c47 Mon Sep 17 00:00:00 2001 From: CookiePieWw <1035325592@qq.com> Date: Fri, 26 Apr 2024 00:45:52 +0800 Subject: [PATCH] chore: suggested changes and corresponding test changes --- tests-fuzz/src/generator/create_expr.rs | 13 +++++++------ tests-fuzz/src/ir.rs | 4 ++-- tests-fuzz/targets/fuzz_create_logical_table.rs | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests-fuzz/src/generator/create_expr.rs b/tests-fuzz/src/generator/create_expr.rs index fab2114f9dce..ad32032a749c 100644 --- a/tests-fuzz/src/generator/create_expr.rs +++ b/tests-fuzz/src/generator/create_expr.rs @@ -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, }; @@ -246,12 +246,9 @@ impl Generator for CreatePhysicalTableExpr pub struct CreateLogicalTableExprGenerator { physical_table_ctx: TableContextRef, labels: usize, - #[builder(default = "false")] if_not_exists: bool, #[builder(default = "Box::new(WordGenerator)")] name_generator: Box>, - #[builder(default = "Box::new(StringColumnTypeGenerator)")] - label_column_type_generator: ConcreteDataTypeGenerator, } impl Generator for CreateLogicalTableExprGenerator { @@ -288,8 +285,8 @@ impl Generator 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| { @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tests-fuzz/src/ir.rs b/tests-fuzz/src/ir.rs index 317945b2891b..8bb55311dad1 100644 --- a/tests-fuzz/src/ir.rs +++ b/tests-fuzz/src/ir.rs @@ -64,7 +64,7 @@ lazy_static! { ConcreteDataType::datetime_datatype(), ]; pub static ref STRING_DATA_TYPES: Vec = - vec![ConcreteDataType::string_datatype(),]; + vec![ConcreteDataType::string_datatype()]; } impl_random!(ConcreteDataType, ColumnTypeGenerator, DATA_TYPES); @@ -326,7 +326,7 @@ pub fn ts_column_options_generator( vec![ColumnOption::TimeIndex] } -pub fn primary_key_column_options_generator( +pub fn primary_key_and_not_null_column_options_generator( _: &mut R, _: &ConcreteDataType, ) -> Vec { diff --git a/tests-fuzz/targets/fuzz_create_logical_table.rs b/tests-fuzz/targets/fuzz_create_logical_table.rs index 269285bf5d61..e66ea4518966 100644 --- a/tests-fuzz/targets/fuzz_create_logical_table.rs +++ b/tests-fuzz/targets/fuzz_create_logical_table.rs @@ -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}; @@ -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, @@ -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,