Databricks windows 使用 sql 分组

Databricks windows group by using sql

我无法找到如何将 pyspark window 语句转换为等效的 SQL 格式。

示例:

  eventsDF \
    .groupBy(
      "deviceId",
      window("eventTime", "10 minutes", "5 minutes")) \
    .count()

应该是这样的:

   select window, deviceId, count(deviceId)
   from events
   group by window eventTime 10 minutes 5 minutes, deviceId

我认为以下查询的结果是您所期望的:

select deviceId, count(deviceId)
from events
group by `eventTime`, `10 minutes`,  `5 minutes`, `deviceId`

group by 将对所有 windows 您期望的行进行分组

您需要修正一些语法错误。 window 应该用括号括起来。

select
    window(eventTime, '10 minutes', '5 minutes'),
    deviceId,
    count(deviceId)
from events
group by
    window(eventTime, '10 minutes', '5 minutes'),
    deviceId