chore: enable fuzz test for append table (#4702)

* chore: enable fuzz test for append table

* fix: fix mysql translator
This commit is contained in:
Weny Xu
2024-09-18 12:01:30 +09:00
committed by GitHub
parent 36b1bafbf0
commit d1dfffcdaf
8 changed files with 47 additions and 2 deletions

View File

@@ -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![
@@ -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![],
})
}

View File

@@ -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"))
}
}
}

View File

@@ -14,6 +14,7 @@
#![no_main]
use std::collections::HashMap;
use std::sync::Arc;
use arbitrary::{Arbitrary, Unstructured};
@@ -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)

View File

@@ -14,6 +14,7 @@
#![no_main]
use std::collections::HashMap;
use std::sync::Arc;
use arbitrary::{Arbitrary, Unstructured};
@@ -71,6 +72,10 @@ 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,
@@ -78,6 +83,7 @@ fn generate_create_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTab
)))
.columns(columns)
.engine("mito")
.with_clause(with_clause)
.build()
.unwrap();
create_table_generator.generate(rng)

View File

@@ -14,6 +14,7 @@
#![no_main]
use std::collections::HashMap;
use std::sync::Arc;
use common_telemetry::info;
@@ -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)?;

View File

@@ -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;
@@ -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(
@@ -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)

View File

@@ -14,6 +14,7 @@
#![no_main]
use std::collections::HashMap;
use std::sync::Arc;
use common_telemetry::info;
@@ -83,6 +84,11 @@ 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,
@@ -90,6 +96,7 @@ fn generate_create_expr<R: Rng + 'static>(
)))
.columns(input.columns)
.engine("mito")
.with_clause(with_clause)
.ts_column_type_generator(Box::new(MySQLTsColumnTypeGenerator))
.build()
.unwrap();

View File

@@ -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)