**Describe the bug**
Running query with *StateResample leads clickhouse server to be killed because of seg fault.

**How to reproduce**
ClickHouse server version 20.4.4 revision 54434
`select sumIfStateResample(0,20,1)(number,1=1,number%20) as arr  from numbers(200);`

**Expected behavior**
Query should works.

**Error message and/or stacktrace**
```
2020.06.30 01:27:40.412792 [ 91519 ] {} <Fatal> BaseDaemon: ########################################
2020.06.30 01:27:40.412865 [ 91519 ] {} <Fatal> BaseDaemon: (version 20.4.4.18 (official build)) (from thread 130019) (query_id: a6b35b38-e9e5-4b5e-b75d-4950dff2c905) Received signal Segmentation fault (11).
2020.06.30 01:27:40.412888 [ 91519 ] {} <Fatal> BaseDaemon: Address: NULL pointer. Access: read. Unknown si_code.
2020.06.30 01:27:40.412905 [ 91519 ] {} <Fatal> BaseDaemon: Stack trace: 0xd5788e9 0xb3bc0a2 0xb3bd98a 0xb3bda7a 0x92562c1 0xd1dcde4 0xd1e1d50 0xdcea9ec 0xdaf0235 0xdb1d131 0xdb210ed 0xdb23228 0xdb233f5 0x90fe0b7 0x90263ab 0x902717a 0x902526b 0x9023753 0x7faedd0956db 0x7faedd76c88f
2020.06.30 01:27:40.413392 [ 91519 ] {} <Fatal> BaseDaemon: 3. DB::ColumnAggregateFunction::insertFrom(DB::IColumn const&, unsigned long) @ 0xd5788e9 in /usr/bin/clickhouse
2020.06.30 01:27:40.413624 [ 91519 ] {} <Fatal> BaseDaemon: 4. DB::FunctionArrayElement::executeGenericConst(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, DB::Field const&, DB::ArrayImpl::NullMapBuilder&) @ 0xb3bc0a2 in /usr/bin/clickhouse
2020.06.30 01:27:40.413646 [ 91519 ] {} <Fatal> BaseDaemon: 5. DB::FunctionArrayElement::perform(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, DB::ArrayImpl::NullMapBuilder&, unsigned long) @ 0xb3bd98a in /usr/bin/clickhouse
2020.06.30 01:27:40.413660 [ 91519 ] {} <Fatal> BaseDaemon: 6. DB::FunctionArrayElement::executeImpl(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) @ 0xb3bda7a in /usr/bin/clickhouse
2020.06.30 01:27:40.413867 [ 91519 ] {} <Fatal> BaseDaemon: 7. DB::ExecutableFunctionAdaptor::execute(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x92562c1 in /usr/bin/clickhouse
2020.06.30 01:27:40.413885 [ 91519 ] {} <Fatal> BaseDaemon: 8. DB::ExpressionAction::execute(DB::Block&, bool, std::__1::shared_ptr<DB::ExtraBlock>&) const @ 0xd1dcde4 in /usr/bin/clickhouse
2020.06.30 01:27:40.413895 [ 91519 ] {} <Fatal> BaseDaemon: 9. DB::ExpressionActions::execute(DB::Block&, bool) const @ 0xd1e1d50 in /usr/bin/clickhouse
2020.06.30 01:27:40.414090 [ 91519 ] {} <Fatal> BaseDaemon: 10. DB::ExpressionTransform::transform(DB::Chunk&) @ 0xdcea9ec in /usr/bin/clickhouse
2020.06.30 01:27:40.414301 [ 91519 ] {} <Fatal> BaseDaemon: 11. DB::ISimpleTransform::work() @ 0xdaf0235 in /usr/bin/clickhouse
2020.06.30 01:27:40.414317 [ 91519 ] {} <Fatal> BaseDaemon: 12. ? @ 0xdb1d131 in /usr/bin/clickhouse
2020.06.30 01:27:40.414511 [ 91519 ] {} <Fatal> BaseDaemon: 13. DB::PipelineExecutor::executeSingleThread(unsigned long, unsigned long) @ 0xdb210ed in /usr/bin/clickhouse
2020.06.30 01:27:40.414523 [ 91519 ] {} <Fatal> BaseDaemon: 14. DB::PipelineExecutor::executeImpl(unsigned long) @ 0xdb23228 in /usr/bin/clickhouse
2020.06.30 01:27:40.414531 [ 91519 ] {} <Fatal> BaseDaemon: 15. DB::PipelineExecutor::execute(unsigned long) @ 0xdb233f5 in /usr/bin/clickhouse
2020.06.30 01:27:40.414540 [ 91519 ] {} <Fatal> BaseDaemon: 16. ? @ 0x90fe0b7 in /usr/bin/clickhouse
2020.06.30 01:27:40.414551 [ 91519 ] {} <Fatal> BaseDaemon: 17. ThreadPoolImpl<ThreadFromGlobalPool>::worker(std::__1::__list_iterator<ThreadFromGlobalPool, void*>) @ 0x90263ab in /usr/bin/clickhouse
2020.06.30 01:27:40.414658 [ 91519 ] {} <Fatal> BaseDaemon: 18. ThreadFromGlobalPool::ThreadFromGlobalPool<void ThreadPoolImpl<ThreadFromGlobalPool>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda1'()>(void&&, void ThreadPoolImpl<ThreadFromGlobalPool>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda1'()&&...)::'lambda'()::operator()() const @ 0x902717a in /usr/bin/clickhouse
2020.06.30 01:27:40.414683 [ 91519 ] {} <Fatal> BaseDaemon: 19. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0x902526b in /usr/bin/clickhouse
2020.06.30 01:27:40.414691 [ 91519 ] {} <Fatal> BaseDaemon: 20. ? @ 0x9023753 in /usr/bin/clickhouse
2020.06.30 01:27:40.414706 [ 91519 ] {} <Fatal> BaseDaemon: 21. start_thread @ 0x76db in /lib/x86_64-linux-gnu/libpthread-2.27.so
2020.06.30 01:27:40.414718 [ 91519 ] {} <Fatal> BaseDaemon: 22. __clone @ 0x12188f in /lib/x86_64-linux-gnu/libc-2.27.so
```

**Additional context**
Add any other context about the problem here.

const ColumnWithTypeAndName & src_col = source.getByPosition(column_idx);
        MutableColumns scattered_columns = src_col.column->scatter(num_buckets, selector);
        for (size_t bucket = 0, size = num_buckets; bucket < size; ++bucket)
        {
            if (!scattered_columns[bucket]->empty())
            {
                Block & dst = destinations[bucket];
                dst.info.bucket_num = bucket;
                dst.insert({std::move(scattered_columns[bucket]), src_col.type, src_col.name});
            }
            /** Inserted columns of type ColumnAggregateFunction will own states of aggregate functions
              *  by holding shared_ptr to source column. See ColumnAggregateFunction.h
              */
        }
    }
}
std::vector<Block> Aggregator::convertBlockToTwoLevel(const Block & block)
{
    if (!block)
        return {};
    AggregatedDataVariants data;
    ColumnRawPtrs key_columns(params.keys_size);
    
    for (size_t i = 0; i < params.keys_size; ++i)
        key_columns[i] = block.safeGetByPosition(i).column.get();
    AggregatedDataVariants::Type type = method_chosen;
    data.keys_size = params.keys_size;
    data.key_sizes = key_sizes;
#define M(NAME) \
    else if (type == AggregatedDataVariants::Type::NAME) \