```
SELECT if(x = 100, toUInt8(x), -1) FROM (SELECT CAST(null, 'Nullable(UInt8)') AS x)


2020.07.13 16:27:41.854176 [ 49447 ] {ef40a485-4af0-455c-bdd5-71b14e35a7dd} <Error> : Logical error: 'Bad cast from type DB::ColumnVector<signed char> to DB::ColumnVector<short>'.
clickhouse-server: /home/akuzm/ch4/ch/src/Common/Exception.cpp:45: DB::Exception::Exception(const std::string &, int): Assertion `false' failed.
2020.07.13 16:27:41.854677 [ 49394 ] {} <Trace> BaseDaemon: Received signal 6
2020.07.13 16:27:41.855023 [ 49466 ] {} <Fatal> BaseDaemon: ########################################
2020.07.13 16:27:41.855678 [ 49466 ] {} <Fatal> BaseDaemon: (version 20.6.1.1, build id: F176DE2A5C050ABF) (from thread 49447) (query_id: ef40a485-4af0-455c-bdd5-71b14e35a7dd) Received signal Aborted (6)
2020.07.13 16:27:41.855821 [ 49466 ] {} <Fatal> BaseDaemon: 
2020.07.13 16:27:41.855951 [ 49466 ] {} <Fatal> BaseDaemon: Stack trace: 0x7fdee227f18b 0x7fdee225e859 0x7fdee225e729 0x7fdee226ff36 0x7fdee61838ab 0x7fdedd5c4f5b 0x7fded67fd0c5 0x7fdee0f4f7a4 0x7fded67ecbbb 0x7fded6b70194 0x7fded6b705d8 0x7fded2576029 0x7fded2574dbf 0x7fded2571eed 0x7fded2578b52 0x7fdee3444d7c 0x7fdee344558a 0x7fdee2f56173 0x7fdee2f5303d 0x7fdee2f51eba 0x7fdee20c5609 0x7fdee235b103
2020.07.13 16:27:41.856398 [ 49466 ] {} <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.07.13 16:27:41.856659 [ 49466 ] {} <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.07.13 16:27:41.856933 [ 49466 ] {} <Fatal> BaseDaemon: 6. /build/glibc-YYA7BZ/glibc-2.31/intl/loadmsgcat.c:509: _nl_load_domain.cold @ 0x25729 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
2020.07.13 16:27:41.857240 [ 49466 ] {} <Fatal> BaseDaemon: 7. ? @ 0x36f36 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
2020.07.13 16:27:41.857626 [ 49466 ] {} <Fatal> BaseDaemon: 8. /home/akuzm/ch4/ch/src/Common/Exception.cpp:48: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x2798ab in /home/akuzm/ch4/build-clang10/src/libclickhouse_common_iod.so
2020.07.13 16:27:41.864597 [ 49466 ] {} <Fatal> BaseDaemon: 9. /home/akuzm/ch4/ch/src/Common/typeid_cast.h:40: std::__1::enable_if<std::is_reference_v<DB::ColumnVector<short> const&>, DB::ColumnVector<short> const&>::type typeid_cast<DB::ColumnVector<short> const&, DB::IColumn const>(DB::IColumn const&) @ 0x3d86f5b in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.07.13 16:27:41.865558 [ 49466 ] {} <Fatal> BaseDaemon: 10. /home/akuzm/ch4/ch/src/DataTypes/DataTypeNumberBase.cpp:186: DB::DataTypeNumberBase<short>::serializeBinaryBulk(DB::IColumn const&, DB::WriteBuffer&, unsigned long, unsigned long) const @ 0x44b0c5 in /home/akuzm/ch4/build-clang10/src/libclickhouse_datatypesd.so
2020.07.13 16:27:41.866058 [ 49466 ] {} <Fatal> BaseDaemon: 11. /home/akuzm/ch4/ch/src/DataTypes/IDataType.h:184: DB::IDataType::serializeBinaryBulkWithMultipleStreams(DB::IColumn const&, unsigned long, unsigned long, DB::IDataType::SerializeBinaryBulkSettings&, std::__1::shared_ptr<DB::IDataType::SerializeBinaryBulkState>&) const @ 0x24aa7a4 in /home/akuzm/ch4/build-clang10/src/AggregateFunctions/libclickhouse_aggregate_functionsd.so
2020.07.13 16:27:41.866609 [ 49466 ] {} <Fatal> BaseDaemon: 12. /home/akuzm/ch4/ch/src/DataTypes/DataTypeNullable.cpp:102: DB::DataTypeNullable::serializeBinaryBulkWithMultipleStreams(DB::IColumn const&, unsigned long, unsigned long, DB::IDataType::SerializeBinaryBulkSettings&, std::__1::shared_ptr<DB::IDataType::SerializeBinaryBulkState>&) const @ 0x43abbb in /home/akuzm/ch4/build-clang10/src/libclickhouse_datatypesd.so
2020.07.13 16:27:41.867191 [ 49466 ] {} <Fatal> BaseDaemon: 13. /home/akuzm/ch4/ch/src/DataStreams/NativeBlockOutputStream.cpp:58: DB::NativeBlockOutputStream::writeData(DB::IDataType const&, COW<DB::IColumn>::immutable_ptr<DB::IColumn> const&, DB::WriteBuffer&, unsigned long, unsigned long) @ 0x2d9194 in /home/akuzm/ch4/build-clang10/src/libclickhouse_datastreamsd.so
2020.07.13 16:27:41.867691 [ 49466 ] {} <Fatal> BaseDaemon: 14. /home/akuzm/ch4/ch/src/DataStreams/NativeBlockOutputStream.cpp:124: DB::NativeBlockOutputStream::write(DB::Block const&) @ 0x2d95d8 in /home/akuzm/ch4/build-clang10/src/libclickhouse_datastreamsd.so
2020.07.13 16:27:41.868315 [ 49466 ] {} <Fatal> BaseDaemon: 15. /home/akuzm/ch4/ch/src/Server/TCPHandler.cpp:1106: DB::TCPHandler::sendData(DB::Block const&) @ 0x348029 in /home/akuzm/ch4/build-clang10/src/libclickhouse_serverd.so
2020.07.13 16:27:41.868840 [ 49466 ] {} <Fatal> BaseDaemon: 16. /home/akuzm/ch4/ch/src/Server/TCPHandler.cpp:597: DB::TCPHandler::processOrdinaryQueryWithProcessors() @ 0x346dbf in /home/akuzm/ch4/build-clang10/src/libclickhouse_serverd.so
2020.07.13 16:27:41.869307 [ 49466 ] {} <Fatal> BaseDaemon: 17. /home/akuzm/ch4/ch/src/Server/TCPHandler.cpp:272: DB::TCPHandler::runImpl() @ 0x343eed in /home/akuzm/ch4/build-clang10/src/libclickhouse_serverd.so
2020.07.13 16:27:41.869901 [ 49466 ] {} <Fatal> BaseDaemon: 18. /home/akuzm/ch4/ch/src/Server/TCPHandler.cpp:1201: DB::TCPHandler::run() @ 0x34ab52 in /home/akuzm/ch4/build-clang10/src/libclickhouse_serverd.so
2020.07.13 16:27:41.870393 [ 49466 ] {} <Fatal> BaseDaemon: 19. /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.07.13 16:27:41.870889 [ 49466 ] {} <Fatal> BaseDaemon: 20. /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.07.13 16:27:41.871396 [ 49466 ] {} <Fatal> BaseDaemon: 21. /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.07.13 16:27:41.871925 [ 49466 ] {} <Fatal> BaseDaemon: 22. /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.07.13 16:27:41.872442 [ 49466 ] {} <Fatal> BaseDaemon: 23. /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.07.13 16:27:41.872707 [ 49466 ] {} <Fatal> BaseDaemon: 24. start_thread @ 0x9609 in /lib/x86_64-linux-gnu/libpthread-2.31.so
2020.07.13 16:27:41.873202 [ 49466 ] {} <Fatal> BaseDaemon: 25. /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
```
left_ok = true;
            right_ok = executeConstRightType<T0, T1, ColVecT0, ColVecT1>(cond_col, block, arguments, result, col_const_left);
        }
        else if (const auto * col_arr_left = checkAndGetColumn<ColumnArray>(col_left_untyped))
        {
            if (auto col_arr_left_elems = checkAndGetColumn<ColVecT0>(&col_arr_left->getData()))
            {
                left_ok = true;
                right_ok = executeRightTypeArray<T0, T1, ColVecT0, ColVecT1>(
                    cond_col, block, arguments, result, col_arr_left, input_rows_count);
            }
        }
        else if (const auto * col_const_arr_left = checkAndGetColumnConst<ColumnArray>(col_left_untyped))
        {
            if (checkColumn<ColVecT0>(&assert_cast<const ColumnArray &>(col_const_arr_left->getDataColumn()).getData()))
            {
                left_ok = true;
                right_ok = executeConstRightTypeArray<T0, T1, ColVecT0, ColVecT1>(
                    cond_col, block, arguments, result, col_const_arr_left, input_rows_count);
            }
        }
        if (!left_ok)
            return false;
        ColumnWithTypeAndName & right_column_typed = block.getByPosition(arguments[2]);
        if (!right_ok)
            throw Exception("Illegal column " + right_column_typed.column->getName() + " of third argument of function " + getName(),
                ErrorCodes::ILLEGAL_COLUMN);
        return true;
    }
    static bool executeString(const ColumnUInt8 * cond_col, Block & block, const ColumnNumbers & arguments, size_t result)