influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Delete data by tag not working

Open mroelandts opened this issue 4 years ago • 13 comments

InfluxDB v2.2.0 (git: a2f8538837) build_date: 2022-04-06T17:36:40Z

Hello, I'm using python to write to the influxdb.

point = influxdb_client.Point('test-measurement')
point.tag('host', 'test-host')
write_api.write(bucket=self._bucket, org=self._org, record=point)

now I would like to also be able to delete a Point with a certain tag and time frame. According to the documentation this is possible: https://docs.influxdata.com/influxdb/v2.2/write-data/delete-data To test this I'm using the influx command from the package "influxdb2-cli"

attempt 1

influx delete --bucket test-bucket  --start '2022-04-15T12:15:04.600Z' --stop '2022-04-15T12:15:13.230Z' --predicate '_measurement="test-measurement" AND host="test-host"'

But this returns a Error: failed to delete data: 400 Bad Request: invalid request; error parsing request json: bad logical expression, at position 32

attempt 2 When losing the tag specification, everything works, but deletes all points between the time frame... (not wanted!)

influx delete --bucket test-bucket  --start '2022-04-15T12:15:04.600Z' --stop '2022-04-15T12:15:13.230Z' --predicate '_measurement="test-measurement"'

attempt 3 When specifying a non-existing the tag, the command succeeds but deletes nothing...

influx delete --bucket test-bucket  --start '2022-04-15T12:15:04.600Z' --stop '2022-04-15T12:15:13.230Z' --predicate '_measurement="test-measurement" AND testing="test-host"'

As attempt 1 and 3 are the same except for the tag name, the 'invalid request comes from the fact that I'm using a tag that exists and things go haywire... Am I doing things wrong or is this indeed a bug?

mroelandts avatar Apr 15 '22 12:04 mroelandts

I can confirm this issue using influxdb2-2.2.0-1.x86_64. This error can also be reproduced using the DeleteWithName API and occurs with a simple 'tag="XXX"' predicate.

rwatler avatar May 11 '22 04:05 rwatler

I can also confirm this. Using: Influx CLI 2.3.0 (git: 88ba346) build_date: 2022-04-06T19:30:53Z

schmidi-dev avatar Jun 02 '22 20:06 schmidi-dev

I can also confirm this using Influx CLI 2.4.0 (git: 5c7c34f).

See here (before I found this issue): https://community.influxdata.com/t/bad-logical-expression-on-deletion-by-tag/27011

Is there any workaround?

sparx82 avatar Oct 18 '22 06:10 sparx82

It seems to work for me: OSS 2.4.0, CLI 2.4.0, Windows

vlastahajek avatar Oct 18 '22 15:10 vlastahajek

@vlastahajek Could you please elaborate a little bit more what tags you have and how you delete the data?

sparx82 avatar Oct 18 '22 15:10 sparx82

I have such test inserts: stat,unit=temperature,level=ok|crit|warn avg=<float>,max=<float> <timestamp> This cmd works flawlessly using both tags, no matter if string literal is surrounded by double quotes: influx delete --start=2022-10-17T13:00:00Z --stop=2022-10-18T13:00:00Z -p "level=warn" -org my-org -b my-bucket -t my-token

Data are generated using Go client:

func main() {
	rand.Seed(132)
	// Create a client
	client := influxdb2.NewClient("http://localhost:8086", "my-token")
	// Get non-blocking write client
	writeApi := client.WriteAPI("my-org", "my-bucket")
	t := time.Now().Add(-time.Hour * 24)
	max := 0.0
	for time.Now().Sub(t) > 0 {
		temp := 20 + (30 * (rand.Float64() - 0.5))
		if temp > max {
			max = temp
		}
		level := "ok"
		if temp > 30 {
			level = "crit"
		} else if temp > 25 {
			level = "warn"
		}
		p := influxdb2.NewPoint("stat",
			map[string]string{"unit": "temperature", "level": level},
			map[string]interface{}{"avg": temp, "max": max},
			t)
		t = t.Add(time.Minute)
		// Write data
		writeApi.WritePoint(p)
	}
	// Close client
	client.Close()
}

vlastahajek avatar Oct 18 '22 19:10 vlastahajek

@vlastahajek Indeed, this works for me as well. I tried to figure out what I'm doing otherwise and as soon as I name the tag key "measurement" it doesn't work again. Now I see that "measurement" is one of the keywords which, I guess, is causing the trouble.

