samuelcolvin opened a new issue, #11306:
URL: https://github.com/apache/datafusion/issues/11306

   ### Describe the bug
   
   Aliases are not allowed as filter predicates.
   
   As per 
https://github.com/datafusion-contrib/datafusion-functions-json/pull/26#discussion_r1664566127
 @alamb suggested we work around change of alias when substituting functions to 
replace operators by using `Expr::Alias`.
   
   However when substituting `foo ? 'bar'` with a function wrapped in an alias, 
we get an error
   
   ```
   Plan("Attempted to create Filter predicate with expression 
`json_contains(test.json_data, Utf8(\"foo\"))` aliased as 'json_data ? 
Utf8(\"foo\")'. Filter predicates should not be aliased.")
   ```
   
   This is caused by
   
   
https://github.com/apache/datafusion/blob/08c5345e932f1c5c948751e0d06b1fd99e174efa/datafusion/expr/src/logical_plan/plan.rs#L2133-L2140
   
   Ref #3796 & #3795
   
   This seems unnecessarily strict.
   
   The problem is that I when replacing the operator, you don't know what part 
of the query the operator is used in, so you can't decide whether or not to 
apply the alias AFAIK.
   
   ### To Reproduce
   
   Add the following test to 
https://github.com/datafusion-contrib/datafusion-functions-json/pull/26
   
   ```
   
   #[tokio::test]
   async fn test_question_filter() {
       let batches = run_query("select name from test where json_data ? 'foo'")
           .await
           .unwrap();
   
       let expected = [
           "+------------+",
           "| name       |",
           "+------------+",
           "| object_foo |",
           "+------------+",
       ];
       assert_batches_eq!(expected, &batches);
   }
   ```
   
   ### Expected behavior
   
   I think aliases as predicates should be allowed.
   
   ### Additional context
   
   _No response_


-- 
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]

Reply via email to