infuxdb子查询中的子句

发布于 2025-02-07 23:34:12 字数 1409 浏览 1 评论 0原文

有一些问题将我的大脑围绕着这个问题。我在infuxdb 1.8.x中有两个表,这是相关的数据布局,

table a
-------------------------------------------
|time               |hostname|device_cache|
|6/14/2022 9:00:30PM|device1 |dm-4        |
|6/14/2022 9:00:30PM|device2 |dm-4        |
|6/14/2022 9:00:30PM|device3 |dm-8        |
-------------------------------------------

table b
-----------------------------------------------------
|time               |hostname|diskiodevice|diskiola1|
|6/14/2022 9:00:30PM|device1 |dm-0        |8        | 
|6/14/2022 9:00:30PM|device1 |dm-4        |7        |
|6/14/2022 9:00:30PM|device3 |dm-3        |9        |
|6/14/2022 9:00:30PM|device2 |dm-2        |8        |
|6/14/2022 9:00:30PM|device3 |dm-8        |15       |
|6/14/2022 9:00:30PM|device2 |dm-4        |9        |
|6/14/2022 9:00:30PM|device3 |dm-3        |1        |
-----------------------------------------------------

因此,我要做的是从表B中获取diskiola1值的所有diskiola1值,这些diskiola1值从表B中从表a定义为特定hostname输入的表A的device_cache项目。这是我尝试的:

SELECT max("diskiola1")
FROM "table b"
WHERE hostname = 'device1'
AND
time > now() - 10m
AND
"cache_device" IN
( Select distinct("device_cache") as "cache_device" FROM "table a" WHERE hostname = 'device1')
GROUP BY time(20s)

我的目标是将其作为图表中的时间序列,以在一段时间内仅用于设备_CACHE项目,以显示给定主机的diskiola1值。这些数据是给我使用的,我真的无法修改它。

有人看到我出了什么问题吗?我收到的错误是 err:错误解析查询:发现,预期;

Having some issues wrapping my brain around this one. I have two tables in InfluxDB 1.8.x, here's the relevant data layout

table a
-------------------------------------------
|time               |hostname|device_cache|
|6/14/2022 9:00:30PM|device1 |dm-4        |
|6/14/2022 9:00:30PM|device2 |dm-4        |
|6/14/2022 9:00:30PM|device3 |dm-8        |
-------------------------------------------

table b
-----------------------------------------------------
|time               |hostname|diskiodevice|diskiola1|
|6/14/2022 9:00:30PM|device1 |dm-0        |8        | 
|6/14/2022 9:00:30PM|device1 |dm-4        |7        |
|6/14/2022 9:00:30PM|device3 |dm-3        |9        |
|6/14/2022 9:00:30PM|device2 |dm-2        |8        |
|6/14/2022 9:00:30PM|device3 |dm-8        |15       |
|6/14/2022 9:00:30PM|device2 |dm-4        |9        |
|6/14/2022 9:00:30PM|device3 |dm-3        |1        |
-----------------------------------------------------

So, what I am trying to do is get all the diskiola1 values for the diskiodevices from table b that are defined as device_cache items from table a for a particular hostname entry. Here's what I've tried:

SELECT max("diskiola1")
FROM "table b"
WHERE hostname = 'device1'
AND
time > now() - 10m
AND
"cache_device" IN
( Select distinct("device_cache") as "cache_device" FROM "table a" WHERE hostname = 'device1')
GROUP BY time(20s)

My goal is to have this as a time series in a graph to show the values of diskiola1 for a given host over a period of time for only the device_cache items. This data is given to me to work with, I really can't modify it unfortunately.

Anyone see where I'm going wrong? The error I receive is
ERR: error parsing query: found IN, expected ;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝影如岚 2025-02-14 23:34:12

不幸的是,InfuxQl不支持操作员或可预见的将来(请参阅详细信息在这里。 InfluxQl也不支持加入操作(请参阅详细信息 >)。

似乎您的“ table_a”更像是映射表,而“ table_b”实际上存储了时间序列数据。假设主机名是标签,而device_cache是​​“表A”的字段;主机名是标签,而diskiodevice和diskiola1是“表B”的字段。您可以尝试启用flux 并尝试以下示例代码

aDistinctDeviceCache = from(bucket:"yourDatabaseName/yourRentionPolicyName")
|> range(start: 2018-05-22T23:30:00Z, stop: 2018-05-23T00:00:00Z)   // start and stop can be changed
|> filter(fn:(r) => r._measurement == "table a" and r.hostname == "device1" and r._field == "device_cache")
|> distinct()

bDevice1 = from(bucket:"yourDatabaseName/yourRentionPolicyName")
|> range(start: -10m)
|> filter(fn:(r) => r._measurement == "table b" and r.hostname == "device1")
|> rename(columns: {diskiodevice: "device_cache"})

maxDiskiola1ForDevice1 = 
join(tables:{aPlus:aDistinctDeviceCache, bPlus:bDevice1}, on:["hostname", "device_cache"])
|> window(every: 20s)
|> max("diskiola1")
|> yield()

:首先从“ table_a”中获取不同的值,然后重命名“ table_b”的某些字段,以便我们可以在最后一步中将两个表连接在一起。

以下是一些更多提示,可以转换您的流向通量并转换您的 subquies

Unfortunately InfluxQL doesn't support IN operator or for the foreseeable future (see details here). InfluxQL doesn't support JOIN operation either (see details here).

Seems your "table_a" is more like a mapping table while "table_b" is storing the time series data actually. Assuming hostname is a tag while device_cache is a field for "table a"; hostname is a tag while diskiodevice and diskiola1 are fields for "table b". You could try enabling Flux and try following sample codes:

aDistinctDeviceCache = from(bucket:"yourDatabaseName/yourRentionPolicyName")
|> range(start: 2018-05-22T23:30:00Z, stop: 2018-05-23T00:00:00Z)   // start and stop can be changed
|> filter(fn:(r) => r._measurement == "table a" and r.hostname == "device1" and r._field == "device_cache")
|> distinct()

bDevice1 = from(bucket:"yourDatabaseName/yourRentionPolicyName")
|> range(start: -10m)
|> filter(fn:(r) => r._measurement == "table b" and r.hostname == "device1")
|> rename(columns: {diskiodevice: "device_cache"})

maxDiskiola1ForDevice1 = 
join(tables:{aPlus:aDistinctDeviceCache, bPlus:bDevice1}, on:["hostname", "device_cache"])
|> window(every: 20s)
|> max("diskiola1")
|> yield()

This will first grab distinct values from "table_a" and then rename some field of "table_b" so that we can join the two tables together in the last step.

Here are some more tips to convert your InfluxQL to Flux and convert your subqueries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文