From 58f86723fc45acc26fd460d0db5e3f46656b1c39 Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Tue, 21 May 2024 11:03:49 +0000 Subject: [PATCH] Backport #63753 to 24.3: Allow cast from Array(Nothing) to Map(Nothing, Nothing) --- src/Functions/FunctionsConversion.cpp | 7 +++++++ tests/queries/0_stateless/01787_map_remote.reference | 3 +++ tests/queries/0_stateless/01787_map_remote.sql | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/src/Functions/FunctionsConversion.cpp b/src/Functions/FunctionsConversion.cpp index 7049ca44110..4694f98ad50 100644 --- a/src/Functions/FunctionsConversion.cpp +++ b/src/Functions/FunctionsConversion.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -3762,6 +3763,12 @@ private: } else if (const auto * from_array = typeid_cast(from_type_untyped.get())) { + if (typeid_cast(from_array->getNestedType().get())) + return [nested = to_type->getNestedType()](ColumnsWithTypeAndName &, const DataTypePtr &, const ColumnNullable *, size_t size) + { + return ColumnMap::create(nested->createColumnConstWithDefaultValue(size)->convertToFullColumnIfConst()); + }; + const auto * nested_tuple = typeid_cast(from_array->getNestedType().get()); if (!nested_tuple || nested_tuple->getElements().size() != 2) throw Exception( diff --git a/tests/queries/0_stateless/01787_map_remote.reference b/tests/queries/0_stateless/01787_map_remote.reference index c7828769f9f..c411899c87c 100644 --- a/tests/queries/0_stateless/01787_map_remote.reference +++ b/tests/queries/0_stateless/01787_map_remote.reference @@ -2,3 +2,6 @@ {'a':1,'b':2} {'a':1,'b':2} {'a':1,'b':2} +{} +{} +{'':''} diff --git a/tests/queries/0_stateless/01787_map_remote.sql b/tests/queries/0_stateless/01787_map_remote.sql index 217308e5141..e169ed62781 100644 --- a/tests/queries/0_stateless/01787_map_remote.sql +++ b/tests/queries/0_stateless/01787_map_remote.sql @@ -1,2 +1,8 @@ SELECT map('a', 1, 'b', 2) FROM remote('127.0.0.{1,2}', system, one); SELECT map('a', 1, 'b', 2) FROM remote('127.0.0.{1,2}'); + +SELECT map() from remote('127.0.0.{1,2}', system,one); + +drop table if exists bug_repro_local; +CREATE TABLE bug_repro_local (`attributes` Map(LowCardinality(String), String)) ENGINE = Log as select map('',''); +SELECT if(1, attributes, map()) from remote('127.0.0.{1,2}', currentDatabase(), bug_repro_local) limit 1;