-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datafusion 42 does not raise plan error when UNION branches have different number of columns #13092
Comments
I think this is related to #11961 |
I think SQL requires the inputs to have the same number of columns Here is an example in postgres postgres=# create table foo (x int, y int) ;
CREATE TABLE
postgres=# insert into foo values (1, 1), (1, 2);
INSERT 0 2
postgres=# select x from foo UNION ALL select y, y FROM foo;
ERROR: each UNION query must have the same number of columns
LINE 1: select x from foo UNION ALL select y, y FROM foo;
^
postgres=# select x FROM foo UNION ALL select x, y FROM foo; Perhaps you can get equivalent behavior in DataFusion 42 using a null constant SELECT "Product" FROM "my_table" UNION ALL SELECT "Product", "Id" FROM "my_table" to SELECT "Product", NULL FROM "my_table" UNION ALL SELECT "Product", "Id" FROM "my_table" |
I think the author's concern is not that the sql is invalid, it's that it's not being detected as invalid as early as it used to be. Is that a correct summation @emanueledomingo ? |
Ah, sorry -- that is my mistake |
I think we can check if the number of columns is the same when building Unions, as it is a common scenario and does not depend on wildcard expansion and type coercion. pub fn union(left_plan: LogicalPlan, right_plan: LogicalPlan) -> Result<LogicalPlan> {
if left_plan.schema().fields().len() != right_plan.schema().fields().len() {
return plan_err!(
"UNION queries have different number of columns: \
left has {} columns whereas right has {} columns",
left_plan.schema().fields().len(),
right_plan.schema().fields().len()
);
} |
Yes exactly. I realised it because i have a set of unit tests to test a function that handles errors and one of them failed. Not a real bug to me, i just want to report that this behaviour changed! |
take |
#11961 is probably related, at least "Union queries must have the same number of columns" error changed there. @emanueledomingo if this is about UNIONs, can we change the issue title to "Datafusion 42 does not raise plan error when UNION branches have different number of columns"?, or is there more to it? |
I experienced this bug only with this kind of query. i have 5 wrong queries in the unit test and only this gave this error |
Describe the bug
Since datafusion 41, i got Datafusion Error when some SQL queries contain errors.
raises
With new datafusion version, this doesn't happens anymore (it crashes later, when i run
.collect()
after the .sql() result)To Reproduce
Expected behavior
DataFusion error exception correctly raised
Additional context
No response
The text was updated successfully, but these errors were encountered: