Skip to content

Commit

Permalink
fix(sqlsmith): fix generation of decode (#12855)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwannoel authored Oct 16, 2023
1 parent f8de4a9 commit 0aa9f7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/tests/sqlsmith/src/sql_gen/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 7 additions & 1 deletion src/tests/sqlsmith/src/sql_gen/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,20 @@ impl TryFrom<RwCastSig> for CastSig {
/// effectiveness, e.g. cause it to crash.
static FUNC_BAN_LIST: LazyLock<HashSet<ExprType>> = 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()
});

/// 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<HashMap<DataType, Vec<&'static FuncSign>>> =
LazyLock::new(|| {
let mut funcs = HashMap::<DataType, Vec<&'static FuncSign>>::new();
Expand Down

0 comments on commit 0aa9f7e

Please sign in to comment.