xudong963 commented on code in PR #17088: URL: https://github.com/apache/datafusion/pull/17088#discussion_r2265983998
########## datafusion/expr-common/src/operator.rs: ########## @@ -328,6 +328,55 @@ impl Operator { Operator::Multiply | Operator::Divide | Operator::Modulo => 45, } } + + /// Returns true if the `Expr::BinaryOperator` with this operator + /// is guaranteed to return null if either side is null. + pub fn returns_null_on_null(&self) -> bool { + match self { + Operator::Eq + | Operator::NotEq + | Operator::Lt + | Operator::LtEq + | Operator::Gt + | Operator::GtEq + | Operator::Plus + | Operator::Minus + | Operator::Multiply + | Operator::Divide + | Operator::Modulo + | Operator::RegexMatch + | Operator::RegexIMatch + | Operator::RegexNotMatch + | Operator::RegexNotIMatch + | Operator::LikeMatch + | Operator::ILikeMatch + | Operator::NotLikeMatch + | Operator::NotILikeMatch + | Operator::BitwiseAnd + | Operator::BitwiseOr + | Operator::BitwiseXor + | Operator::BitwiseShiftRight + | Operator::BitwiseShiftLeft + | Operator::AtArrow + | Operator::ArrowAt + | Operator::Arrow + | Operator::LongArrow + | Operator::HashArrow + | Operator::HashLongArrow + | Operator::AtAt + | Operator::IntegerDivide + | Operator::HashMinus + | Operator::AtQuestion + | Operator::Question + | Operator::QuestionAnd + | Operator::QuestionPipe => true, + Operator::Or + | Operator::And + | Operator::IsDistinctFrom + | Operator::IsNotDistinctFrom + | Operator::StringConcat => false, Review Comment: I recommend adding such comments, three-valued boolean logic is alway ignored. ```suggestion // In SQL's three-valued boolean logic (TRUE, FALSE, NULL), these operators do not always return NULL // when either operand is NULL: // - For logical OR: If one side is TRUE, the result is TRUE even if the other side is NULL. // - For logical AND: If one side is FALSE, the result is FALSE even if the other side is NULL. // - For IS DISTINCT FROM / IS NOT DISTINCT FROM: These always return TRUE or FALSE, never NULL, // even if either operand is NULL. // - For string concatenation: Some SQL dialects treat NULL as an empty string, so the result may not be NULL. // Because the result is not guaranteed to be NULL when either side is NULL, these operators return false here. Operator::Or | Operator::And | Operator::IsDistinctFrom | Operator::IsNotDistinctFrom | Operator::StringConcat => false, ``` -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org