InfluxDB v2.6.1 (git: 9dcf880fe0) build_date: 2022-12-29T15:53:07Z
Hi~
I found something strange when I use conditional expressions to handle zero divide。
When I ran below query without divide operation,the result _value returned as expected(0->-1 or the origin value)
from(bucket: "cams_http_detect")
|> range(start: 2023-02-06T19:52:18.309Z, stop: 2023-02-07T07:52:18.309Z)
|> filter(fn: (r) => r["name"] == "system1")
|> filter(fn: (r) => r["_measurement"] == "http_metric" )
|> filter(fn: (r) => r["_field"] == "response_length" or r["_field"] == "response_time")
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> map(
fn: (r) => ({
_start:r._start,
_stop:r._stop,
_time: r._time,
node:r.node,
access_url:r.access_url,
_measurement: r._measurement,
_field: "download_speed",
_value: if r.response_time == 0 then -1 else r.response_time,
}),
)
|>drop(columns: ["response_length", "response_time"])
|>group(columns:["_field","_start","_stop","_measurement","access_url","node"])
But after adding divide operation,the query run failed with zero divide error。
from(bucket: "cams_http_detect")
|> range(start: 2023-02-06T19:52:18.309Z, stop: 2023-02-07T07:52:18.309Z)
|> filter(fn: (r) => r["name"] == "system1")
|> filter(fn: (r) => r["_measurement"] == "http_metric" )
|> filter(fn: (r) => r["_field"] == "response_length" or r["_field"] == "response_time")
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> map(
fn: (r) => ({
_start:r._start,
_stop:r._stop,
_time: r._time,
node:r.node,
access_url:r.access_url,
_measurement: r._measurement,
_field: "download_speed",
_value: if r.response_time == 0 then -1 else r.response_length/r.response_time,
}),
)
|>drop(columns: ["response_length", "response_time"])|>group(columns:["_field","_start","_stop","_measurement","access_url","node"])
Error: failed to execute query: 400 Bad Request: runtime error: cannot divide by zero
So where is the problem in my query?
Thanks in advance.