```sql
SELECT toStartOfHour(time) AS timex, id, count()
FROM
(
    SELECT
        concat('id', toString(number % 3)) AS id,
        toDateTime('2020-01-01') + (number * 60) AS time
    FROM numbers(100)
)
GROUP BY
    GROUPING SETS ( (timex, id), (timex))
ORDER BY timex ASC;

Received exception from server (version 22.5.1):
Code: 215. DB::Exception: Received from localhost:9000. 
DB::Exception: Column `time` is not under aggregate function and not in GROUP BY: 
While processing time ASC. (NOT_AN_AGGREGATE)
```
if (implicit_distinct.empty())
            return {};
    }
    
    for (const auto & id : select.select()->children)
    {
        String alias = id->tryGetAlias();
        if (const auto * identifier = id->as<ASTIdentifier>())
        {
            const String & name = identifier->shortName();
            if (select.distinct || implicit_distinct.contains(name))
            {
                if (alias.empty())
                    names.insert(name);
                else
                    names.insert(alias);
            }
        }
        else if (select.distinct && !alias.empty())
        {
            
            names.insert(alias);
        }
    }
    
    if (!select.distinct && names.size() != implicit_distinct.size())
        return {};
    return names;
}
void optimizeDuplicateDistinct(ASTSelectQuery & select)