我在 Spark SQL 中有一个查询,例如
select count(ts), truncToHour(ts)
from myTable
group by truncToHour(ts).
其中ts
是时间戳类型,truncToHour
是将时间戳截断为小时的 UDF。此查询不起作用。如果我尝试,
select count(ts), ts from myTable group by truncToHour(ts)
我得到了expression 'ts' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() if you don't care which value you get.;
,但first()
如果我这样做没有定义:
select count(ts), first(ts) from myTable group by truncToHour(ts)
无论如何要在不使用子查询的情况下获得我想要的东西?另外,为什么它说“wrap in first()”但first()
没有定义?