Skip to content

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

Description

@Curricane

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions