mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #21699 from CurtizJ/fix-map-field-conversion
Fix conversions for fields in function 'arrayElement' for type Map
This commit is contained in:
commit
2e1f293bd5
@ -872,15 +872,18 @@ bool FunctionArrayElement::matchKeyToIndexNumberConst(
|
||||
if (!data_numeric)
|
||||
return false;
|
||||
|
||||
bool is_integer_field = Field::dispatch([](const auto & value)
|
||||
std::optional<DataType> index_as_integer;
|
||||
Field::dispatch([&](const auto & value)
|
||||
{
|
||||
return is_integer_v<std::decay_t<decltype(value)>>;
|
||||
using FieldType = std::decay_t<decltype(value)>;
|
||||
if constexpr (is_integer_v<FieldType> && std::is_convertible_v<FieldType, DataType>)
|
||||
index_as_integer = static_cast<DataType>(value);
|
||||
}, index);
|
||||
|
||||
if (!is_integer_field)
|
||||
if (!index_as_integer)
|
||||
return false;
|
||||
|
||||
MatcherNumberConst<DataType> matcher{data_numeric->getData(), get<DataType>(index)};
|
||||
MatcherNumberConst<DataType> matcher{data_numeric->getData(), *index_as_integer};
|
||||
executeMatchKeyToIndex(offsets, matched_idxs, matcher);
|
||||
return true;
|
||||
}
|
||||
|
@ -31,10 +31,12 @@ Map(Date, Int32)
|
||||
Map(UUID, UInt16)
|
||||
{'00001192-0000-4000-8000-000000000001':1,'00001192-0000-4000-7000-000000000001':2}
|
||||
0 2 1
|
||||
Map(Int128, Int32)
|
||||
Map(Int128, String)
|
||||
{-1:'a',0:'b',1234567898765432193024000:'c',-1234567898765432193024000:'d'}
|
||||
a b c d
|
||||
|
||||
a
|
||||
b
|
||||
|
||||
a b c d
|
||||
b b b b
|
||||
|
@ -11,7 +11,7 @@ SELECT 'Map(Int8, Int8)';
|
||||
|
||||
SELECT m FROM table_map_with_key_integer;
|
||||
SELECT m[127], m[1], m[0], m[-1] FROM table_map_with_key_integer;
|
||||
SELECT m[toInt8(number - 2)] FROM table_map_with_key_integer ARRAY JOIN range(5) AS number;
|
||||
SELECT m[toInt8(number - 2)] FROM table_map_with_key_integer ARRAY JOIN [0, 1, 2, 3, 4] AS number;
|
||||
|
||||
SELECT count() FROM table_map_with_key_integer WHERE m = map();
|
||||
|
||||
@ -26,7 +26,7 @@ SELECT 'Map(Int32, UInt16)';
|
||||
|
||||
SELECT m FROM table_map_with_key_integer;
|
||||
SELECT m[-1], m[2147483647], m[-2147483648] FROM table_map_with_key_integer;
|
||||
SELECT m[toInt32(number - 2)] FROM table_map_with_key_integer ARRAY JOIN range(5) AS number;
|
||||
SELECT m[toInt32(number - 2)] FROM table_map_with_key_integer ARRAY JOIN [0, 1, 2, 3, 4] AS number;
|
||||
|
||||
DROP TABLE IF EXISTS table_map_with_key_integer;
|
||||
|
||||
@ -39,7 +39,7 @@ SELECT 'Map(Date, Int32)';
|
||||
|
||||
SELECT m FROM table_map_with_key_integer;
|
||||
SELECT m[toDate('2020-01-01')], m[toDate('2020-01-02')], m[toDate('2020-01-03')] FROM table_map_with_key_integer;
|
||||
SELECT m[toDate(number)] FROM table_map_with_key_integer ARRAY JOIN range(3) AS number;
|
||||
SELECT m[toDate(number)] FROM table_map_with_key_integer ARRAY JOIN [0, 1, 2] AS number;
|
||||
|
||||
DROP TABLE IF EXISTS table_map_with_key_integer;
|
||||
|
||||
@ -51,12 +51,14 @@ INSERT INTO table_map_with_key_integer VALUES ('2020-01-01', map('00001192-0000-
|
||||
SELECT 'Map(UUID, UInt16)';
|
||||
|
||||
SELECT m FROM table_map_with_key_integer;
|
||||
SELECT
|
||||
m[toUUID('00001192-0000-4000-6000-000000000001')],
|
||||
m[toUUID('00001192-0000-4000-7000-000000000001')],
|
||||
SELECT
|
||||
m[toUUID('00001192-0000-4000-6000-000000000001')],
|
||||
m[toUUID('00001192-0000-4000-7000-000000000001')],
|
||||
m[toUUID('00001192-0000-4000-8000-000000000001')]
|
||||
FROM table_map_with_key_integer;
|
||||
|
||||
SELECT m[257], m[1] FROM table_map_with_key_integer; -- { serverError 43 }
|
||||
|
||||
DROP TABLE IF EXISTS table_map_with_key_integer;
|
||||
|
||||
CREATE TABLE table_map_with_key_integer (d DATE, m Map(Int128, String))
|
||||
@ -65,11 +67,14 @@ ENGINE = MergeTree() ORDER BY d;
|
||||
|
||||
INSERT INTO table_map_with_key_integer SELECT '2020-01-01', map(-1, 'a', 0, 'b', toInt128(1234567898765432123456789), 'c', toInt128(-1234567898765432123456789), 'd');
|
||||
|
||||
SELECT 'Map(Int128, Int32)';
|
||||
SELECT 'Map(Int128, String)';
|
||||
|
||||
SELECT m FROM table_map_with_key_integer;
|
||||
SELECT m[toInt128(-1)], m[toInt128(0)], m[toInt128(1234567898765432123456789)], m[toInt128(-1234567898765432123456789)] FROM table_map_with_key_integer;
|
||||
SELECT m[toInt128(number - 2)] FROM table_map_with_key_integer ARRAY JOIN range(4) AS number;
|
||||
SELECT m[toInt128(number - 2)] FROM table_map_with_key_integer ARRAY JOIN [0, 1, 2, 3] AS number;
|
||||
|
||||
SELECT m[-1], m[0], m[toInt128(1234567898765432123456789)], m[toInt128(-1234567898765432123456789)] FROM table_map_with_key_integer;
|
||||
SELECT m[toUInt64(0)], m[toInt64(0)], m[toUInt8(0)], m[toUInt16(0)] FROM table_map_with_key_integer;
|
||||
|
||||
DROP TABLE IF EXISTS table_map_with_key_integer;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user