influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.65k stars 3.54k forks source link

regexp support look-around, including look-ahead and look-behind #23621

Closed ZeroSean closed 2 years ago

ZeroSean commented 2 years ago

Proposal: use string regexp to filter metrics record, for example: from(bucket: "tsdb_mysql") |> range(start: 2022-08-10T06:50:00Z, stop: 2022-08-10T07:15:00Z) |> filter(fn: (r) => (r._measurement == "mysql_global_status_queries" and r._field == "value") and r.hostname !~ /mgb-test(?!da01-dba|dp01-dba).*/)

Current behavior: occured errror: compilation failed: error @12:117-12:266: regex parse error: mgb-test(?!da01-dba|dp01-dba).* error: look-around, including look-ahead and look-behind, is not supported

Desired behavior: flux string regexp support look-around, including look-ahead and look-behind.

sanderson commented 2 years ago

@ZeroSean The Flux regexp implementation is built on top of the Go regexp implementation, which does not support look-around, look-ahead, or look-behind expressions. This is done for performance reasons. Because this is more of a Flux issue rather than an InfluxDB issue, I'm going to go ahead and close this issue.

You may consider opening a feature request on the Flux repo to add support for these expressions in the regexp implementation, but just know that this implementation was a conscious decision due to the performance impact of these types of expressions.