未验证 提交 41fb856d 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #8933 from bgiard/summing_merge_tree_strings

String keys in SummingMergeTree maps
...@@ -156,7 +156,7 @@ SummingSortedBlockInputStream::SummingSortedBlockInputStream( ...@@ -156,7 +156,7 @@ SummingSortedBlockInputStream::SummingSortedBlockInputStream(
|| endsWith(name, "Key") || endsWith(name, "Key")
|| endsWith(name, "Type")) || endsWith(name, "Type"))
{ {
if (!nested_type.isValueRepresentedByInteger()) if (!nested_type.isValueRepresentedByInteger() && !isStringOrFixedString(nested_type))
break; break;
map_desc.key_col_nums.push_back(*column_num_it); map_desc.key_col_nums.push_back(*column_num_it);
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
[1] [250] [1] [250]
[1,2] [250,150] [1,2] [250,150]
[2] [150] [2] [150]
['1','2'] [100,150]
['1'] [250]
['1','2'] [250,150]
['2'] [150]
20 [1,2] [100,150] 20 [1,2] [100,150]
20 [1] [250] 20 [1] [250]
20 [1,2] [250,150] 20 [1,2] [250,150]
......
...@@ -9,6 +9,15 @@ select `SomeMap.ID`, `SomeMap.Num` from nested_map; ...@@ -9,6 +9,15 @@ select `SomeMap.ID`, `SomeMap.Num` from nested_map;
drop table nested_map; drop table nested_map;
create table nested_map (d default today(), k UInt64, payload default rand(), SomeMap Nested(ID String, Num Int64)) engine=SummingMergeTree(d, k, 8192);
insert into nested_map (k, `SomeMap.ID`, `SomeMap.Num`) values (0,['1'],[100]),(1,['1'],[100]),(2,['1'],[100]),(3,['1','2'],[100,150]);
insert into nested_map (k, `SomeMap.ID`, `SomeMap.Num`) values (0,['2'],[150]),(1,['1'],[150]),(2,['1','2'],[150,150]),(3,['1'],[-100]);
optimize table nested_map;
select `SomeMap.ID`, `SomeMap.Num` from nested_map;
drop table nested_map;
drop table if exists nested_map_explicit; drop table if exists nested_map_explicit;
create table nested_map_explicit (d default today(), k UInt64, SomeIntExcluded UInt32, SomeMap Nested(ID UInt32, Num Int64)) engine=SummingMergeTree(d, k, 8192, (SomeMap)); create table nested_map_explicit (d default today(), k UInt64, SomeIntExcluded UInt32, SomeMap Nested(ID UInt32, Num Int64)) engine=SummingMergeTree(d, k, 8192, (SomeMap));
......
2000-01-01 1 [1,2] [3,4] [10,11] [0,1,2] [3,4,5] [-1,-2,-3] [1,10,100] 2000-01-01 1 [1,2] [3,4] [10,11] [0,1,2] ['3','4','5'] [-1,-2,-3] [1,10,100]
2000-01-01 1 [2,1] [4,3] [20,22] [2,2,1] [5,5,0] [-3,-3,-33] [10,100,1000] 2000-01-01 1 [2,1] [4,3] [20,22] [2,2,1] ['5','5','0'] [-3,-3,-33] [10,100,1000]
2000-01-01 2 [1,2] [3,4] [10,11] [0,1,2] [3,4,5] [-1,-2,-3] [1,10,100] 2000-01-01 2 [1,2] [3,4] [10,11] [0,1,2] ['3','4','5'] [-1,-2,-3] [1,10,100]
2000-01-01 2 [2,1,1] [4,3,3] [20,22,33] [2,2] [5,5] [-3,-3] [10,100] 2000-01-01 2 [2,1,1] [4,3,3] [20,22,33] [2,2] ['5','5'] [-3,-3] [10,100]
2000-01-01 2 [1,2] [3,4] [10,11] [0,1,2] [3,4,5] [-1,-2,-3] [1,10,100] 2000-01-01 2 [1,2] [3,4] [10,11] [0,1,2] ['3','4','5'] [-1,-2,-3] [1,10,100]
2000-01-01 1 1 3 10 2000-01-01 1 1 3 10
2000-01-01 1 1 3 22 2000-01-01 1 1 3 22
2000-01-01 1 2 4 11 2000-01-01 1 2 4 11
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
2000-01-01 2 0 3 -1 2 2000-01-01 2 0 3 -1 2
2000-01-01 2 1 4 -2 20 2000-01-01 2 1 4 -2 20
2000-01-01 2 2 5 -3 310 2000-01-01 2 2 5 -3 310
2000-01-01 1 [1,2] [3,4] [32,31] [0,1,1,2] [3,0,4,5] [-1,-33,-2,-3] [1,1000,10,210] 2000-01-01 1 [1,2] [3,4] [32,31] [0,1,1,2] ['3','0','4','5'] [-1,-33,-2,-3] [1,1000,10,210]
2000-01-01 2 [1,2] [3,4] [75,42] [0,1,2] [3,4,5] [-1,-2,-3] [2,20,310] 2000-01-01 2 [1,2] [3,4] [75,42] [0,1,2] ['3','4','5'] [-1,-2,-3] [2,20,310]
2000-01-01 1 1 3 32 2000-01-01 1 1 3 32
2000-01-01 1 2 4 31 2000-01-01 1 2 4 31
2000-01-01 2 1 3 75 2000-01-01 2 1 3 75
......
DROP TABLE IF EXISTS summing_composite_key; DROP TABLE IF EXISTS summing_composite_key;
CREATE TABLE summing_composite_key (d Date, k UInt64, FirstMap Nested(k1 UInt32, k2ID Int8, s Float64), SecondMap Nested(k1ID UInt64, k2Key UInt32, k3Type Int32, s Int64)) ENGINE = SummingMergeTree(d, k, 1); CREATE TABLE summing_composite_key (d Date, k UInt64, FirstMap Nested(k1 UInt32, k2ID Int8, s Float64), SecondMap Nested(k1ID UInt64, k2Key String, k3Type Int32, s Int64)) ENGINE = SummingMergeTree(d, k, 1);
INSERT INTO summing_composite_key VALUES ('2000-01-01', 1, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]), ('2000-01-01', 1, [2,1], [4,3], [20,22], [2,2,1], [5,5,0], [-3,-3,-33], [10,100,1000]), ('2000-01-01', 2, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]), ('2000-01-01', 2, [2,1,1], [4,3,3], [20,22,33], [2,2], [5,5], [-3,-3], [10,100]), ('2000-01-01', 2, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]); INSERT INTO summing_composite_key VALUES ('2000-01-01', 1, [1,2], ['3','4'], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]), ('2000-01-01', 1, [2,1], ['4','3'], [20,22], [2,2,1], [5,5,0], [-3,-3,-33], [10,100,1000]), ('2000-01-01', 2, [1,2], ['3','4'], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]), ('2000-01-01', 2, [2,1,1], ['4','3','3'], [20,22,33], [2,2], [5,5], [-3,-3], [10,100]), ('2000-01-01', 2, [1,2], ['3','4'], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]);
SELECT * FROM summing_composite_key ORDER BY d, k, _part_index; SELECT * FROM summing_composite_key ORDER BY d, k, _part_index;
......
...@@ -112,7 +112,7 @@ Table can have nested data structures that are processed in a special way. ...@@ -112,7 +112,7 @@ Table can have nested data structures that are processed in a special way.
If the name of a nested table ends with `Map` and it contains at least two columns that meet the following criteria: If the name of a nested table ends with `Map` and it contains at least two columns that meet the following criteria:
- the first column is numeric `(*Int*, Date, DateTime)`, let's call it `key`, - the first column is numeric `(*Int*, Date, DateTime)` or a string `(String, FixedString)`, let's call it `key`,
- the other columns are arithmetic `(*Int*, Float32/64)`, let's call it `(values...)`, - the other columns are arithmetic `(*Int*, Float32/64)`, let's call it `(values...)`,
then this nested table is interpreted as a mapping of `key => (values...)`, and when merging its rows, the elements of two data sets are merged by `key` with a summation of the corresponding `(values...)`. then this nested table is interpreted as a mapping of `key => (values...)`, and when merging its rows, the elements of two data sets are merged by `key` with a summation of the corresponding `(values...)`.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册