ClickHouse icon indicating copy to clipboard operation
ClickHouse copied to clipboard

map inside if statement with default empty map value fails when accessed through distributed table

Open tanner-bruce opened this issue 9 months ago • 1 comments

clickhouse version: 24.4.1.2088

Using if(..., some_map, map()) appears to fail with allow_experimental_analyzer=1 when queried through a distributed table.

our setup:

create table:

    `resource_attributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)),
-- Query through distributed table, analyzer on

SELECT if(1, resource_attributes, map())
FROM tracing.otel_traces
LIMIT 1
FORMAT `Null`
SETTINGS allow_experimental_analyzer = 1

Received exception from server (version 24.4.1):
Code: 10. DB::Exception: Received from localhost:9000. DB::Exception: Not found column if(1_UInt8, __table1.resource_attributes, _CAST([]_Map(Nothing, Nothing), 'Map(Nothing, Nothing)'_String)) in block. There are only columns: __table1.resource_attributes: While executing Remote. (NOT_FOUND_COLUMN_IN_BLOCK)


-- Query through distributed table, analyzer off
SELECT if(1, resource_attributes, map())
FROM tracing.otel_traces
LIMIT 1
FORMAT `Null`
SETTINGS allow_experimental_analyzer = 0

Ok.

0 rows in set. Elapsed: 0.833 sec.


-- Query through local table, analyzer on
SELECT if(1, resource_attributes, map())
FROM tracing.otel_traces_local
LIMIT 1
SETTINGS allow_experimental_analyzer = 1

Query id: e209cf69-2621-476a-8b25-c1e5ed1f5e78

Ok.

0 rows in set. Elapsed: 0.001 sec.

This should reproduce it from what I am seeing:

CREATE TABLE default.bug_repro_local
(
    `id` String CODEC(ZSTD(1)),
    `attributes` Map(LowCardinality(String), String) CODEC(ZSTD(1))
)
ENGINE = MergeTree
ORDER BY (id);

CREATE TABLE default.bug_repro
(
    `id` String CODEC(ZSTD(1)),
    `attributes` Map(LowCardinality(String), String) CODEC(ZSTD(1))
)
ENGINE = Distributed('all-shards', 'default', 'bug_repro_local', rand());

SELECT if(1, attributes, map()) from default.bug_repro limit 1 SETTINGS allow_experimental_analyzer=1;
SELECT if(1, attributes, map()) from default.bug_repro limit 1 SETTINGS allow_experimental_analyzer=0;
SELECT if(1, attributes, map()) from default.bug_repro_local limit 1 SETTINGS allow_experimental_analyzer=1;

tanner-bruce avatar May 10 '24 19:05 tanner-bruce

SELECT map() 
from remote('127.0.0.{1,2}', system,one)
SETTINGS allow_experimental_analyzer=0
{}
{}


SELECT map() 
from remote('127.0.0.{1,2}', system,one)
SETTINGS allow_experimental_analyzer=1

DB::Exception: CAST AS Map from array requires nested tuple of 2 elements.

https://fiddle.clickhouse.com/535fe5c1-b10a-465d-bb27-0146058c6a5d

CREATE TABLE bug_repro_local
(
    `attributes` Map(LowCardinality(String), String)
)
ENGINE = Memory as select map('','');

SELECT if(1, attributes, map()) 
from remote('127.0.0.{1,2}', default,bug_repro_local)
limit 1 SETTINGS allow_experimental_analyzer=0
format Pretty;

   +------------+
   | attributes |
   +------------+
1. | {'':''}    |
   +------------+


SELECT if(1, attributes, map()) 
from remote('127.0.0.{1,2}', default,bug_repro_local)
limit 1 SETTINGS allow_experimental_analyzer=1
format Pretty;

DB::Exception: Not found column if(1_UInt8, __table1.attributes,

https://fiddle.clickhouse.com/160b5196-2915-4f60-95ba-a9a85e05044e

den-crane avatar May 10 '24 20:05 den-crane