```
/4/ :) SELECT [1, null][[1, NULL][1]]


Received exception from server (version 20.6.1):
Code: 49. DB::Exception: Received from localhost:9000. DB::Exception: Bad cast from type DB::DataTypeNumber<char8_t> to DB::DataTypeNullable. Stack trace:

0. /home/akuzm/ch4/ch/contrib/poco/Foundation/src/Exception.cpp:27: Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x1152bbd0 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
1. /home/akuzm/ch4/ch/src/Common/Exception.cpp:37: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x97a736d in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
2. std::__1::enable_if<is_reference_v<DB::DataTypeNullable const&>, DB::DataTypeNullable const&>::type typeid_cast<DB::DataTypeNullable const&, DB::IDataType const>(DB::IDataType const&) @ 0xcb995f8 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
3. DB::FunctionArrayElement::executeImpl(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) @ 0xcb9719e in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
4. DB::ExecutableFunctionAdaptor::defaultImplementationForNulls(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0xa3cf29a in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
5. DB::ExecutableFunctionAdaptor::executeWithoutLowCardinalityColumns(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0xa3cf0f1 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
6. DB::ExecutableFunctionAdaptor::defaultImplementationForConstantArguments(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0xa3ceea6 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
7. DB::ExecutableFunctionAdaptor::executeWithoutLowCardinalityColumns(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0xa3cf0c2 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
8. DB::ExecutableFunctionAdaptor::execute(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0xa3cfe41 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
9. /home/akuzm/ch4/ch/src/Interpreters/ExpressionActions.cpp:209: 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> > > >&) @ 0xe3843f5 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
10. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:1635: 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> > > >&) @ 0xe384fb5 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
11. /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> > > >&) @ 0xe38561d in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
12. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:1549: DB::ScopeStack::addAction(DB::ExpressionAction const&) @ 0xe42a8ed in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
13. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:593: DB::ActionsMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0xe432776 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
14. /home/akuzm/ch4/ch/contrib/libcxx/include/memory:3826: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0xe42002b in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
15. /home/akuzm/ch4/ch/src/Interpreters/InDepthNodeVisitor.h:45: DB::ExpressionAnalyzer::getRootActions(std::__1::shared_ptr<DB::IAST> const&, bool, std::__1::shared_ptr<DB::ExpressionActions>&, bool) (.constprop.0) @ 0xe4126f3 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
16. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:656: DB::SelectQueryExpressionAnalyzer::appendSelect(DB::ExpressionActionsChain&, bool) @ 0xe413688 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
17. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:662: 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&) @ 0xe41ceb7 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
18. /home/akuzm/ch4/ch/src/Interpreters/ExpressionAnalyzer.h:164: DB::InterpreterSelectQuery::getSampleBlockImpl() @ 0xe3cb1cd in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
19. /home/akuzm/ch4/ch/src/Interpreters/InterpreterSelectQuery.cpp:312: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions 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> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&)::'lambda'(bool)::operator()(bool) const @ 0xe3d1c6a in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
20. /home/akuzm/ch4/ch/src/Interpreters/InterpreterSelectQuery.cpp:408: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions 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> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&) @ 0xe3d9cb7 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
21. /home/akuzm/ch4/ch/src/Interpreters/InterpreterSelectQuery.cpp:146: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions 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> > > > const&) @ 0xe3db669 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
22. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:1681: DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions 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> > > > const&) @ 0xe53cb77 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
23. /home/akuzm/ch4/ch/contrib/libcxx/include/vector:461: DB::InterpreterFactory::get(std::__1::shared_ptr<DB::IAST>&, DB::Context&, DB::QueryProcessingStage::Enum) @ 0xe347064 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
24. /home/akuzm/ch4/ch/contrib/libcxx/include/memory:2587: DB::executeQueryImpl(char const*, char const*, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool, DB::ReadBuffer*) @ 0xe6ae7cd in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
25. /home/akuzm/ch4/ch/src/Interpreters/executeQuery.cpp:644: DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool) @ 0xe6b20ba in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
26. /home/akuzm/ch4/ch/src/Server/TCPHandler.cpp:253: DB::TCPHandler::runImpl() @ 0xece41c6 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
27. /home/akuzm/ch4/ch/src/Server/TCPHandler.cpp:1203: DB::TCPHandler::run() @ 0xece4f20 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
28. /home/akuzm/ch4/ch/contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x11449a3b in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
29. /home/akuzm/ch4/ch/contrib/libcxx/include/atomic:856: Poco::Net::TCPServerDispatcher::run() @ 0x11449ecb in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
30. /home/akuzm/ch4/ch/contrib/poco/Foundation/include/Poco/Mutex_POSIX.h:59: Poco::PooledThread::run() @ 0x115c89a6 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
31. /home/akuzm/ch4/ch/contrib/poco/Foundation/include/Poco/AutoPtr.h:223: Poco::ThreadImpl::runnableEntry(void*) @ 0x115c3da0 in /home/akuzm/ch4/build-gcc9-rel/programs/clickhouse
```
ArrayImpl::NullMapBuilder & builder)
{
    const ColumnArray * col_array = checkAndGetColumn<ColumnArray>(block.getByPosition(arguments[0]).column.get());
    if (!col_array)
        return false;
    const auto & col_nested = col_array->getData();
    auto col_res = col_nested.cloneEmpty();
    if (index.getType() == Field::Types::UInt64)
        ArrayElementGenericImpl::vectorConst<false>(
            col_nested, col_array->getOffsets(), safeGet<UInt64>(index) - 1, *col_res, builder);
    else if (index.getType() == Field::Types::Int64)
        ArrayElementGenericImpl::vectorConst<true>(
            col_nested, col_array->getOffsets(), -safeGet<Int64>(index) - 1, *col_res, builder);
    else
        throw Exception("Illegal type of array index", ErrorCodes::LOGICAL_ERROR);
    block.getByPosition(result).column = std::move(col_res);
    return true;
}
template <typename IndexType>
bool FunctionArrayElement::executeGeneric(Block & block, const ColumnNumbers & arguments, size_t result, const PaddedPODArray<IndexType> & indices,