You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression: Invalid comparison operation: Utf8 == Utf8View error during LEFT ANTI JOIN #13510
Apologies for the slow turnaround. Sharing findings from today:
Compiling with latest main DF did NOT fix the issue.
After simulating my ANTI JOIN in datafusion-cli between CSV and Parquet to force view/no-view mismatch I still could not find a smaller repro - will continue digging.
@alamb setting datafusion.execution.parquet.schema_force_view_types = false made the issue go away. Thanks a lot for the suggestion. This will allow us to upgrade to v43 and not fall behind.
Hello! I've dug into this issue a bit and it seems that the problem here arises from the fact that the table name for each table scan in the plan defaults to UNNAMED_TABLE ("?table?").
Because of this, column references in the "on" portion of the join node are ambiguous. In fact, if we dedup the references by either changing column names or qualifying at least one table in the example with an alias, it works because type coercion is able to determine that a cast is necessary. Without this, the data type lookup for the columns during type coercion will yield that associated with the first matched field in the schema (the left-hand side). Thus, there appears to be no cast necessary.
Other join types (e.g. inner) fail earlier in planning with a DuplicateQualifiedField error because they compute the joined schema, performing duplicate name checks as a result. I'm thinking a good path forward here may be to perform this validation for all join types? That way we fail earlier in planning.
Would love some feedback/thoughts! Thanks!
(FYI @alamb I tested #13370 rebased off the latest main and it does not fix the issue. But this is expected based on the description above! 😅 )
Hello! I've dug into this issue a bit and it seems that the problem here arises from the fact that the table name for each table scan in the plan defaults to UNNAMED_TABLE ("?table?").
When I tested this reproducer last, when I disabled datafusion.execution.parquet.schema_force_view_types (set it to false) then the query would run
This suggests to me the problem wasn't related to ambiguous schemas but instead somehow to some type coercion that was/wasn't happening 🤔
I would have thought this code was coerceing the join predicates already:
I looked a bit at this, I think the issue is that the join type coercion is resolving the on clause in terms of the output schema (not hte input schema).
I think this only affects DataFrame with unnamed relations (if the inputs have names things are ok)
I suspect this coercion issue has always been lurking, but it became more of an issue once Utf8View became more common
#[tokio::test]asyncfnjoin_coercion_unnnamed() -> Result<()>{let ctx = SessionContext::new();// Test that join will coerce column types when necessary// even when the relations don't have unique nameslet left = ctx.read_batch(record_batch!(("id",Int32,[1,2,3]),("name",Utf8,["a","b","c"]))?)?;let right = ctx.read_batch(record_batch!(("id",Int32,[10,3]),("name",Utf8View,["d","c"])// Utf8View is a different type)?)?;let cols = vec!["name","id"];let filter = None;let join = right.join(left,JoinType::LeftAnti,&cols,&cols, filter)?;let results = join.collect().await?;assert_batches_sorted_eq!(["+----+----+","| id | id |","+----+----+","| c | c |","+----+----+",],&results
);Ok(())}
This fails with Error: ArrowError(InvalidArgumentError("Invalid comparison operation: Utf8View == Utf8"), None)
Activity
ttencate commentedon Nov 26, 2024
Related to #13568? I filed that as a separate issue, but it seems like they might have the same root cause.
findepi commentedon Nov 26, 2024
@sergiimk are you able to simplify the failing query so that we have the simplest possible reproducer?
sergiimk commentedon Nov 28, 2024
@findepi was slammed this week unfortunately. I will re-test with latest master and try to narrow the issue down this weekend.
alamb commentedon Dec 3, 2024
Does the problem go away if you turn off this config setting:
https://datafusion.apache.org/user-guide/configs.html
datafusion.execution.parquet.schema_force_view_types
We are still working through some additional needed support:
sergiimk commentedon Dec 5, 2024
Apologies for the slow turnaround. Sharing findings from today:
Compiling with latest
mainDF did NOT fix the issue.After simulating my ANTI JOIN in
datafusion-clibetween CSV and Parquet to force view/no-view mismatch I still could not find a smaller repro - will continue digging.@alamb setting
datafusion.execution.parquet.schema_force_view_types = falsemade the issue go away. Thanks a lot for the suggestion. This will allow us to upgrade to v43 and not fall behind.sergiimk commentedon Dec 5, 2024
Phew, finally got the minimal repro:
Utf8columns)Utf8View)LEFT ANTI JOINIncluding the test project with sample data:
datafusion-13510.zip
Still not sure why the same exact scenario didn't break when using
datafusion-cli.Will update the ticket description with the repro.
alamb commentedon Dec 22, 2024
Summary:
datafusion.execution.parquet.schema_force_view_typesconfig to falseThe error comes from arrow-rs (source https://github.com/apache/arrow-rs/blob/2c84f243b882eff69806cd7294d38bf422fdb24a/arrow-ord/src/cmp.rs#L241
Here is the stack of the error:
I suspect what is needed to fix this issue is to insert a coercsion somewhere in DataFusion so the join key is correctly coerced
alamb commentedon Jan 13, 2025
I added this to the list of items that i think we should fix before releasing version 45.0.0:
45.0.0#14008alamb commentedon Jan 28, 2025
I am hoping (🙏 ing?) that this is fixed by
Utf8Viewforget_wider_type+binary_to_string_coercionfunctions #13370 from @jonathanc-nBut we'll have to see
rkrishn7 commentedon Jan 31, 2025
Hello! I've dug into this issue a bit and it seems that the problem here arises from the fact that the table name for each table scan in the plan defaults to
UNNAMED_TABLE("?table?").Because of this, column references in the "on" portion of the join node are ambiguous. In fact, if we dedup the references by either changing column names or qualifying at least one table in the example with an alias, it works because type coercion is able to determine that a cast is necessary. Without this, the data type lookup for the columns during type coercion will yield that associated with the first matched field in the schema (the left-hand side). Thus, there appears to be no cast necessary.
Other join types (e.g. inner) fail earlier in planning with a
DuplicateQualifiedFielderror because they compute the joined schema, performing duplicate name checks as a result. I'm thinking a good path forward here may be to perform this validation for all join types? That way we fail earlier in planning.Would love some feedback/thoughts! Thanks!
(FYI @alamb I tested #13370 rebased off the latest main and it does not fix the issue. But this is expected based on the description above! 😅 )
alamb commentedon Jan 31, 2025
Thank you for the investigation @rkrishn7 🙏
When I tested this reproducer last, when I disabled
datafusion.execution.parquet.schema_force_view_types(set it to false) then the query would runThis suggests to me the problem wasn't related to ambiguous schemas but instead somehow to some type coercion that was/wasn't happening 🤔
I would have thought this code was coerceing the join predicates already:
https://github.com/apache/datafusion/blob/d42b99474691a263c1dd53179e9ad1b481b1e819/datafusion/optimizer/src/analyzer/type_coercion.rs#L193-L192
But clearly something isn't working
alamb commentedon Jan 31, 2025
I looked a bit at this, I think the issue is that the join type coercion is resolving the on clause in terms of the output schema (not hte input schema).
I am working on a smaller reproducer and fix now
alamb commentedon Jan 31, 2025
Here is a self contained reproducer
I think this only affects
DataFramewith unnamed relations (if the inputs have names things are ok)I suspect this coercion issue has always been lurking, but it became more of an issue once
Utf8Viewbecame more commonThis fails with
Error: ArrowError(InvalidArgumentError("Invalid comparison operation: Utf8View == Utf8"), None)alamb commentedon Jan 31, 2025
BTW @rkrishn7 narrowed in on the fact that the inputs are
UNNAMED_TABLEwhich is a key observation. Thank you @rkrishn7 🙏alamb commentedon Jan 31, 2025
Here is a fix:
DataFrameAPI #14387rkrishn7 commentedon Jan 31, 2025
Awesome, thanks @alamb! Your fix makes sense to me 👍🏾