**How to check**
```
CREATE TABLE test_local on cluster '{cluster}' (number UInt64) ENGINE = MergeTree() ORDER BY number;
CREATE TABLE test_distruted (number UInt64) ENGINE = Distributed('{cluster}', currentDatabase(), test_local);

INSERT INTO test_local SELECT number from system.numbers limit 3;

select number from test_distruted order by toDateTime(number) DESC;
```

Without distributed table (only merge tree) it work's correctly

**Versions**
21.12.4 - ok
22.2.3 - ok
22.3.2 - not ok
metadata.partition_key = KeyDescription::buildEmptyKey();
    const auto & query_select = result.query_ast->as<const ASTSelectQuery &>();
    if (select.hasAggregation())
    {
        if (query.orderBy())
            throw Exception(
                "When aggregation is used in projection, ORDER BY cannot be specified", ErrorCodes::ILLEGAL_PROJECTION);
        result.type = ProjectionDescription::Type::Aggregate;
        if (const auto & group_expression_list = query_select.groupBy())
        {
            ASTPtr order_expression;
            if (group_expression_list->children.size() == 1)
            {
                result.key_size = 1;
                order_expression = std::make_shared<ASTIdentifier>(group_expression_list->children.front()->getColumnName());
            }
            else
            {
                auto function_node = std::make_shared<ASTFunction>();
                function_node->name = "tuple";
                function_node->arguments = group_expression_list->clone();
                result.key_size = function_node->arguments->children.size();
                for (auto & child : function_node->arguments->children)
                    child = std::make_shared<ASTIdentifier>(child->getColumnName());
                function_node->children.push_back(function_node->arguments);
                order_expression = function_node;
            }
            auto columns_with_state = ColumnsDescription(result.sample_block.getNamesAndTypesList());
            metadata.sorting_key = KeyDescription::getSortingKeyFromAST(order_expression, columns_with_state, query_context, {});
            metadata.primary_key = KeyDescription::getKeyFromAST(order_expression, columns_with_state, query_context);