You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

InfluxDB按时间排序报错:无法将浮点与字符串类型分组

Flux查询排序报错解决方案

错误原因

你碰到的sort: schema collision: cannot group float and string types together错误,是因为使用无参数的group()会移除所有分组键,导致不同类型的_value(比如数值型的速度、计数,和字符串型的操作员、状态)被合并到同一张表中,而Flux的排序操作要求同表内的列类型必须一致,因此触发冲突。

解决方法

方法一:保留默认分组直接排序

默认情况下,range和filter之后的数据会按_measurement等标签自动分组,每个分组内的_value类型统一,直接排序即可,不需要额外的group()操作:

from(bucket: "plc-metrics")
  |> range(start: 1707288974, stop: 1709794574)
  |> filter(fn: (r) => r._measurement == "PLC_Sim03e162698dc1aa4f-status" or r._measurement == "PLC_Sim03e162698dc1aa4f-total_count" or r._measurement == "PLC_Sim03e162698dc1aa4f-good_count" or r._measurement == "PLC_Sim03e162698dc1aa4f-speed" or r._measurement == "PLC_Sim03e162698dc1aa4f-operator" )
  |> sort(columns: ["_time"])

方法二:转成宽表后排序(适合单时间行展示多指标)

如果需要把不同指标的数值放在同一行展示,可使用pivot将每个_measurement转为单独列,确保列类型一致后再排序:

from(bucket: "plc-metrics")
  |> range(start: 1707288974, stop: 1709794574)
  |> filter(fn: (r) => r._measurement == "PLC_Sim03e162698dc1aa4f-status" or r._measurement == "PLC_Sim03e162698dc1aa4f-total_count" or r._measurement == "PLC_Sim03e162698dc1aa4f-good_count" or r._measurement == "PLC_Sim03e162698dc1aa4f-speed" or r._measurement == "PLC_Sim03e162698dc1aa4f-operator" )
  |> pivot(rowKey: ["_time"], columnKey: ["_measurement"], valueColumn: "_value")
  |> sort(columns: ["_time"])

内容的提问来源于stack exchange,提问作者Jantoma21

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 09:35:23