Skip to content

Commit

Permalink
fix(sqlsmith): generate typed null (#7679)
Browse files Browse the repository at this point in the history
Approved-By: fuyufjh
  • Loading branch information
kwannoel authored Feb 3, 2023
1 parent 50bd487 commit 496f7a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/tests/sqlsmith/src/sql_gen/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,13 @@ fn make_bin_op(func: ExprType, exprs: &[Expr]) -> Option<Expr> {
})
}

pub(crate) fn typed_null(ty: &DataType) -> Expr {
Expr::Cast {
expr: Box::new(sql_null()),
data_type: data_type_to_ast_data_type(ty),
}
}

/// Generates a `NULL` value.
pub(crate) fn sql_null() -> Expr {
Expr::Value(Value::Null)
Expand Down
10 changes: 3 additions & 7 deletions src/tests/sqlsmith/src/sql_gen/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use rand::Rng;
use risingwave_common::types::DataType;
use risingwave_sqlparser::ast::{DataType as AstDataType, Expr, Value};

use crate::sql_gen::expr::sql_null;
use crate::sql_gen::types::data_type_to_ast_data_type;
use crate::sql_gen::expr::typed_null;
use crate::sql_gen::SqlGenerator;

impl<'a, R: Rng> SqlGenerator<'a, R> {
Expand All @@ -35,10 +34,7 @@ impl<'a, R: Rng> SqlGenerator<'a, R> {
// NOTE(kwannoel): We generate Cast with NULL to avoid generating lots of ambiguous
// expressions. For instance agg calls such as `max(NULL)` may be generated,
// and coerced to VARCHAR, where we require a `NULL::int` instead.
return Expr::Cast {
expr: Box::new(sql_null()),
data_type: data_type_to_ast_data_type(typ),
};
return typed_null(typ);
}
// Scalars which may generate negative numbers are wrapped in
// `Nested` to ambiguity while parsing.
Expand Down Expand Up @@ -103,7 +99,7 @@ impl<'a, R: Rng> SqlGenerator<'a, R> {
// .map(|typ| self.gen_simple_scalar(typ))
// .collect(),
// ),
_ => sql_null(),
_ => typed_null(typ),
}
}

Expand Down

0 comments on commit 496f7a9

Please sign in to comment.