-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
I want to be able to use null constants in my datafusion queries (e.g. NULL < 5). While at first this seems a silly usecase, we end up with such predicates during automated rewrites in IOx (where sometimes we replace column references with null constants -- See more details on https://github.com/influxdata/influxdb_iox/issues/883)
While they are allowed in the SQL or expr language (e.g. Expr::Literal(ScalarValue::Utf8(None))) they typically generate some runtime error before execution
Describe the solution you'd like
I want to be able to write expressions like NULL < 5 in all cases where I could write col < 5 and have DataFusion evaluate to the correct thing.
The proper fix for this ticket is likely first class support for DataType::Null and then proper coercion logic in the codebase as required. See the discussion by @Dandandan and @jimexist on #1179 at #1179 (comment)
Task List
- Support casting to/from
DataType::Null/NullArrayand other types arrow-rs#876 - Comparisons (BinaryExprs) to literal NULL don't work #1179
- Function calls with NULL literals do not work #1188
- CASE expr with NULL literals panics
'WHEN expression did not return a BooleanArray'#1189 -
not()with NULL literals does not work: can't be evaluated because the expression's type is Utf8, not boolean #1191 -
-(negation) with NULL literals does not work: can't be evaluated because the expression's type is Utf8, not signed #1192 -
betweenwith NULL literals does not work: can't be evaluated because there isn't a common type to coerce the types to #1193 - window functions with NULL literals in
partition byandorder bydo not work: Internal("Sort operation is not applicable to scalar value NULL") #1194 - ORDER BY does not work with literals: Sort operation is not applicable to scalar value 'foo' #1195
Additional context
This is a tracking ticket for a variety of null incorrectness issues I found while working on #1179