**Describe the bug**
[A link to the report
](https://s3.amazonaws.com/clickhouse-test-reports/42516/00f9ae99249c636320141607ee51dac170ae6938/fuzzer_astfuzzerasan//report.html)

**How to reproduce**
```sql
WITH map(1, 2, 3, NULL) AS m
SELECT toTypeName(m);

┌─toTypeName(m)───────────────┐
│ Map(UInt8, Nullable(UInt8)) │
└─────────────────────────────┘

SELECT
    map(1, 2, 3, NULL) AS m,
    m[toNullable(1)]
```

```
2022.10.20 13:32:01.108662 [ 1119659 ] {3b38465f-ef53-477d-9274-3f7284a05c8c} <Debug> executeQuery: (from [::ffff:127.0.0.1]:41364) select map(1, 2, 3, NULL) as m, m[toNullable(1)] (stage: Complete)
2022.10.20 13:32:01.109375 [ 1119659 ] {3b38465f-ef53-477d-9274-3f7284a05c8c} <Error> executeQuery: Code: 49. DB::Exception: Bad cast from type DB::DataTypeNumber<char8_t> to DB::DataTypeNullable: While processing map(1, 2, 3, NULL) AS m, m[toNullable(1)]. (LOGICAL_ERROR) (version 22.10.1.1) (from [::ffff:127.0.0.1]:41364) (in query: select map(1, 2, 3, NULL) as m, m[toNullable(1)]), Stack trace (when copying this message, always include the lines below):

0. ./build_clang/./contrib/libcxx/include/exception:133: Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x17db630c in /usr/local/bin/clickhouse
1. ./build_clang/./src/Common/Exception.cpp:69: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0xfe75d5a in /usr/local/bin/clickhouse
2. DB::DataTypeNullable const& typeid_cast<DB::DataTypeNullable const&, DB::IDataType const>(DB::IDataType const&) @ 0xfad5a3f in /usr/local/bin/clickhouse
3. DB::FunctionArrayElement::executeImpl(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0xfac1ac3 in /usr/local/bin/clickhouse
4. DB::FunctionArrayElement::executeMap(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0xfac11f9 in /usr/local/bin/clickhouse
5. DB::FunctionArrayElement::executeImpl(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0xfac19cf in /usr/local/bin/clickhouse
6. DB::IFunction::executeImplDryRun(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0xb4eb80a in /usr/local/bin/clickhouse
7. DB::FunctionToExecutableFunctionAdaptor::executeDryRunImpl(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0xb4eb4ce in /usr/local/bin/clickhouse
8. ./build_clang/./src/Functions/IFunction.cpp:0: DB::IExecutableFunction::executeWithoutLowCardinalityColumns(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x13dbd911 in /usr/local/bin/clickhouse
9. ./build_clang/./src/Functions/IFunction.cpp:0: DB::IExecutableFunction::defaultImplementationForNulls(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x13dbdb4e in /usr/local/bin/clickhouse
10. ./build_clang/./src/Functions/IFunction.cpp:0: DB::IExecutableFunction::executeWithoutLowCardinalityColumns(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x13dbd8dd in /usr/local/bin/clickhouse
11. ./build_clang/./contrib/boost/boost/smart_ptr/intrusive_ptr.hpp:200: DB::IExecutableFunction::defaultImplementationForConstantArguments(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x13dbd43c in /usr/local/bin/clickhouse
12. ./build_clang/./src/Functions/IFunction.cpp:0: DB::IExecutableFunction::executeWithoutLowCardinalityColumns(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x13dbd8b5 in /usr/local/bin/clickhouse
13. ./build_clang/./contrib/boost/boost/smart_ptr/intrusive_ptr.hpp:115: DB::IExecutableFunction::executeWithoutSparseColumns(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x13dbe140 in /usr/local/bin/clickhouse
14. ./build_clang/./src/Functions/IFunction.cpp:372: DB::IExecutableFunction::execute(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x13dbf0dc in /usr/local/bin/clickhouse
15. ./build_clang/./src/Interpreters/ActionsDAG.cpp:0: DB::ActionsDAG::addFunction(std::__1::shared_ptr<DB::IFunctionOverloadResolver> const&, std::__1::vector<DB::ActionsDAG::Node const*, std::__1::allocator<DB::ActionsDAG::Node const*> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) @ 0x1434bc2a in /usr/local/bin/clickhouse
16. ./build_clang/./src/Interpreters/ActionsVisitor.cpp:0: DB::ScopeStack::addFunction(std::__1::shared_ptr<DB::IFunctionOverloadResolver> 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::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) @ 0x1478115c in /usr/local/bin/clickhouse
17. ./build_clang/./contrib/libcxx/include/string:1445: DB::ActionsMatcher::Data::addFunction(std::__1::shared_ptr<DB::IFunctionOverloadResolver> 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::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) @ 0x1478c72f in /usr/local/bin/clickhouse
18. ./build_clang/./contrib/libcxx/include/string:1445: DB::ActionsMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0x14785ec9 in /usr/local/bin/clickhouse
19. ./build_clang/./src/Interpreters/ActionsVisitor.cpp:0: DB::ActionsMatcher::visit(DB::ASTExpressionList&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0x14788b4b in /usr/local/bin/clickhouse
20. ./build_clang/./src/Interpreters/InDepthNodeVisitor.h:46: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, false, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0x1476bf5a in /usr/local/bin/clickhouse
21. ./build_clang/./src/Interpreters/ActionsVisitor.h:187: DB::ExpressionAnalyzer::getRootActions(std::__1::shared_ptr<DB::IAST> const&, bool, std::__1::shared_ptr<DB::ActionsDAG>&, bool) @ 0x1475b9de in /usr/local/bin/clickhouse
22. ./build_clang/./contrib/libcxx/include/__memory/shared_ptr.h:702: DB::SelectQueryExpressionAnalyzer::appendSelect(DB::ExpressionActionsChain&, bool) @ 0x14764bb4 in /usr/local/bin/clickhouse
23. ./build_clang/./src/Interpreters/ExpressionAnalyzer.cpp:0: DB::ExpressionAnalysisResult::ExpressionAnalysisResult(DB::SelectQueryExpressionAnalyzer&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, bool, bool, bool, std::__1::shared_ptr<DB::FilterDAGInfo> const&, std::__1::shared_ptr<DB::FilterDAGInfo> const&, DB::Block const&) @ 0x14768d0e in /usr/local/bin/clickhouse
24. ./build_clang/./src/Interpreters/InterpreterSelectQuery.cpp:804: DB::InterpreterSelectQuery::getSampleBlockImpl() @ 0x14bb1ae6 in /usr/local/bin/clickhouse
25. ./build_clang/./src/Interpreters/InterpreterSelectQuery.cpp:637: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context> 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&, std::__1::shared_ptr<DB::PreparedSets>)::$_1::operator()(bool) const @ 0x14babf03 in /usr/local/bin/clickhouse
26. ./build_clang/./contrib/libcxx/include/__memory/shared_ptr.h:816: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context> 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&, std::__1::shared_ptr<DB::PreparedSets>) @ 0x14ba7efb in /usr/local/bin/clickhouse
27. ./build_clang/./contrib/libcxx/include/optional:237: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<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&) @ 0x14ba5eb1 in /usr/local/bin/clickhouse
28. ./build_clang/./src/Interpreters/InterpreterSelectWithUnionQuery.cpp:247: DB::InterpreterSelectWithUnionQuery::buildCurrentChildInterpreter(std::__1::shared_ptr<DB::IAST> 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&) @ 0x14bea15a in /usr/local/bin/clickhouse
29. ./build_clang/./src/Interpreters/InterpreterSelectWithUnionQuery.cpp:146: DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context>, 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&) @ 0x14be8741 in /usr/local/bin/clickhouse
30. ./build_clang/./contrib/libcxx/include/vector:399: std::__1::__unique_if<DB::InterpreterSelectWithUnionQuery>::__unique_single std::__1::make_unique<DB::InterpreterSelectWithUnionQuery, std::__1::shared_ptr<DB::IAST>&, std::__1::shared_ptr<DB::Context>&, DB::SelectQueryOptions const&>(std::__1::shared_ptr<DB::IAST>&, std::__1::shared_ptr<DB::Context>&, DB::SelectQueryOptions const&) @ 0x14b76153 in /usr/local/bin/clickhouse
31. ./build_clang/./src/Interpreters/InterpreterFactory.cpp:0: DB::InterpreterFactory::get(std::__1::shared_ptr<DB::IAST>&, std::__1::shared_ptr<DB::Context>, DB::SelectQueryOptions const&) @ 0x14b75556 in /usr/local/bin/clickhouse
else
    {
        Field index = (*arguments[1].column)[0];
        executed = matchKeyToIndexNumberConst(keys_data, offsets, index, indices_data)
            || matchKeyToIndexStringConst(keys_data, offsets, index, indices_data);
    }
    if (!executed)
        throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
            "Illegal types of arguments: {}, {} for function {}",
            arguments[0].type->getName(), arguments[1].type->getName(), getName());
    ColumnPtr values_array = ColumnArray::create(values_data.getPtr(), nested_column.getOffsetsPtr());
    if (col_const_map)
        values_array = ColumnConst::create(values_array, input_rows_count);
    
    ColumnsWithTypeAndName new_arguments =
    {
        {
            values_array,
            std::make_shared<DataTypeArray>(result_type),
            ""
        },
        {
            std::move(indices_column),
            std::make_shared<DataTypeNumber<UInt64>>(),
            ""
        }
    };
    return executeImpl(new_arguments, result_type, input_rows_count);
}
String FunctionArrayElement::getName() const