Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable fuzz test for append table #4702

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tests-fuzz/src/generator/create_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,20 @@ pub struct CreatePhysicalTableExprGenerator<R: Rng + 'static> {
name_generator: Box<dyn Random<Ident, R>>,
#[builder(default = "false")]
if_not_exists: bool,
#[builder(default, setter(into))]
with_clause: HashMap<String, String>,
}

impl<R: Rng + 'static> Generator<CreateTableExpr, R> for CreatePhysicalTableExprGenerator<R> {
type Error = Error;

fn generate(&self, rng: &mut R) -> Result<CreateTableExpr> {
let mut options = HashMap::with_capacity(self.with_clause.len() + 1);
options.insert("physical_metric_table".to_string(), Value::from(""));
for (key, value) in &self.with_clause {
options.insert(key.to_string(), Value::from(value.to_string()));
}

Ok(CreateTableExpr {
table_name: self.name_generator.gen(rng),
columns: vec![
Expand All @@ -266,7 +274,7 @@ impl<R: Rng + 'static> Generator<CreateTableExpr, R> for CreatePhysicalTableExpr
if_not_exists: self.if_not_exists,
partition: None,
engine: "metric".to_string(),
options: [("physical_metric_table".to_string(), "".into())].into(),
options,
primary_keys: vec![],
})
}
Expand Down
2 changes: 1 addition & 1 deletion tests-fuzz/src/translator/mysql/create_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl CreateTableExprTranslator {
for (key, value) in &input.options {
output.push(format!("\"{key}\" = \"{value}\""));
}
format!(" with ({})", output.join("\n"))
format!(" with ({})", output.join(",\n"))
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests-fuzz/targets/fuzz_alter_logical_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![no_main]

use std::collections::HashMap;
use std::sync::Arc;

use arbitrary::{Arbitrary, Unstructured};
Expand Down Expand Up @@ -76,12 +77,17 @@ impl Arbitrary<'_> for FuzzInput {

fn generate_create_physical_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTableExpr> {
let physical_table_if_not_exists = rng.gen_bool(0.5);
let mut with_clause = HashMap::new();
if rng.gen_bool(0.5) {
with_clause.insert("append_mode".to_string(), "true".to_string());
}
let create_physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
.name_generator(Box::new(MappedGenerator::new(
WordGenerator,
merge_two_word_map_fn(random_capitalize_map, uppercase_and_keyword_backtick_map),
)))
.if_not_exists(physical_table_if_not_exists)
.with_clause(with_clause)
.build()
.unwrap();
create_physical_table_expr.generate(rng)
Expand Down
6 changes: 6 additions & 0 deletions tests-fuzz/targets/fuzz_alter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![no_main]

use std::collections::HashMap;
use std::sync::Arc;

use arbitrary::{Arbitrary, Unstructured};
Expand Down Expand Up @@ -71,13 +72,18 @@ enum AlterTableOption {
fn generate_create_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTableExpr> {
let max_columns = get_gt_fuzz_input_max_columns();
let columns = rng.gen_range(2..max_columns);
let mut with_clause = HashMap::new();
if rng.gen_bool(0.5) {
with_clause.insert("append_mode".to_string(), "true".to_string());
}
let create_table_generator = CreateTableExprGeneratorBuilder::default()
.name_generator(Box::new(MappedGenerator::new(
WordGenerator,
merge_two_word_map_fn(random_capitalize_map, uppercase_and_keyword_backtick_map),
)))
.columns(columns)
.engine("mito")
.with_clause(with_clause)
.build()
.unwrap();
create_table_generator.generate(rng)
Expand Down
6 changes: 6 additions & 0 deletions tests-fuzz/targets/fuzz_create_logical_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![no_main]

use std::collections::HashMap;
use std::sync::Arc;

use common_telemetry::info;
Expand Down Expand Up @@ -68,12 +69,17 @@ async fn execute_create_logic_table(ctx: FuzzContext, input: FuzzInput) -> Resul

// Create physical table
let physical_table_if_not_exists = rng.gen_bool(0.5);
let mut with_clause = HashMap::new();
if rng.gen_bool(0.5) {
with_clause.insert("append_mode".to_string(), "true".to_string());
}
let create_physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
.name_generator(Box::new(MappedGenerator::new(
WordGenerator,
merge_two_word_map_fn(random_capitalize_map, uppercase_and_keyword_backtick_map),
)))
.if_not_exists(physical_table_if_not_exists)
.with_clause(with_clause)
.build()
.unwrap()
.generate(&mut rng)?;
Expand Down
7 changes: 7 additions & 0 deletions tests-fuzz/targets/fuzz_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#![no_main]

use std::collections::HashMap;

use common_telemetry::info;
use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured};
use libfuzzer_sys::fuzz_target;
Expand Down Expand Up @@ -65,6 +67,10 @@ impl Arbitrary<'_> for FuzzInput {
fn generate_expr(input: FuzzInput) -> Result<CreateTableExpr> {
let mut rng = ChaChaRng::seed_from_u64(input.seed);
let if_not_exists = rng.gen_bool(0.5);
let mut with_clause = HashMap::new();
if rng.gen_bool(0.5) {
with_clause.insert("append_mode".to_string(), "true".to_string());
}

let create_table_generator = CreateTableExprGeneratorBuilder::default()
.name_generator(Box::new(MappedGenerator::new(
Expand All @@ -74,6 +80,7 @@ fn generate_expr(input: FuzzInput) -> Result<CreateTableExpr> {
.columns(input.columns)
.engine("mito")
.if_not_exists(if_not_exists)
.with_clause(with_clause)
.build()
.unwrap();
create_table_generator.generate(&mut rng)
Expand Down
7 changes: 7 additions & 0 deletions tests-fuzz/targets/fuzz_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![no_main]

use std::collections::HashMap;
use std::sync::Arc;

use common_telemetry::info;
Expand Down Expand Up @@ -83,13 +84,19 @@ fn generate_create_expr<R: Rng + 'static>(
input: FuzzInput,
rng: &mut R,
) -> Result<CreateTableExpr> {
let mut with_clause = HashMap::new();
if rng.gen_bool(0.5) {
with_clause.insert("append_mode".to_string(), "true".to_string());
}

let create_table_generator = CreateTableExprGeneratorBuilder::default()
.name_generator(Box::new(MappedGenerator::new(
WordGenerator,
merge_two_word_map_fn(random_capitalize_map, uppercase_and_keyword_backtick_map),
)))
.columns(input.columns)
.engine("mito")
.with_clause(with_clause)
.ts_column_type_generator(Box::new(MySQLTsColumnTypeGenerator))
.build()
.unwrap();
Expand Down
5 changes: 5 additions & 0 deletions tests-fuzz/targets/fuzz_insert_logical_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,17 @@ impl Arbitrary<'_> for FuzzInput {

fn generate_create_physical_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTableExpr> {
let physical_table_if_not_exists = rng.gen_bool(0.5);
let mut with_clause = HashMap::new();
if rng.gen_bool(0.5) {
with_clause.insert("append_mode".to_string(), "true".to_string());
}
let create_physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
.name_generator(Box::new(MappedGenerator::new(
WordGenerator,
merge_two_word_map_fn(random_capitalize_map, uppercase_and_keyword_backtick_map),
)))
.if_not_exists(physical_table_if_not_exists)
.with_clause(with_clause)
.build()
.unwrap();
create_physical_table_expr.generate(rng)
Expand Down