apache / apache/datafusion

Create UNION plan node with correct schema

Open
#14,380 18 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Is your feature request related to a problem or challenge?

When building a query plan `union()` behavior doesn't type-coerce the expressions and it [takes the left node's schema](https://github.com/apache/datafusion/blob/4fd460d7a2d2b60e6f9dc716148d8596d94d048c/datafusion/expr/src/logical_plan/builder.rs#L1346-L1352).
This creates an invalid plan which later needs to be fixed. It would be better to create a valid plan from the start.

Note: https://github.com/apache/datafusion/pull/14356 moves the code around, but doesn't change the behavior. See @alamb's https://github.com/apache/datafusion/pull/14356#discussion_r1936081492

### Describe the solution you'd like

Create correctly coerced plan if possible

### Describe alternatives you've considered

Keep creating incorrect plan. Rely on some later logic to fix it some time later.

### Additional context

- see @wiedld's https://github.com/apache/datafusion/pull/12142#discussion_r1730651101
- see @alamb's https://github.com/apache/datafusion/pull/14356#discussion_r1936085994
- https://github.com/apache/datafusion/issues/14363 talks about similar problem, but for JOIN. It's better to be able to create a valid plan.

Contributor guide

Open the contributing guide

Research direction

Start with the UNION-related code in datafusion/expr/src/logical_plan/builder.rs, including the referenced discussion and related JOIN issue. Determine how UNION expressions should be coerced and how the resulting schema should be established; done means the builder creates a valid plan with the correctly coerced schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.