https://s3.amazonaws.com/clickhouse-test-reports/0/9346c9363afe6e1314472c601589a92cde68c95f/fuzzer_astfuzzerdebug,actions//report.html

```
2022.05.10 13:58:41.253027 [ 244 ] {540603e9-c395-4496-b69f-6badc18b6658} <Fatal> : Logical error: 'Invalid Field get from type UInt64 to type String'.
2022.05.10 14:00:14.576906 [ 489 ] {} <Fatal> BaseDaemon: ########################################
2022.05.10 14:00:14.583166 [ 489 ] {} <Fatal> BaseDaemon: (version 22.5.1.1 (official build), build id: FA22D30A47CE3A55) (from thread 244) (query_id: 540603e9-c395-4496-b69f-6badc18b6658) (query: SELECT ('00000000', '', '\00'), ('', ''), NULL, * FROM dist_01756_str WHERE key IN (257, 65536)) Received signal Aborted (6)
2022.05.10 14:00:14.583514 [ 489 ] {} <Fatal> BaseDaemon: 
2022.05.10 14:00:14.583931 [ 489 ] {} <Fatal> BaseDaemon: Stack trace: 0x7fd64577c03b 0x7fd64575b859 0x1733fdf4 0x1733ff02 0x174dad8a 0x1750efcc 0x2109c73d 0x2109c715 0x2109bcc1 0x25448454 0x26a6923b 0x26a68fd7 0x26a696d2 0x26a6962b 0x26a69519 0x26a68beb 0x26a68a81 0x26a6889d 0x26a65c83 0x26a66cd7 0x26a65d5d 0x26a645d9 0x26a38ef1 0x2607cafc 0x2607695a 0x26075e45 0x260fea5d 0x260ff41a 0x2652bf42 0x26528f84 0x274b656b 0x274c4dc5 0x2d43ae19 0x2d43b628 0x2d68f5d4 0x2d68c0da 0x2d68aebc 0x7fd645933609 0x7fd645858163
2022.05.10 14:00:14.584398 [ 489 ] {} <Fatal> BaseDaemon: 4. gsignal @ 0x7fd64577c03b in ?
2022.05.10 14:00:14.584626 [ 489 ] {} <Fatal> BaseDaemon: 5. abort @ 0x7fd64575b859 in ?
2022.05.10 14:00:14.735117 [ 489 ] {} <Fatal> BaseDaemon: 6. /build/build_docker/../src/Common/Exception.cpp:52: DB::handle_error_code(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool, std::__1::vector<void*, std::__1::allocator<void*> > const&) @ 0x1733fdf4 in /workspace/clickhouse
2022.05.10 14:00:14.823703 [ 489 ] {} <Fatal> BaseDaemon: 7. /build/build_docker/../src/Common/Exception.cpp:59: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0x1733ff02 in /workspace/clickhouse
2022.05.10 14:00:15.084711 [ 489 ] {} <Fatal> BaseDaemon: 8. /build/build_docker/../src/Common/Exception.h:39: DB::Exception::Exception<DB::Field::Types::Which&, DB::Field::Types::Which const&>(int, fmt::v8::basic_format_string<char, fmt::v8::type_identity<DB::Field::Types::Which&>::type, fmt::v8::type_identity<DB::Field::Types::Which const&>::type>, DB::Field::Types::Which&, DB::Field::Types::Which const&) @ 0x174dad8a in /workspace/clickhouse
2022.05.10 14:00:15.349523 [ 489 ] {} <Fatal> BaseDaemon: 9. /build/build_docker/../src/Core/Field.h:838: DB::NearestFieldTypeImpl<std::__1::decay<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>::type, void>::Type& DB::Field::get<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>() @ 0x1750efcc in /workspace/clickhouse
2022.05.10 14:00:15.476199 [ 489 ] {} <Fatal> BaseDaemon: 10. /build/build_docker/../src/Core/Field.h:429: auto const& DB::Field::get<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>() const @ 0x2109c73d in /workspace/clickhouse
2022.05.10 14:00:15.612381 [ 489 ] {} <Fatal> BaseDaemon: 11. /build/build_docker/../src/Core/Field.h:888: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const& DB::get<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(DB::Field const&) @ 0x2109c715 in /workspace/clickhouse
2022.05.10 14:00:15.737108 [ 489 ] {} <Fatal> BaseDaemon: 12. /build/build_docker/../src/Columns/ColumnString.h:131: DB::ColumnString::insert(DB::Field const&) @ 0x2109bcc1 in /workspace/clickhouse
2022.05.10 14:00:15.837769 [ 489 ] {} <Fatal> BaseDaemon: 13. /build/build_docker/../src/DataTypes/IDataType.cpp:58: DB::IDataType::createColumnConst(unsigned long, DB::Field const&) const @ 0x25448454 in /workspace/clickhouse
2022.05.10 14:00:15.998059 [ 489 ] {} <Fatal> BaseDaemon: 14. /build/build_docker/../src/Interpreters/OptimizeShardingKeyRewriteInVisitor.cpp:22: (anonymous namespace)::executeFunctionOnField(DB::Field const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::ExpressionActions> const&, std::__1::shared_ptr<DB::IDataType const> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) @ 0x26a6923b in /workspace/clickhouse
2022.05.10 14:00:16.158930 [ 489 ] {} <Fatal> BaseDaemon: 15. /build/build_docker/../src/Interpreters/OptimizeShardingKeyRewriteInVisitor.cpp:52: (anonymous namespace)::shardContains(DB::Field, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::OptimizeShardingKeyRewriteInMatcher::Data const&) @ 0x26a68fd7 in /workspace/clickhouse
2022.05.10 14:00:16.318800 [ 489 ] {} <Fatal> BaseDaemon: 16. /build/build_docker/../src/Interpreters/OptimizeShardingKeyRewriteInVisitor.cpp:121: auto DB::OptimizeShardingKeyRewriteInMatcher::visit(DB::ASTFunction&, DB::OptimizeShardingKeyRewriteInMatcher::Data&)::$_1::operator()<DB::Field>(DB::Field&) const @ 0x26a696d2 in /workspace/clickhouse
2022.05.10 14:00:16.479022 [ 489 ] {} <Fatal> BaseDaemon: 17. /build/build_docker/../contrib/libcxx/include/__algorithm/find_if.h:25: std::__1::__wrap_iter<DB::Field*> std::__1::find_if<std::__1::__wrap_iter<DB::Field*>, DB::OptimizeShardingKeyRewriteInMatcher::visit(DB::ASTFunction&, DB::OptimizeShardingKeyRewriteInMatcher::Data&)::$_1&>(std::__1::__wrap_iter<DB::Field*>, std::__1::__wrap_iter<DB::Field*>, DB::OptimizeShardingKeyRewriteInMatcher::visit(DB::ASTFunction&, DB::OptimizeShardingKeyRewriteInMatcher::Data&)::$_1&) @ 0x26a6962b in /workspace/clickhouse
2022.05.10 14:00:16.639668 [ 489 ] {} <Fatal> BaseDaemon: 18. /build/build_docker/../contrib/libcxx/include/__algorithm/remove_if.h:26: std::__1::__wrap_iter<DB::Field*> std::__1::remove_if<std::__1::__wrap_iter<DB::Field*>, DB::OptimizeShardingKeyRewriteInMatcher::visit(DB::ASTFunction&, DB::OptimizeShardingKeyRewriteInMatcher::Data&)::$_1>(std::__1::__wrap_iter<DB::Field*>, std::__1::__wrap_iter<DB::Field*>, DB::OptimizeShardingKeyRewriteInMatcher::visit(DB::ASTFunction&, DB::OptimizeShardingKeyRewriteInMatcher::Data&)::$_1) @ 0x26a69519 in /workspace/clickhouse
2022.05.10 14:00:16.792177 [ 489 ] {} <Fatal> BaseDaemon: 19. /build/build_docker/../contrib/libcxx/include/vector:3285: std::__1::vector<DB::Field, AllocatorWithMemoryTracking<DB::Field> >::size_type std::__1::erase_if<DB::Field, AllocatorWithMemoryTracking<DB::Field>, DB::OptimizeShardingKeyRewriteInMatcher::visit(DB::ASTFunction&, DB::OptimizeShardingKeyRewriteInMatcher::Data&)::$_1>(std::__1::vector<DB::Field, AllocatorWithMemoryTracking<DB::Field> >&, DB::OptimizeShardingKeyRewriteInMatcher::visit(DB::ASTFunction&, DB::OptimizeShardingKeyRewriteInMatcher::Data&)::$_1) @ 0x26a68beb in /workspace/clickhouse
2022.05.10 14:00:16.931318 [ 489 ] {} <Fatal> BaseDaemon: 20. /build/build_docker/../src/Interpreters/OptimizeShardingKeyRewriteInVisitor.cpp:0: DB::OptimizeShardingKeyRewriteInMatcher::visit(DB::ASTFunction&, DB::OptimizeShardingKeyRewriteInMatcher::Data&) @ 0x26a68a81 in /workspace/clickhouse
2022.05.10 14:00:17.071160 [ 489 ] {} <Fatal> BaseDaemon: 21. /build/build_docker/../src/Interpreters/OptimizeShardingKeyRewriteInVisitor.cpp:87: DB::OptimizeShardingKeyRewriteInMatcher::visit(std::__1::shared_ptr<DB::IAST>&, DB::OptimizeShardingKeyRewriteInMatcher::Data&) @ 0x26a6889d in /workspace/clickhouse
2022.05.10 14:00:17.317256 [ 489 ] {} <Fatal> BaseDaemon: 22. /build/build_docker/../src/Interpreters/InDepthNodeVisitor.h:34: DB::InDepthNodeVisitor<DB::OptimizeShardingKeyRewriteInMatcher, true, false, std::__1::shared_ptr<DB::IAST> >::visit(std::__1::shared_ptr<DB::IAST>&) @ 0x26a65c83 in /workspace/clickhouse
2022.05.10 14:00:17.586008 [ 489 ] {} <Fatal> BaseDaemon: 23. /build/build_docker/../src/Interpreters/InDepthNodeVisitor.h:53: DB::InDepthNodeVisitor<DB::OptimizeShardingKeyRewriteInMatcher, true, false, std::__1::shared_ptr<DB::IAST> >::visitChildren(std::__1::shared_ptr<DB::IAST>&) @ 0x26a66cd7 in /workspace/clickhouse
2022.05.10 14:00:17.832149 [ 489 ] {} <Fatal> BaseDaemon: 24. /build/build_docker/../src/Interpreters/InDepthNodeVisitor.h:43: DB::InDepthNodeVisitor<DB::OptimizeShardingKeyRewriteInMatcher, true, false, std::__1::shared_ptr<DB::IAST> >::visit(std::__1::shared_ptr<DB::IAST>&) @ 0x26a65d5d in /workspace/clickhouse
2022.05.10 14:00:18.116150 [ 489 ] {} <Fatal> BaseDaemon: 25. /build/build_docker/../src/Interpreters/ClusterProxy/executeQuery.cpp:162: DB::ClusterProxy::executeQuery(DB::QueryPlan&, DB::Block const&, DB::QueryProcessingStage::Enum, DB::StorageID const&, std::__1::shared_ptr<DB::IAST> const&, DB::ClusterProxy::IStreamFactory&, Poco::Logger*, std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context const>, DB::SelectQueryInfo const&, std::__1::shared_ptr<DB::ExpressionActions> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::Cluster> const&) @ 0x26a645d9 in /workspace/clickhouse
2022.05.10 14:00:18.761148 [ 489 ] {} <Fatal> BaseDaemon: 26. /build/build_docker/../src/Storages/StorageDistributed.cpp:710: DB::StorageDistributed::read(DB::QueryPlan&, 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::StorageSnapshot const> const&, DB::SelectQueryInfo&, std::__1::shared_ptr<DB::Context const>, DB::QueryProcessingStage::Enum, unsigned long, unsigned int) @ 0x26a38ef1 in /workspace/clickhouse
2022.05.10 14:00:19.360266 [ 489 ] {} <Fatal> BaseDaemon: 27. /build/build_docker/../src/Interpreters/InterpreterSelectQuery.cpp:2120: DB::InterpreterSelectQuery::executeFetchColumns(DB::QueryProcessingStage::Enum, DB::QueryPlan&) @ 0x2607cafc in /workspace/clickhouse
2022.05.10 14:00:19.977791 [ 489 ] {} <Fatal> BaseDaemon: 28. /build/build_docker/../src/Interpreters/InterpreterSelectQuery.cpp:1155: DB::InterpreterSelectQuery::executeImpl(DB::QueryPlan&, std::__1::optional<DB::Pipe>) @ 0x2607695a in /workspace/clickhouse
2022.05.10 14:00:20.594603 [ 489 ] {} <Fatal> BaseDaemon: 29. /build/build_docker/../src/Interpreters/InterpreterSelectQuery.cpp:623: DB::InterpreterSelectQuery::buildQueryPlan(DB::QueryPlan&) @ 0x26075e45 in /workspace/clickhouse
2022.05.10 14:00:20.855829 [ 489 ] {} <Fatal> BaseDaemon: 30. /build/build_docker/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:270: DB::InterpreterSelectWithUnionQuery::buildQueryPlan(DB::QueryPlan&) @ 0x260fea5d in /workspace/clickhouse
2022.05.10 14:00:21.118543 [ 489 ] {} <Fatal> BaseDaemon: 31. /build/build_docker/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:336: DB::InterpreterSelectWithUnionQuery::execute() @ 0x260ff41a in /workspace/clickhouse
2022.05.10 14:00:21.437808 [ 489 ] {} <Fatal> BaseDaemon: 32. /build/build_docker/../src/Interpreters/executeQuery.cpp:704: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x2652bf42 in /workspace/clickhouse
2022.05.10 14:00:21.778106 [ 489 ] {} <Fatal> BaseDaemon: 33. /build/build_docker/../src/Interpreters/executeQuery.cpp:1067: DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum) @ 0x26528f84 in /workspace/clickhouse
2022.05.10 14:00:22.109452 [ 489 ] {} <Fatal> BaseDaemon: 34. /build/build_docker/../src/Server/TCPHandler.cpp:332: DB::TCPHandler::runImpl() @ 0x274b656b in /workspace/clickhouse
2022.05.10 14:00:22.482616 [ 489 ] {} <Fatal> BaseDaemon: 35. /build/build_docker/../src/Server/TCPHandler.cpp:1780: DB::TCPHandler::run() @ 0x274c4dc5 in /workspace/clickhouse
2022.05.10 14:00:22.560339 [ 489 ] {} <Fatal> BaseDaemon: 36. /build/build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:43: Poco::Net::TCPServerConnection::start() @ 0x2d43ae19 in /workspace/clickhouse
2022.05.10 14:00:22.656509 [ 489 ] {} <Fatal> BaseDaemon: 37. /build/build_docker/../contrib/poco/Net/src/TCPServerDispatcher.cpp:115: Poco::Net::TCPServerDispatcher::run() @ 0x2d43b628 in /workspace/clickhouse
2022.05.10 14:00:22.757783 [ 489 ] {} <Fatal> BaseDaemon: 38. /build/build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:199: Poco::PooledThread::run() @ 0x2d68f5d4 in /workspace/clickhouse
2022.05.10 14:00:22.858043 [ 489 ] {} <Fatal> BaseDaemon: 39. /build/build_docker/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x2d68c0da in /workspace/clickhouse
2022.05.10 14:00:22.957417 [ 489 ] {} <Fatal> BaseDaemon: 40. /build/build_docker/../contrib/poco/Foundation/src/Thread_POSIX.cpp:345: Poco::ThreadImpl::runnableEntry(void*) @ 0x2d68aebc in /workspace/clickhouse
2022.05.10 14:00:22.957643 [ 489 ] {} <Fatal> BaseDaemon: 41. ? @ 0x7fd645933609 in ?
2022.05.10 14:00:22.957828 [ 489 ] {} <Fatal> BaseDaemon: 42. clone @ 0x7fd645858163 in ?
2022.05.10 14:00:24.188471 [ 489 ] {} <Fatal> BaseDaemon: Checksum of the binary: D1F7D5AA50D58103D610F9C1C3D8F982, integrity check passed.

```

cc: @azat 

#include <Interpreters/ExpressionActions.h>
#include <Interpreters/convertFieldToType.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTIdentifier.h>
#include <DataTypes/DataTypesNumber.h>
#include <Interpreters/OptimizeShardingKeyRewriteInVisitor.h>
namespace
{
using namespace DB;
Field executeFunctionOnField(
    const Field & field,
    const std::string & name,
    const ExpressionActionsPtr & sharding_expr,
    const DataTypePtr & type,
    const std::string & sharding_key_column_name)
{
    ColumnWithTypeAndName column;
    column.column = type->createColumnConst(1, field);
    column.name = name;
    column.type = type;
    Block block{column};
    size_t num_rows = 1;
    sharding_expr->execute(block, num_rows);
    ColumnWithTypeAndName & ret = block.getByName(sharding_key_column_name);
    return (*ret.column)[0];
}
bool shardContains(