pepijnve commented on code in PR #17813:
URL: https://github.com/apache/datafusion/pull/17813#discussion_r2388672062
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -830,6 +883,150 @@ mod tests {
assert!(expr.nullable(&get_schema(false)).unwrap());
}
+ fn check_nullability(
+ expr: Expr,
+ nullable: bool,
+ get_schema: fn(bool) -> MockExprSchema,
+ ) -> Result<()> {
+ assert_eq!(
+ expr.nullable(&get_schema(true))?,
+ nullable,
+ "Nullability of '{expr}' should be {nullable} when column is
nullable"
+ );
+ assert!(
+ !expr.nullable(&get_schema(false))?,
+ "Nullability of '{expr}' should be false when column is not
nullable"
+ );
+ Ok(())
+ }
+
+ #[test]
+ fn test_case_expression_nullability() -> Result<()> {
+ let get_schema = |nullable| {
+ MockExprSchema::new()
+ .with_data_type(DataType::Int32)
+ .with_nullable(nullable)
+ };
+
+ check_nullability(
+ when(is_not_null(col("foo")), col("foo")).otherwise(lit(0))?,
+ false,
+ get_schema,
+ )?;
+
+ check_nullability(
+ when(not(is_null(col("foo"))), col("foo")).otherwise(lit(0))?,
+ false,
+ get_schema,
+ )?;
+
+ check_nullability(
+ when(binary_expr(col("foo"), Operator::Eq, lit(5)), col("foo"))
+ .otherwise(lit(0))?,
Review Comment:
I ended up sticking with prefix notation for the boolean combinators and
infix for the rest. Using infix for the boolean made it hard to read. I've also
added the SQL equivalent as a comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]