Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use datafusion_expr::type_coercion::other::{
use datafusion_expr::type_coercion::{is_datetime, is_utf8_or_large_utf8};
use datafusion_expr::utils::merge_schema;
use datafusion_expr::{
is_false, is_not_false, is_not_true, is_not_unknown, is_true, is_unknown,
is_false, is_not_false, is_not_true, is_not_unknown, is_true, is_unknown, not,
type_coercion, AggregateFunction, BuiltinScalarFunction, Expr, ExprSchemable,
LogicalPlan, Operator, Projection, ScalarFunctionDefinition, Signature, WindowFrame,
WindowFrameBound, WindowFrameUnits,
Expand Down Expand Up @@ -176,6 +176,10 @@ impl TreeNodeRewriter for TypeCoercionRewriter {
negated,
)))
}
Expr::Not(expr) => {
let expr = not(get_casted_expr_for_bool_op(&expr, &self.schema)?);
Ok(expr)
}
Expr::IsTrue(expr) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to remove the catch all from this match expression

https://github.com/apache/arrow-datafusion/blob/bc0ba6a724aaaf312b770451718cbce696de6640/datafusion/optimizer/src/analyzer/type_coercion.rs#L413

And explicitly list out all Expr types so that we don't accidentally another Expr type in the future

Is that something you might be willing to do in another PR @guojidan ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will do soon

let expr = is_true(get_casted_expr_for_bool_op(&expr, &self.schema)?);
Ok(expr)
Expand Down
11 changes: 1 addition & 10 deletions datafusion/physical-expr/src/expressions/not.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ use crate::physical_expr::down_cast_any_ref;
use crate::PhysicalExpr;
use arrow::datatypes::{DataType, Schema};
use arrow::record_batch::RecordBatch;
use datafusion_common::{
cast::as_boolean_array, internal_err, DataFusionError, Result, ScalarValue,
};
use datafusion_common::{cast::as_boolean_array, Result, ScalarValue};
use datafusion_expr::ColumnarValue;

/// Not expression
Expand Down Expand Up @@ -83,13 +81,6 @@ impl PhysicalExpr for NotExpr {
if scalar.is_null() {
return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
}
let value_type = scalar.data_type();
if value_type != DataType::Boolean {
return internal_err!(
"NOT '{:?}' can't be evaluated because the expression's type is {:?}, not boolean or NULL",
self.arg, value_type
);
}
let bool_value: bool = scalar.try_into()?;
Ok(ColumnarValue::Scalar(ScalarValue::Boolean(Some(
!bool_value,
Expand Down
4 changes: 2 additions & 2 deletions datafusion/sqllogictest/test_files/scalar.slt
Original file line number Diff line number Diff line change
Expand Up @@ -1527,15 +1527,15 @@ SELECT not(true), not(false)
----
false true

query error
query error type_coercion\ncaused by\nError during planning: Cannot infer common argument type for comparison operation Int64 IS DISTINCT FROM Boolean
SELECT not(1), not(0)

query ?B
SELECT null, not(null)
----
NULL NULL

query error
query error type_coercion\ncaused by\nError during planning: Cannot infer common argument type for comparison operation Utf8 IS DISTINCT FROM Boolean
SELECT NOT('hi')

# test_negative_expressions()
Expand Down