-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Don't preserve functional dependency when generating UNION logical plan #12979
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,8 +49,8 @@ use datafusion_common::display::ToStringifiedPlan; | |
| use datafusion_common::file_options::file_type::FileType; | ||
| use datafusion_common::{ | ||
| get_target_functional_dependencies, internal_err, not_impl_err, plan_datafusion_err, | ||
| plan_err, Column, DFSchema, DFSchemaRef, DataFusionError, Result, ScalarValue, | ||
| TableReference, ToDFSchema, UnnestOptions, | ||
| plan_err, Column, DFSchema, DFSchemaRef, DataFusionError, FunctionalDependencies, | ||
| Result, ScalarValue, TableReference, ToDFSchema, UnnestOptions, | ||
| }; | ||
| use datafusion_expr_common::type_coercion::binary::type_union_resolution; | ||
|
|
||
|
|
@@ -1402,7 +1402,12 @@ pub fn validate_unique_names<'a>( | |
| pub fn union(left_plan: LogicalPlan, right_plan: LogicalPlan) -> Result<LogicalPlan> { | ||
| // Temporarily use the schema from the left input and later rely on the analyzer to | ||
| // coerce the two schemas into a common one. | ||
| let schema = Arc::clone(left_plan.schema()); | ||
|
|
||
| // Functional Dependencies doesn't preserve after UNION operation | ||
| let schema = (**left_plan.schema()).clone(); | ||
| let schema = | ||
| Arc::new(schema.with_functional_dependencies(FunctionalDependencies::empty())?); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is clearing out all dependencies the right fix? Could we retain some if they do not harm?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll wait to merge this PR until tomorrow to give @Sevenannn a chance to respond
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @berkaysynnada, thanks for the review! I don’t think any FD persists when performing UNION on 2 tables. A simple example would be UNION table t1 with another table t2 which only has 1 row, there always exists such data in t2 which could break the FDs in t1 / t2 after the UNION. In this case, clearing FDs would be the right fix since we don’t want FDs to get wrongly retained and affect later plans, e.g. aggregation. Please let me know if you have any further questions regarding this PR, thanks! |
||
| Ok(LogicalPlan::Union(Union { | ||
| inputs: vec![Arc::new(left_plan), Arc::new(right_plan)], | ||
| schema, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.