Describe the bug
Aliases are not allowed as filter predicates.
As per datafusion-contrib/datafusion-functions-json#26 (comment) @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
|
// filter predicates should not be aliased |
|
if let Expr::Alias(Alias { expr, name, .. }) = predicate { |
|
return plan_err!( |
|
"Attempted to create Filter predicate with \ |
|
expression `{expr}` aliased as '{name}'. Filter predicates should not be \ |
|
aliased." |
|
); |
|
} |
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 datafusion-contrib/datafusion-functions-json#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
Describe the bug
Aliases are not allowed as filter predicates.
As per datafusion-contrib/datafusion-functions-json#26 (comment) @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 errorThis is caused by
datafusion/datafusion/expr/src/logical_plan/plan.rs
Lines 2133 to 2140 in 08c5345
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 datafusion-contrib/datafusion-functions-json#26
Expected behavior
I think aliases as predicates should be allowed.
Additional context
No response