Hello,
I am scratching my head for second day over this problem.
Using InfluxDB 1.8.5
I have data stored in measurement “modbus” in telegraf/autogen. I copied it into modbusdb/autogen via CLI:
use telegraf
SELECT * INTO modbusdb."autogen".modbus FROM modbus
Copying of the data seems ok, InfluxQL queries gives same results but Flux queries returns no data after changing the bucket.
Original(working) flux query:
actual = from(bucket: "telegraf/autogen")
|> range(start: -6mo)
|> filter(fn: (r) => r._measurement == "modbus" and (r._field == "energy_delivered"))
|> filter(fn: (r) => r.name == "something.example.com")
|> window(every: 1mo, period: 1mo)
|> last()
|> group(columns: ["_time", "_start", "_stop", "_value"], mode: "except")
diff = from(bucket: "telegraf/autogen")
|> range(start: -6mo)
|> filter(fn: (r) => r._measurement == "modbus" and (r._field == "energy_delivered"))
|> filter(fn: (r) => r.name == "something.example.com")
|> window(every: 1mo, period: 1mo)
|> last()
|> group(columns: ["_time", "_start", "_stop", "_value"], mode: "except")
|> difference(
nonNegative: false,
columns: ["_value"],
keepFirst: true
)
join(
tables: {actual:actual, diff:diff},
on: ["_time"]
)
|> map(fn: (r) => ({
_time: r._time,
_value1: r._value_actual,
_value2: r._value_diff
}))
Altered flux query:
actual = from(bucket: "modbusdb/autogen")
|> range(start: -6mo)
|> filter(fn: (r) => r._measurement == "modbus" and (r._field == "energy_delivered"))
|> filter(fn: (r) => r.name == "something.example.com")
|> window(every: 1mo, period: 1mo)
|> last()
|> group(columns: ["_time", "_start", "_stop", "_value"], mode: "except")
diff = from(bucket: "modbusdb/autogen")
|> range(start: -6mo)
|> filter(fn: (r) => r._measurement == "modbus" and (r._field == "energy_delivered"))
|> filter(fn: (r) => r.name == "something.example.com")
|> window(every: 1mo, period: 1mo)
|> last()
|> group(columns: ["_time", "_start", "_stop", "_value"], mode: "except")
|> difference(
nonNegative: false,
columns: ["_value"],
keepFirst: true
)
join(
tables: {actual:actual, diff:diff},
on: ["_time"]
)
|> map(fn: (r) => ({
_time: r._time,
_value1: r._value_actual,
_value2: r._value_diff
}))
After trying different things I figured out that maybe the filter r.name == “something.example.com” is causing trouble because even the most simple flux query doesnt work with it. When I remove it than the query starts returning some data. I thought that maybe the “name” keyword is reserved so I copied the data again with:
SELECT *, "name" AS hostname INTO modbusdb."autogen".modbus FROM modbus
but filtering on hostname field behaves the same.
Filtering on name with InfluxQL works without problem.
Has somebody idea what is going on?