Skip to content
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

create view with multi union use the first union schema as the final view schema #14132

Closed
Curricane opened this issue Jan 15, 2025 · 1 comment · Fixed by #14133
Closed

create view with multi union use the first union schema as the final view schema #14132

Curricane opened this issue Jan 15, 2025 · 1 comment · Fixed by #14133
Labels
bug Something isn't working

Comments

@Curricane
Copy link
Contributor

Describe the bug

create view with multi union use the first union schema as the final view schema. eg:
use the latest datafusion-cli

CREATE UNBOUNDED EXTERNAL TABLE test1 (
    id  INT NOT NULL,
    id1  INT NOT NULL,
)
STORED AS CSV
LOCATION '/home/cc/demo1.csv';

CREATE UNBOUNDED EXTERNAL TABLE test2 (
    id  INT NOT NULL,
    id1  INT,
)
STORED AS CSV
LOCATION '/home/cc/demo2.csv';

CREATE VIEW adv_001
AS 
SELECT id, id1 from test1
UNION ALL
SELECT id, id1 from test2;

CREATE VIEW adv_002
AS 
SELECT id, id1 from test2
UNION ALL
SELECT id, id1 from test1;

when describe adv_001 and adv_002,get different result

> describe adv_001;
+-------------+-----------+-------------+
| column_name | data_type | is_nullable |
+-------------+-----------+-------------+
| id          | Int32     | NO          |
| id1         | Int32     | NO          |
+-------------+-----------+-------------+
2 row(s) fetched.
Elapsed 0.002 seconds.

> describe adv_002;
+-------------+-----------+-------------+
| column_name | data_type | is_nullable |
+-------------+-----------+-------------+
| id          | Int32     | NO          |
| id1         | Int32     | YES         |
+-------------+-----------+-------------+
2 row(s) fetched.
Elapsed 0.002 seconds

In other words, if there are multiple UNION when creating a view, the schema of multiple UNIONs will not be processed, such as TypeCoercion

To Reproduce

see describe

Expected behavior

if there are multiple UNION when creating a view, the schema of multiple UNIONs should be processed, such as TypeCoercion

Additional context

I will fix it.

@Curricane Curricane added the bug Something isn't working label Jan 15, 2025
Curricane pushed a commit to Curricane/datafusion that referenced this issue Jan 15, 2025
create view with analyzer rule of TypeCoercion
@matthewmturner
Copy link
Contributor

@xudong963 this sounds similar to the issue we saw?

Curricane pushed a commit to Curricane/datafusion that referenced this issue Jan 16, 2025
create view with analyzer rule of TypeCoercion
jonahgao pushed a commit that referenced this issue Jan 16, 2025
…14133)

create view with analyzer rule of TypeCoercion

Co-authored-by: chenmch <chenmch@diit.cn>
alamb pushed a commit that referenced this issue Jan 16, 2025
* bugfix: create view with multi union may get wrong schema (#14132)

create view with analyzer rule of TypeCoercion

* test: Add tests for PR #14133 (create view with multi unions)

---------

Co-authored-by: chenmch <chenmch@diit.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants