```
SELECT h3kRing(581276613233082367, 65535)


2020.08.12 07:33:37.303682 [ 934614 ] {ad2b0b4d-1c24-406f-a259-18459c1dbacc} <Error> executeQuery: std::exception. Code: 1001, type: std::length_error, e.what() = vector (version 20.8.1.1) (from [::1]:55046) (in query:  SELECT '1048577', arraySort(h3kRing(581276613233082367, 65535))), Stack trace (when copying this message, always include the lines below):

0. /home/akuzm/ch4/ch/contrib/libcxx/include/exception:129: std::exception::capture() @ 0x1d6a38 in /home/akuzm/ch4/build-clang10/programs/server/libclickhouse-server-libd.so
1. /home/akuzm/ch4/ch/contrib/libcxx/include/exception:109: std::exception::exception() @ 0x105302 in /home/akuzm/ch4/build-clang10/contrib/libcxx-cmake/libcxxd.so
2. /home/akuzm/ch4/ch/contrib/libcxx/src/support/runtime/stdexcept_default.ipp:24: std::logic_error::logic_error(char const*) @ 0x104f30 in /home/akuzm/ch4/build-clang10/contrib/libcxx-cmake/libcxxd.so
3. /home/akuzm/ch4/ch/contrib/libcxx/include/stdexcept:153: std::length_error::length_error(char const*) @ 0x188837 in /home/akuzm/ch4/build-clang10/programs/server/libclickhouse-server-libd.so
4. /home/akuzm/ch4/ch/contrib/libcxx/include/stdexcept:251: std::__1::__throw_length_error(char const*) @ 0x1887c9 in /home/akuzm/ch4/build-clang10/programs/server/libclickhouse-server-libd.so
5. ? @ 0x18d2b8 in /home/akuzm/ch4/build-clang10/programs/server/libclickhouse-server-libd.so
6. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:0: std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >::__recommend(unsigned long) const @ 0x2b68ede in /home/akuzm/ch4/build-clang10/src/AggregateFunctions/libclickhouse_aggregate_functionsd.so
7. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:1092: std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >::__append(unsigned long) @ 0x2f66d6a in /home/akuzm/ch4/build-clang10/src/AggregateFunctions/libclickhouse_aggregate_functionsd.so
8. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:2022: std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >::resize(unsigned long) @ 0x2f666f6 in /home/akuzm/ch4/build-clang10/src/AggregateFunctions/libclickhouse_aggregate_functionsd.so
9. /home/akuzm/ch4/ch/src/Functions/h3kRing.cpp:69: DB::FunctionH3KRing::executeImpl(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) const @ 0x3db0a2d in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
10. /home/akuzm/ch4/ch/src/Functions/IFunctionImpl.h:202: DB::IFunction::executeImplDryRun(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) const @ 0x28b5581 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
11. /home/akuzm/ch4/ch/src/Functions/IFunctionAdaptors.h:156: DB::DefaultExecutable::executeDryRun(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) @ 0x28b4a8f in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
12. /home/akuzm/ch4/ch/src/Functions/IFunction.cpp:323: DB::ExecutableFunctionAdaptor::executeWithoutLowCardinalityColumns(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x30e63c3 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
13. /home/akuzm/ch4/ch/src/Functions/IFunction.cpp:266: DB::ExecutableFunctionAdaptor::defaultImplementationForConstantArguments(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x30e5f9e in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
14. /home/akuzm/ch4/ch/src/Functions/IFunction.cpp:316: DB::ExecutableFunctionAdaptor::executeWithoutLowCardinalityColumns(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x30e6340 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
15. /home/akuzm/ch4/ch/src/Functions/IFunction.cpp:486: DB::ExecutableFunctionAdaptor::execute(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x30e74cd in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
16. /home/akuzm/ch4/ch/src/Interpreters/ExpressionActions.cpp:206: DB::ExpressionAction::prepare(DB::Block&, DB::Settings const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) @ 0x1230136 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
17. /home/akuzm/ch4/ch/src/Interpreters/ExpressionActions.cpp:625: DB::ExpressionActions::addImpl(DB::ExpressionAction, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) @ 0x12339b7 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
18. /home/akuzm/ch4/ch/src/Interpreters/ExpressionActions.cpp:586: DB::ExpressionActions::add(DB::ExpressionAction const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) @ 0x12332e3 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
19. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:441: DB::ScopeStack::addAction(DB::ExpressionAction const&) @ 0xe150c2 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
20. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.h:117: DB::ActionsMatcher::Data::addAction(DB::ExpressionAction const&) @ 0xe20906 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
21. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:776: DB::ActionsMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0xe18465 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
22. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:498: DB::ActionsMatcher::visit(std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0xe154c7 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
23. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:675: DB::ActionsMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0xe17518 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
24. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:498: DB::ActionsMatcher::visit(std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0xe154c7 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
25. /home/akuzm/ch4/ch/src/Interpreters/InDepthNodeVisitor.h:32: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0x125269d in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
26. /home/akuzm/ch4/ch/src/Interpreters/InDepthNodeVisitor.h:45: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visitChildren(std::__1::shared_ptr<DB::IAST> const&) @ 0x125fd36 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
27. /home/akuzm/ch4/ch/src/Interpreters/InDepthNodeVisitor.h:35: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0x12526af in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
28. /home/akuzm/ch4/ch/src/Interpreters/ExpressionAnalyzer.cpp:396: DB::ExpressionAnalyzer::getRootActions(std::__1::shared_ptr<DB::IAST> const&, bool, std::__1::shared_ptr<DB::ExpressionActions>&, bool) @ 0x124983d in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
29. /home/akuzm/ch4/ch/src/Interpreters/ExpressionAnalyzer.cpp:818: DB::SelectQueryExpressionAnalyzer::appendSelect(DB::ExpressionActionsChain&, bool) @ 0x124c9eb in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
30. /home/akuzm/ch4/ch/src/Interpreters/ExpressionAnalyzer.cpp:1174: DB::ExpressionAnalysisResult::ExpressionAnalysisResult(DB::SelectQueryExpressionAnalyzer&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, bool, bool, bool, std::__1::shared_ptr<DB::FilterInfo> const&, DB::Block const&) @ 0x124f654 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
31. /home/akuzm/ch4/ch/src/Interpreters/InterpreterSelectQuery.cpp:505: DB::InterpreterSelectQuery::getSampleBlockImpl() @ 0x169408b in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so

2020.08.12 07:33:37.305253 [ 934565 ] {} <Trace> BaseDaemon: Received signal 6
2020.08.12 07:33:37.305611 [ 934621 ] {} <Fatal> BaseDaemon: ########################################
2020.08.12 07:33:37.306477 [ 934621 ] {} <Fatal> BaseDaemon: (version 20.8.1.1, build id: A86A33D8D97654E5) (from thread 934614) (query_id: ad2b0b4d-1c24-406f-a259-18459c1dbacc) Received signal Aborted (6)
2020.08.12 07:33:37.306650 [ 934621 ] {} <Fatal> BaseDaemon: 
2020.08.12 07:33:37.306839 [ 934621 ] {} <Fatal> BaseDaemon: Stack trace: 0x7f84a340118b 0x7f84a33e0859 0x7f84923496b6 0x7f84923506a8 0x7f84a45c9d7c 0x7f84a45ca58a 0x7f84a40db173 0x7f84a40d803d 0x7f84a40d6eba 0x7f84a3247609 0x7f84a34dd103
2020.08.12 07:33:37.308153 [ 934621 ] {} <Fatal> BaseDaemon: 4. /build/glibc-YYA7BZ/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51: __GI_raise @ 0x4618b in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
2020.08.12 07:33:37.308768 [ 934621 ] {} <Fatal> BaseDaemon: 5. /build/glibc-YYA7BZ/glibc-2.31/stdlib/abort.c:81: abort @ 0x25859 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
2020.08.12 07:33:37.309496 [ 934621 ] {} <Fatal> BaseDaemon: 6. /home/akuzm/ch4/ch/src/Server/TCPHandler.cpp:0: DB::TCPHandler::runImpl() @ 0x3776b6 in /home/akuzm/ch4/build-clang10/src/libclickhouse_serverd.so
2020.08.12 07:33:37.310154 [ 934621 ] {} <Fatal> BaseDaemon: 7. /home/akuzm/ch4/ch/src/Server/TCPHandler.cpp:1213: DB::TCPHandler::run() @ 0x37e6a8 in /home/akuzm/ch4/build-clang10/src/libclickhouse_serverd.so
2020.08.12 07:33:37.310710 [ 934621 ] {} <Fatal> BaseDaemon: 8. /home/akuzm/ch4/ch/contrib/poco/Net/src/TCPServerConnection.cpp:43: Poco::Net::TCPServerConnection::start() @ 0x1b9d7c in /home/akuzm/ch4/build-clang10/contrib/poco-cmake/Net/lib_poco_netd.so
2020.08.12 07:33:37.311132 [ 934621 ] {} <Fatal> BaseDaemon: 9. /home/akuzm/ch4/ch/contrib/poco/Net/src/TCPServerDispatcher.cpp:114: Poco::Net::TCPServerDispatcher::run() @ 0x1ba58a in /home/akuzm/ch4/build-clang10/contrib/poco-cmake/Net/lib_poco_netd.so
2020.08.12 07:33:37.311625 [ 934621 ] {} <Fatal> BaseDaemon: 10. /home/akuzm/ch4/ch/contrib/poco/Foundation/src/ThreadPool.cpp:199: Poco::PooledThread::run() @ 0x276173 in /home/akuzm/ch4/build-clang10/contrib/poco-cmake/Foundation/lib_poco_foundationd.so
2020.08.12 07:33:37.312139 [ 934621 ] {} <Fatal> BaseDaemon: 11. /home/akuzm/ch4/ch/contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x27303d in /home/akuzm/ch4/build-clang10/contrib/poco-cmake/Foundation/lib_poco_foundationd.so
2020.08.12 07:33:37.312651 [ 934621 ] {} <Fatal> BaseDaemon: 12. /home/akuzm/ch4/ch/contrib/poco/Foundation/src/Thread_POSIX.cpp:345: Poco::ThreadImpl::runnableEntry(void*) @ 0x271eba in /home/akuzm/ch4/build-clang10/contrib/poco-cmake/Foundation/lib_poco_foundationd.so
2020.08.12 07:33:37.312787 [ 934621 ] {} <Fatal> BaseDaemon: 13. start_thread @ 0x9609 in /lib/x86_64-linux-gnu/libpthread-2.31.so
2020.08.12 07:33:37.313131 [ 934621 ] {} <Fatal> BaseDaemon: 14. /build/glibc-YYA7BZ/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:97: __clone @ 0x122103 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
```
dst_offsets.resize(input_rows_count);
        auto current_offset = 0;
        std::vector<H3Index> hindex_vec;
        for (const auto row : ext::range(0, input_rows_count))
        {
            const H3Index origin_hindex = col_hindex->getUInt(row);
            const int k = col_k->getInt(row);
            const auto vec_size = maxKringSize(k);
            hindex_vec.resize(vec_size);
            kRing(origin_hindex, k, hindex_vec.data());
            dst_data.reserve(dst_data.size() + vec_size);
            for (auto hindex : hindex_vec)
            {
                if (hindex != 0)
                {
                    ++current_offset;
                    dst_data.insert(hindex);
                }
            }
            dst_offsets[row] = current_offset;
        }
        block.getByPosition(result).column = std::move(dst);
    }
};
void registerFunctionH3KRing(FunctionFactory & factory)
{
    factory.registerFunction<FunctionH3KRing>();
}
}