Repository navigation
Closed
Labels
unexpected behaviourResult is unexpected, but not entirely wrong at the same time.
Description
You have to provide the following information whenever possible.
The is an error when using a union and combining nullable and non-nullable fields.
A clear and concise description of what works not as it is supposed to.
Here's the distilled query that fails:
-- create the table
create database broken_view;
create table broken_view.table1
(
start DateTime64(6),
end DateTime64(6),
)
ENGINE = ReplacingMergeTree(start)
order by (start);
-- create the view
CREATE or replace VIEW broken_view.broken as
select
t.start as start,
t.end as end,
cast(datediff('second', t.start, t.end) as float) as total_sec
from broken_view.table1 t final
union all
select
null as start,
null as end,
null as total_sec;
-- do a select
select
v.start,
v.total_sec
from
broken_view.broken v final
where
v.start is not null;A link to reproducer in https://fiddle.clickhouse.com/.
Does it reproduce on recent release?
Yes
Enable crash reporting
No crash with ClickHouse
How to reproduce
- Which ClickHouse server version to use - 23.9.x
See above for the playground & queries
Expected behavior
This should not return the error mentioned
Error message and/or stacktrace
Received exception from server (version 23.9.1):
Code: 352. DB::Exception: Received from localhost:9000. DB::Exception: Block structure mismatch in (columns with identical name must have identical structure) stream: different types:
start DateTime64(6) DateTime64(size = 0)
start Nullable(DateTime64(6)) Nullable(size = 0, DateTime64(size = 0), UInt8(size = 0)). (AMBIGUOUS_COLUMN_NAME)
(query: -- do a select
select
v.start,
v.total_sec
from
broken_view.broken v final
where
v.start is not null;)
Additional context
We have a view that uses unions over multiple tables. Some tables provide a value for the column, others do not
Metadata
Metadata
Assignees
Labels
unexpected behaviourResult is unexpected, but not entirely wrong at the same time.
Activity
colmanhumphrey commentedon Oct 19, 2023
Note that if you change the final WHERE clause to
v.end is not null, it works fine: https://fiddle.clickhouse.com/eeda2c81-1f04-499d-9019-fb95e623a33b.You can also change it to
v.total_sec is not nulland it works (but if you replacev.startwithv.endin the SELECT and also the WHERE, then it's back to broken).The working cases make sense according to the docs:
But yeah, not clear to us yet why the base case fails
den-crane commentedon Oct 19, 2023
It's known issue. You can name columns differently, not
t.start as startbutt.start as start_https://fiddle.clickhouse.com/a7d33161-b129-4bd4-8c73-49d80e517ac4
den-crane commentedon Oct 19, 2023
does not work with analyzer as well https://fiddle.clickhouse.com/e86c8fe3-61e7-419c-872f-010660f1d35a
Fallenyasha commentedon Dec 8, 2023
More easy way to reproduce:
select 0, 0
union all
select cast(0 as Int16), cast(0 as Int32)
Code: 352. DB::Exception: Block structure mismatch in (columns with identical name must have identical structure) stream: different types: 0 Int16 Int16(size = 0) 0 Int32 Int32(size = 0). (AMBIGUOUS_COLUMN_NAME) (version 23.11.1.2711 (official build))
ClickHouse version 23.11.1.2711
Close #55803