AWS Timestream:不支持给定的相关子查询

AWS Timestream: Given correlated subquery is not supported

select host, time as currentTime, floor((1 - (
  select sum(measure_value::double)
    from "DendroTimestreamDB"."hostMetrics"
    where cpuMode = 'idle'
    and time <= h.time
    group by host
) / ((
  select sum(measure_value::double)
    from "DendroTimestreamDB"."hostMetrics"
    where cpuMode = 'idle'
    and time <= h.time
    group by host
) + (
  select sum(measure_value::double)
    from "DendroTimestreamDB"."hostMetrics"
    where cpuMode = 'system'
    and time <= h.time
    group by host
) + (
  select sum(measure_value::double)
    from "DendroTimestreamDB"."hostMetrics"
    where cpuMode = 'user'
    and time <= h.time
    group by host
))) * 100) as utilization
from "DendroTimestreamDB"."hostMetrics" h
group by host, time

returns 错误 line 20:3: Given correlated subquery is not supported 但根据 Timestream subquery support

The Timestream query language supports correlated and other subqueries.

列:

cpuMode, host, device, cpuCode, collector, measure_value::double, measure_name, time,

示例数据:

idle, MacBook-Pro.local, -, 0, cpu, 115950.13, cpu_seconds_total, 2021-04-29 13:46:11.000000000

期望的输出:

host, time, utilization

MacBook-Pro.local 2021-04-29 13:47:56.000000000 15

MacBook-Pro.local 2021-04-29 13:47:41.000000000 16

MacBook-Pro.local 2021-04-29 13:47:26.000000000 19

我正在尝试使用公式 (1 - idleTime / totalTime) * 100 计算 CPU 利用率,但显然不支持这些相关子查询。我只需要用不同的方式重写它吗?

在求和子查询中,我试图计算在主查询时间之前接收到的度量值的总和,我正在使用导致查询的行 and time <= h.time 执行此操作是相关的,因此是问题。

非常感谢

我很确定您需要条件聚合。我不能真正遵循逻辑,但组件看起来是这样的:

select host, time as currentTime,
       sum(sum(case when cpuMode = 'idle' then measure_value::double)) over (partition by host order by time)
       sum(sum(case when cpuMode = 'system' then measure_value::double)) over (partition by host order by time)
       sum(sum(case when cpuMode = 'user' then measure_value::double)) over (partition by host order by time)
from "DendroTimestreamDB"."hostMetrics" h
group by host, time