**Describe what's wrong**

if the first column in sorting key contains function, `DISTINCT` query with the same column will fail
Example:
<pre>
CREATE TABLE t
(
    `datetime` DateTime,
    `a` UInt64
)
ENGINE = MergeTree
ORDER BY <b>toDate(datetime)</b>;
INSERT INTO t FORMAT Values ('2000-01-01', 1);
SELECT DISTINCT <b>toDate(datetime)</b> FROM t;
</pre>

**Does it reproduce on recent release?**
Yes, version 22.10.1.15995 (official build)

**Stack**
```
Code: 49. DB::Exception: Sort description can't be empty when reading in order. (LOGICAL_ERROR), Stack trace (when copying this message, always include the lines below):

0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0x78fd3ba in /usr/bin/clickhouse
1. DB::ReadFromMergeTree::requestReadingInOrder(unsigned long, int, unsigned long) @ 0x1337fc67 in /usr/bin/clickhouse
2. DB::QueryPlanOptimizations::tryDistinctReadInOrder(DB::QueryPlan::Node*, std::__1::list<DB::QueryPlan::Node, std::__1::allocator<DB::QueryPlan::Node> >&) @ 0x133ce567 in /usr/bin/clickhouse
3. DB::QueryPlanOptimizations::optimizeTree(DB::QueryPlanOptimizationSettings const&, DB::QueryPlan::Node&, std::__1::list<DB::QueryPlan::Node, std::__1::allocator<DB::QueryPlan::Node> >&) @ 0x133c78a8 in /usr/bin/clickhouse
4. DB::QueryPlan::buildQueryPipeline(DB::QueryPlanOptimizationSettings const&, DB::BuildQueryPipelineSettings const&) @ 0x13360731 in /usr/bin/clickhouse
5. DB::InterpreterSelectWithUnionQuery::execute() @ 0x120ef7e6 in /usr/bin/clickhouse
6. ? @ 0x123ea4eb in /usr/bin/clickhouse
7. DB::executeQuery(DB::ReadBuffer&, DB::WriteBuffer&, bool, std::__1::shared_ptr<DB::Context>, std::__1::function<void (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> > const&, 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> > const&)>, std::__1::optional<DB::FormatSettings> const&) @ 0x123ef213 in /usr/bin/clickhouse
8. DB::HTTPHandler::processQuery(DB::HTTPServerRequest&, DB::HTMLForm&, DB::HTTPServerResponse&, DB::HTTPHandler::Output&, std::__1::optional<DB::CurrentThread::QueryScope>&) @ 0x12f5ba4e in /usr/bin/clickhouse
9. DB::HTTPHandler::handleRequest(DB::HTTPServerRequest&, DB::HTTPServerResponse&) @ 0x12f60870 in /usr/bin/clickhouse
10. DB::HTTPServerConnection::run() @ 0x12fdbaaa in /usr/bin/clickhouse
11. Poco::Net::TCPServerConnection::start() @ 0x15a7342f in /usr/bin/clickhouse
12. Poco::Net::TCPServerDispatcher::run() @ 0x15a757bb in /usr/bin/clickhouse
13. Poco::PooledThread::run() @ 0x15c30d52 in /usr/bin/clickhouse
14. Poco::ThreadImpl::runnableEntry(void*) @ 0x15c2e4dd in /usr/bin/clickhouse
15. ? @ 0x7fcced143609 in ?
16. clone @ 0x7fcced068133 in ?
 (version 22.10.1.15995 (official build))
```

**Expected behavior**
No error occurs
while (!node->children.empty())
    {
        auto * step = dynamic_cast<ITransformingStep *>(node->step.get());
        if (!step)
            return 0;
        const ITransformingStep::DataStreamTraits & traits = step->getDataStreamTraits();
        if (!traits.preserves_sorting)
            return 0;
        steps2update.push_back(step);
        node = node->children.front();
    }
    
    auto * read_from_merge_tree = typeid_cast<ReadFromMergeTree *>(node->step.get());
    if (!read_from_merge_tree)
        return 0;
    
    const ColumnsWithTypeAndName & distinct_columns = pre_distinct->getOutputStream().header.getColumnsWithTypeAndName();
    std::set<std::string_view> non_const_columns;
    for (const auto & column : distinct_columns)
    {
        if (!isColumnConst(*column.column))
            non_const_columns.emplace(column.name);
    }
    const Names& sorting_key_columns = read_from_merge_tree->getStorageMetadata()->getSortingKeyColumns();
    
    size_t number_of_sorted_distinct_columns = 0;
    for (const auto & column_name : sorting_key_columns)
    {
        if (non_const_columns.end() == non_const_columns.find(column_name))
            break;