From 0aa9f7ed7fe8af6ea19015b9d8bf271a128d4bee Mon Sep 17 00:00:00 2001 From: Noel Kwan <47273164+kwannoel@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:13:01 +0800 Subject: [PATCH] fix(sqlsmith): fix generation of decode (#12855) --- src/tests/sqlsmith/src/sql_gen/functions.rs | 11 +++++++++++ src/tests/sqlsmith/src/sql_gen/types.rs | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/tests/sqlsmith/src/sql_gen/functions.rs b/src/tests/sqlsmith/src/sql_gen/functions.rs index 3583b820f1204..01cbb0604d262 100644 --- a/src/tests/sqlsmith/src/sql_gen/functions.rs +++ b/src/tests/sqlsmith/src/sql_gen/functions.rs @@ -49,6 +49,7 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { 4 => self.gen_overlay(context), _ => unreachable!(), }, + T::Bytea => self.gen_decode(context), _ => match self.rng.gen_bool(0.5) { true => self.gen_case(ret, context), false => self.gen_coalesce(ret, context), @@ -121,6 +122,16 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { .collect() } + fn gen_decode(&mut self, context: SqlGeneratorContext) -> Expr { + let input_string = self.gen_expr(&DataType::Varchar, context); + let encoding = &["base64", "hex", "escape"].choose(&mut self.rng).unwrap(); + let args = vec![ + input_string, + Expr::Value(Value::SingleQuotedString(encoding.to_string())), + ]; + Expr::Function(make_simple_func("decode", &args)) + } + fn gen_fixed_func(&mut self, ret: &DataType, context: SqlGeneratorContext) -> Expr { let funcs = match FUNC_TABLE.get(ret) { None => return self.gen_simple_scalar(ret), diff --git a/src/tests/sqlsmith/src/sql_gen/types.rs b/src/tests/sqlsmith/src/sql_gen/types.rs index ea3c00e45e1da..06d170e604ace 100644 --- a/src/tests/sqlsmith/src/sql_gen/types.rs +++ b/src/tests/sqlsmith/src/sql_gen/types.rs @@ -109,7 +109,10 @@ impl TryFrom for CastSig { /// effectiveness, e.g. cause it to crash. static FUNC_BAN_LIST: LazyLock> = LazyLock::new(|| { [ - ExprType::Repeat, // FIXME: https://github.com/risingwavelabs/risingwave/issues/8003 + // FIXME: https://github.com/risingwavelabs/risingwave/issues/8003 + ExprType::Repeat, + // The format argument needs to be handled specially. It is still generated in `gen_special_func`. + ExprType::Decode, ] .into_iter() .collect() @@ -117,6 +120,9 @@ static FUNC_BAN_LIST: LazyLock> = LazyLock::new(|| { /// Table which maps functions' return types to possible function signatures. // ENABLE: https://github.com/risingwavelabs/risingwave/issues/5826 +// TODO: Create a `SPECIAL_FUNC` table. +// Otherwise when we dump the function table, we won't include those functions in +// gen_special_func. pub(crate) static FUNC_TABLE: LazyLock>> = LazyLock::new(|| { let mut funcs = HashMap::>::new();