【问题标题】:AWS Timestream: Given correlated subquery is not supportedAWS Timestream:不支持给定的相关子查询
【发布时间】:2021-07-24 06:32:12
【问题描述】:
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

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

Timestream 查询语言支持相关子查询和其他子查询。

列:

cpu模式, 主持人, 设备, 处理器代码, 集电极, measure_value::double, 测量名称, 时间,

样本数据:

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

期望的输出:

主持人, 时间, 利用率

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 &lt;= h.time 行来执行此操作,从而使查询相互关联,因此问题。

非常感谢

【问题讨论】:

  • 请提供样本数据、预期结果和逻辑解释。

标签: sql amazon-web-services time-series amazon-timestream


【解决方案1】:

我很确定您想要条件聚合。我无法真正遵循逻辑,但组件似乎是这样的:

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

【讨论】:

  • 这正是我所需要的!谢谢
猜你喜欢
  • 2022-08-03
  • 2021-07-14
  • 2021-12-16
  • 1970-01-01
  • 2021-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-03
相关资源
最近更新 更多