ClickHouse/tests/queries/0_stateless/00915_simple_aggregate_function.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
2.5 KiB
MySQL
Raw Normal View History

set optimize_throw_if_noop = 1;
-- basic test
2019-06-07 16:02:24 +00:00
drop table if exists simple;
2019-06-07 16:02:24 +00:00
create table simple (id UInt64,val SimpleAggregateFunction(sum,Double)) engine=AggregatingMergeTree order by id;
insert into simple select number,number from system.numbers limit 10;
2019-06-07 16:02:24 +00:00
select * from simple;
2020-04-22 13:52:07 +00:00
select * from simple final order by id;
2019-06-07 16:02:24 +00:00
select toTypeName(val) from simple limit 1;
-- merge
2019-06-07 16:02:24 +00:00
insert into simple select number,number from system.numbers limit 10;
2020-04-22 13:52:07 +00:00
select * from simple final order by id;
2019-06-07 16:02:24 +00:00
optimize table simple final;
select * from simple;
-- complex types
2019-06-07 16:02:24 +00:00
drop table if exists simple;
create table simple (
id UInt64,
nullable_str SimpleAggregateFunction(anyLast,Nullable(String)),
low_str SimpleAggregateFunction(anyLast,LowCardinality(Nullable(String))),
ip SimpleAggregateFunction(anyLast,IPv4),
status SimpleAggregateFunction(groupBitOr, UInt32),
tup SimpleAggregateFunction(sumMap, Tuple(Array(Int32), Array(Int64))),
tup_min SimpleAggregateFunction(minMap, Tuple(Array(Int32), Array(Int64))),
tup_max SimpleAggregateFunction(maxMap, Tuple(Array(Int32), Array(Int64))),
arr SimpleAggregateFunction(groupArrayArray, Array(Int32)),
2021-04-20 21:22:29 +00:00
uniq_arr SimpleAggregateFunction(groupUniqArrayArray, Array(Int32))
) engine=AggregatingMergeTree order by id;
2021-04-20 21:22:29 +00:00
insert into simple values(1,'1','1','1.1.1.1', 1, ([1,2], [1,1]), ([1,2], [1,1]), ([1,2], [1,1]), [1,2], [1,2]);
insert into simple values(1,null,'2','2.2.2.2', 2, ([1,3], [1,1]), ([1,3], [2,2]), ([1,3], [2,2]), [2,3,4], [2,3,4]);
Fix SimpleAggregateFunction for String longer MAX_SMALL_STRING_SIZE SimpleAggregateFunction do not pass arena to the add_function -> getAddressOfAddFunction(), hence next crash happens: (gdb) bt #0 DB::Arena::alloc (size=64, this=0x0) at ../dbms/src/Common/Arena.h:124 #1 DB::SingleValueDataString::changeImpl (this=0x7f97424a27d8, value=..., arena=0x0) at ../dbms/src/AggregateFunctions/AggregateFunctionMinMaxAny.h:274 #2 0x0000000005ea5319 in DB::AggregateFunctionNullUnary<true>::add (arena=<optimized out>, row_num=<optimized out>, columns=<optimized out>, place=<optimized out>, this=<optimized out>) at ../dbms/src/AggregateFunctions/AggregateFunctionNull.h:43 #3 DB::IAggregateFunctionHelper<DB::AggregateFunctionNullUnary<true> >::addFree (that=<optimized out>, place=<optimized out>, columns=<optimized out>, row_num=<optimized out>, arena=<optimized out>) at ../dbms/src/AggregateFunctions/IAggregateFunction.h:131 #4 0x000000000679772f in DB::AggregatingSortedBlockInputStream::addRow (this=this@entry=0x7f982de19c00, cursor=...) at ../dbms/src/Common/AlignedBuffer.h:31 #5 0x0000000006797faa in DB::AggregatingSortedBlockInputStream::merge (this=this@entry=0x7f982de19c00, merged_columns=..., queue=...) at ../dbms/src/DataStreams/AggregatingSortedBlockInputStream.cpp:140 #6 0x0000000006798979 in DB::AggregatingSortedBlockInputStream::readImpl (this=0x7f982de19c00) at ../dbms/src/DataStreams/AggregatingSortedBlockInputStream.cpp:78 #7 0x000000000622db55 in DB::IBlockInputStream::read (this=0x7f982de19c00) at ../dbms/src/DataStreams/IBlockInputStream.cpp:56 #8 0x0000000006613bee in DB::MergeTreeDataMergerMutator::mergePartsToTemporaryPart (this=this@entry=0x7f97ec65e1a0, future_part=..., merge_entry=..., time_of_merge=<optimized out>, disk_reservation=<optimized out>, deduplicate=<optimized out>) at /usr/include/c++/8/bits/shared_ptr_base.h:1018 #9 0x000000000658f7a4 in DB::StorageReplicatedMergeTree::tryExecuteMerge (this=0x7f97ec65b810, entry=...) at /usr/include/c++/8/bits/unique_ptr.h:342 #10 0x00000000065940ab in DB::StorageReplicatedMergeTree::executeLogEntry (this=0x7f97ec65b810, entry=...) at ../dbms/src/Storages/StorageReplicatedMergeTree.cpp:910 <snip> (gdb) f 1 (gdb) p MAX_SMALL_STRING_SIZE $1 = 48 (gdb) p capacity $2 = 64 (gdb) p value $3 = {data = 0x7f97242fcbd0 "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", size = 61} v2: avoid leaking of allocated by Arena memory on the intermediate step Fixes: 8f8d2c048e ("Merge pull request #4629 from bgranvea/simple_aggregate_function")
2019-05-16 17:41:09 +00:00
-- String longer then MAX_SMALL_STRING_SIZE (actual string length is 100)
2021-04-20 21:22:29 +00:00
insert into simple values(10,'10','10','10.10.10.10', 4, ([2,3], [1,1]), ([2,3], [3,3]), ([2,3], [3,3]), [], []);
insert into simple values(10,'2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222','20','20.20.20.20', 1, ([2, 4], [1,1]), ([2, 4], [4,4]), ([2, 4], [4,4]), [], []);
2020-04-22 13:52:07 +00:00
select * from simple final order by id;
2021-04-20 21:22:29 +00:00
select toTypeName(nullable_str),toTypeName(low_str),toTypeName(ip),toTypeName(status), toTypeName(tup), toTypeName(tup_min), toTypeName(tup_max), toTypeName(arr), toTypeName(uniq_arr) from simple limit 1;
2019-06-07 16:09:21 +00:00
optimize table simple final;
2019-06-07 16:09:21 +00:00
drop table simple;
drop table if exists with_overflow;
create table with_overflow (
id UInt64,
s SimpleAggregateFunction(sumWithOverflow, UInt8)
) engine AggregatingMergeTree order by id;
insert into with_overflow select 1, 1 from numbers(256);
optimize table with_overflow final;
select 'with_overflow', * from with_overflow;
drop table with_overflow;