Continuous queries in Influxdb ignoring where clause?

无人久伴 提交于 2020-01-17 05:15:42

问题


I'm having a bit of a trouble with the continuous queries in influxdb 0.8.8. I'm trying to create a continuous query but it seems that the where clauses are ignored. I'm aware about the restrictions mentioned here: http://influxdb.com/docs/v0.8/api/continuous_queries.html but I don't consider that this would be the case here.

One row in the time series would contain data like this:

{"hex":"06a0b6", "squawk":"3421", "flight":"QTR028  ", "lat":99.867630, "lon":66.447365, "validposition":1, "altitude":39000,  "vert_rate":-64,"track":125, "validtrack":1,"speed":482, "messages":201, "seen":219}

The query I'm running and works is the following:

select * from flight_series where time > now() - 30m and flight !~ /^$/ and validtrack = 1 and validposition = 1;

Trough it I'm trying to take the last 30 minutes from the current time, check that the flight field is no whitespaces and that the track/position are valid. The query returns successfully but when I'm adding the

into filtered_log

part the 'where' clause is ignored.

How can I create a continuous query which takes the above-mentioned conditions into consideration? At least, how could I extract with one continuous query only the rows which have the valid track/heading set to 1 and the flight is not whitespace/empty string? The time constraint I could eliminate from the query and translate into shard retention/duration.

Also, could I specify to in the continuous query to save the data into a time-series which is located into another database (which has a more relaxed retention/duration policy)?

Thank you!

Later edit:

I've managed to do something closer to my need by using the following cq:

"select time, sequence_number, altitude, vert_rate, messages, squawk, lon, lat, speed, hex, seen from current_flights where ((flight !~ /^$/) AND (validtrack = 1)) AND (validposition = 1) into flight.[flight]"

This creates a series for each 'flight' even for those which have a whitespace in the 'flight' field -- for which a flight. series is built.

How could I specify the retention/duration policies for the series generated by the cq above? Can I do something like:

"spaces": [
    {
      "name": "flight",
      "retentionPolicy": "1h",
      "shardDuration": "30m",
      "regex": "/.*/",
      "replicationFactor": 1,
      "split": 1
    },
 ...

which would give me a retention of 1h and shard duration of 30m?

I'm a bit confused about where those series are stored, which shard space?

Thanks!

P.S.: My final goal would be the following: Have a 'window' of 15-30min max with all the flights around, process some data from them and after that period is over discard the data but in the same time move/copy it to another long-term db/series which can be used for historical purposes.


回答1:


You cannot put time restrictions into the WHERE clause of a continuous query. The server will generate the time restrictions as needed when the CQ runs and must ignore all others. I suspect if you leave out the time restriction the rest of the WHERE clause will be fine.

I don't believe CQs in 0.8 require an aggregation in the SELECT, but you do need to have GROUP BY clause to tell the CQ how often to run. I'm not sure what you would GROUP BY, perhaps the flight?

You can specify a different retention policy when writing to the new series but not a new database. In 0.8 the retention policy for a series is determined by regex matching on the series name. As long as you select a series name correctly it will go into your desired retention policy.

EDIT: updates for new questions

How could I specify the retention/duration policies for the series generated by the cq above?

In 0.8.x, the shard space to which a series belongs controls the retention policy. The regex on the shard space determines which series belong to that shard. The shard space regex is evaluated newest to oldest, meaning the first created shard space will be the last regex evaluated. Unfortunately, I do know if it is possible to create new shard spaces once the database exists. See this discussion on the mailing list for more: https://groups.google.com/d/msgid/influxdb/ce3fc641-fbf2-4b39-9ce7-77e65c67ea24%40googlegroups.com

Can I do something like:

"spaces": [ { "name": "flight", "retentionPolicy": "1h", "shardDuration": "30m", "regex": "/.*/", "replicationFactor": 1, "split": 1 }, ... which would give me a retention of 1h and shard duration of 30m?

That shard space would have a shard duration of 30 minutes, retaining data for 1 hour, meaning any series would only exist in three shards, the current hot shard, the current cold shard, and the shard waiting for deletion.

The regex is /./, meaning it would match any series, not just the 'flight.' series. Perhaps /flight../ is a better regex if you only want those series generated by the CQ in that shard space.



来源:https://stackoverflow.com/questions/30579608/continuous-queries-in-influxdb-ignoring-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!