influxdata / influx-cli

CLI for managing resources in InfluxDB v2
MIT License
61 stars 23 forks source link

influx delete predicate not working #472

Closed Nick135 closed 1 year ago

Nick135 commented 1 year ago

Now I want to delete only certain field values. I don't get an error but the rows are not removed from db.

influx query works:

from(bucket: "mybucket")
|> range(start: -16d, stop: -0s)
|> filter(fn: (r) => r["_measurement"] == "SN001:2" and r["_field"] == "aeff_RMS" and r.SetpointReached=="False")

Result: _result
Table: keys: [_start, _stop, SerialNo, SetpointReached, SpindleSpeed, _field, _measurement, unit]
                   _start:time                      _stop:time  SetpointReached:string           _field:string     _measurement:string                      _time:time                  _value:float
------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------
2023-01-01T12:09:30.593215800Z  2023-01-17T12:09:30.593215800Z                   False                aeff_RMS                 SN001:2 2023-01-01T12:53:54.127250000Z                     0.1149331

cmd.exe

influx delete --bucket "mybucket" --predicate "_measurement=\"SN001:2\" and _field="aeff_RMS" and SetpointReached="False"" --start "2023-12-22T12:09:30.593215800Z" --stop "2023-01-17T12:09:30.593215800Z" -t myToken -o myOrg
jeffreyssmith2nd commented 1 year ago

Can you run the influx delete command with --http-debug and post the results? I think the quoting may be incorrect but that will show the exact payload being sent.

Nick135 commented 1 year ago
2023/01/23 16:56:39
POST /api/v2/delete?bucket=mybucket&org=myOrg HTTP/1.1
Host: localhost:8086
User-Agent: influx/2.6.0 (windows) Sha/90e825c Date/2022-12-15T18:46:35Z
Transfer-Encoding: chunked
Accept: application/json
Authorization: Token myToken
Content-Type: application/json
Accept-Encoding: gzip

a4
{"predicate":"_measurement=\"SN001:2\" and _field=aeff_RMS and SetpointReached=False","start":"2023-12-22T12:09:30.5932158Z","stop":"2023-01-17T12:09:30.5932158Z"}

0

2023/01/23 16:56:39
HTTP/1.1 204 No Content
Content-Length: 0
Date: Mon, 23 Jan 2023 15:56:39 GMT
X-Influxdb-Build: OSS
X-Influxdb-Version: v2.6.0
Nick135 commented 1 year ago

If I escape all string Variales with quoting the command also not work.

influx delete --bucket "mybucket" --predicate "_measurement=\"SN001:2\" and _field=\"aeff_RMS\" and SetpointReached=\"False\"" --start "2023-12-22T12:09:30.593215800Z" --stop "2023-01-17T12:09:30.593215800Z" -t myToken -o myOrg --http-debug
2023/01/23 17:09:02
POST /api/v2/delete?bucket=mybucket&org=myOrg HTTP/1.1
Host: localhost:8086
User-Agent: influx/2.6.0 (windows) Sha/90e825c Date/2022-12-15T18:46:35Z
Transfer-Encoding: chunked
Accept: application/json
Authorization: Token myToken
Content-Type: application/json
Accept-Encoding: gzip

ac
{"predicate":"_measurement=\"SN001:2\" and _field=\"aeff_RMS\" and SetpointReached=\"False\"","start":"2023-12-22T12:09:30.5932158Z","stop":"2023-01-17T12:09:30.5932158Z"}

0

2023/01/23 17:09:02
HTTP/1.1 204 No Content
Content-Length: 0
Date: Mon, 23 Jan 2023 16:09:02 GMT
X-Influxdb-Build: OSS
X-Influxdb-Version: v2.6.0
jeffreyssmith2nd commented 1 year ago

Are you able to share some/all of your data to help reproduce? My initial attempts at replicating are not successful.

Nick135 commented 1 year ago

If helpfull, I can compact the data and share it. Is the old ftp link still active?

jeffreyssmith2nd commented 1 year ago

Yes it is, that would work great

jeffreyssmith2nd commented 1 year ago

Hey @Nick135, sorry for sending you on a bit of wild goose chase here. Due to some implementation specific details, the delete predicates do not support _field based deletion. I should have caught that earlier when looking at your query. The currently supported way to delete specific points is to use Flux to filter the data into a new bucket from() |> filter(.. filter out the bad field ...) |> to(... new bucket ... ). I'm going to close this issue, sorry for the confusion and thanks being helpful in debugging.

https://docs.influxdata.com/influxdb/v2.6/write-data/delete-data/# https://github.com/influxdata/docs-v2/issues/3786

Nick135 commented 1 year ago

@jeffreyssmith2nd: With use of Flux and the to() command, I have the bad fields in two bucket. As I unterstand the docs and my short test, flux send the queried data to the other bucket, but the data are still present in the source bucket.

jeffreyssmith2nd commented 1 year ago

Ah you want to do the inverse. You want to send all the good data to the new bucket and switch to that bucket, deleting the old bucket afterwards.