sparx82 avatar Oct 18 '22 20:10 sparx82

Double quote around tag key solved the problem: https://community.influxdata.com/t/bad-logical-expression-on-deletion-by-tag/27011/3

sparx82 avatar Oct 18 '22 20:10 sparx82

InfluxDB v2.2.0 (git: a2f8538) build_date: 2022-04-06T17:36:40Z

Hello, I'm using python to write to the influxdb.

point = influxdb_client.Point('test-measurement')
point.tag('host', 'test-host')
write_api.write(bucket=self._bucket, org=self._org, record=point)

now I would like to also be able to delete a Point with a certain tag and time frame. According to the documentation this is possible: https://docs.influxdata.com/influxdb/v2.2/write-data/delete-data To test this I'm using the influx command from the package "influxdb2-cli"

attempt 1

influx delete --bucket test-bucket  --start '2022-04-15T12:15:04.600Z' --stop '2022-04-15T12:15:13.230Z' --predicate '_measurement="test-measurement" AND host="test-host"'

But this returns a Error: failed to delete data: 400 Bad Request: invalid request; error parsing request json: bad logical expression, at position 32

attempt 2 When losing the tag specification, everything works, but deletes all points between the time frame... (not wanted!)

influx delete --bucket test-bucket  --start '2022-04-15T12:15:04.600Z' --stop '2022-04-15T12:15:13.230Z' --predicate '_measurement="test-measurement"'

attempt 3 When specifying a non-existing the tag, the command succeeds but deletes nothing...

influx delete --bucket test-bucket  --start '2022-04-15T12:15:04.600Z' --stop '2022-04-15T12:15:13.230Z' --predicate '_measurement="test-measurement" AND testing="test-host"'

As attempt 1 and 3 are the same except for the tag name, the 'invalid request comes from the fact that I'm using a tag that exists and things go haywire... Am I doing things wrong or is this indeed a bug?

Same Happening with me also

suryabala0103 avatar Oct 20 '22 12:10 suryabala0103

Attempt1 works for me with 2.4.0. Exact copy, only adjusted time. Which version and commands are you using?

sparx82 avatar Oct 20 '22 21:10 sparx82

I have a similar issue

influx delete --bucket pythontest --start 2022-09-09T00:00:00Z  --stop 2022-09-10T00:00:00Z --predicate  "_measurement= logging-state"

Produces this: Error: failed to delete data: 400 Bad Request: error decoding json body: bad logical expression, at position 21

However, this code works (both logging and logging-state exist).

influx delete --bucket pythontest --start 2022-09-09T00:00:00Z  --stop 2022-09-10T00:00:00Z --predicate  "_measurement= logging"

This occurs using both the python delete.api and influx cli. using Influx CLI 2.5.0 (git: 3285a03) build_date: 2022-11-01T16:32:06Z.

I am unable to figure out a wokraround in python as it requires a predicate. I can delete the data if I remove the predicate from the cli.

dredvard avatar Dec 07 '22 20:12 dredvard

same for me

root@influxdb:/# influx version
Influx CLI 2.6.0 (git: 90e825c) build_date: 2022-12-15T18:46:35Z
root@influxdb:/# influx delete --start '1970-01-01T00:00:00Z' --stop $(date +"%Y-%m-%dT%H:%M:%SZ") --predicate '_measurement="fibaro" and name="motion temp"'
Error: failed to delete data: 400 Bad Request: invalid request; error parsing predicate: found NAME, expected identifier, string, number, bool at line 1, char 27
root@influxdb:/# influx delete --start '1970-01-01T00:00:00Z' --stop $(date +"%Y-%m-%dT%H:%M:%SZ") --predicate '_measurement="fibaro" and anything="motion temp"'
root@influxdb:/#

abalam666 avatar Dec 26 '22 16:12 abalam666

@dredvard You want to escape quote logging-state so that the - is not interpreted as an operator.

influx delete --bucket pythontest --start 2022-09-09T00:00:00Z  --stop 2022-09-10T00:00:00Z --predicate  "_measurement=\"logging-state\""

@abalam666 You also need escape quotes, but around name due to it being a keyword.

root@influxdb:/# influx delete --start '1970-01-01T00:00:00Z' --stop $(date +"%Y-%m-%dT%H:%M:%SZ") --predicate '_measurement="fibaro" and \"name\"="motion temp"'

jeffreyssmith2nd avatar Dec 30 '22 19:12 jeffreyssmith2nd