When counting distinct value of a datetime it produces an integer. That value when used in a downstream group by is wrongly interpreted (and casted) as a datetime.
I would expect that i would be correctly interpreted as an integer. Anything I'm missing here ?