Merging data type Map #15806#17829
Conversation
SELECT CAST(([1, 2, 3], ['1', '2', 'foo']), 'Map(UInt8, String)') AS map
Allow casting Tuple as Map.
| create table table_map (a Map(String, String), b String) engine = MergeTree() order by a; | ||
| insert into table_map values ({'name':'zhangsan', 'gender':'male'}, 'name'), ({'name':'lisi', 'gender':'female'}, 'gender'); | ||
| select a[b] from table_map; | ||
| select b from table_map where a = map('name','lisi', 'gender', 'female'); |
There was a problem hiding this comment.
Do we have a map constructor that accepts parallel arrays of keys/values a-la sumMap? And functions like keys/values/items that deconstruct it back into parallel arrays or an array of tuples. This constructor looks like it only works for a statically known set of keys, which might be not very practical.
There was a problem hiding this comment.
Map can be created from tuple of arrays by using CAST. Like this:
CAST(([1, 2, 3], ['1', '2', 'foo']), 'Map(UInt8, String)')Maybe we need more convenient syntax to do that.
keys and values columns will be available after #17310 will be merged. items can be implemented also as a CAST.
akuzm
left a comment
There was a problem hiding this comment.
Left some minor comments above, overall looks good now.
|
Fuzzer: #14974. |
|
Integration tests are broken in master. |
| else if (literal->value.getType() == Field::Types::Map) | ||
| { | ||
| const Map & map = literal->value.get<Map>(); | ||
| if (map.size() % 2) |
There was a problem hiding this comment.
What does this condition mean? Why is map size odd if there are NULL values?
There was a problem hiding this comment.
But it's not about null values. I think it's just an excessive check, which is actually unneeded.
| } | ||
| catch (...) | ||
| { | ||
| throw; |
|
@akuzm a bug has been found: deserialization code is not exception safe. |
|
Fixed here: #36333 |
|
@CurtizJ I don't understand why |
|
Does it exist only to enable Map type in Field? |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
The main difference from the original PR is that fixed duplicated sizes of arrays by using the type Nested.