Prashant
Prashant

Reputation: 1064

Downsampled continuous queries with subset of tags

Influxdb 0.9 documentation gives an example of preserving all tags on a Continuous Query (CQ) by simply doing GROUP BY time(<some interval>), *

Is there a way to preserve a subset of tags that I might be interested in from the original set?

For example if I have measurement_a: with tags: tag_1, tag_2, tag_3 and field: field_1

and I'd like to create a CQ that selects from measurement_a and inserts INTO measurement_cq_a with just tag_a. What would the syntax be?

I tried

CREATE CONTINUOUS QUERY measurement_cq_a ON metrics BEGIN SELECT SUM(value) as sum_val, tag_a INTO "measurement_cq_a" FROM "measurement_a" WHERE time > now() - 1h GROUP BY time(5m), tag_a END

But that causes influx to crash with an "index out of range" error/panic.

panic: runtime error: index out of range

goroutine 23 [running]:
github.com/influxdb/influxdb/services/continuous_querier.(*Service).convertRowToPoints(0xc208010310, 0xc210207dd0, 0x21, 0xc21045f3e0, 0x0, 0x0
, 0x0, 0x0, 0x0)
        /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/services/continuous_querier/service.go:349 +0x6ec
github.com/influxdb/influxdb/services/continuous_querier.(*Service).runContinuousQueryAndWriteResult(0xc208010310, 0xc20c5f4240, 0x0, 0x0)
        /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/services/continuous_querier/service.go:287 +0x2f4
github.com/influxdb/influxdb/services/continuous_querier.(*Service).ExecuteContinuousQuery(0xc208010310, 0xc2101b52c0, 0xc210214460, 0x0, 0x0)
        /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/services/continuous_querier/service.go:256 +0xb0f
github.com/influxdb/influxdb/services/continuous_querier.(*Service).runContinuousQueries(0xc208010310)
        /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/services/continuous_querier/service.go:178 +0x32a
github.com/influxdb/influxdb/services/continuous_querier.(*Service).backgroundLoop(0xc208010310)
        /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/services/continuous_querier/service.go:160 +0x1d8
created by github.com/influxdb/influxdb/services/continuous_querier.(*Service).Open
        /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/services/continuous_querier/service.go:87 +0x1ed

I'm testing this on Influx 0.9.0

Upvotes: 4

Views: 2551

Answers (1)

Prashant
Prashant

Reputation: 1064

Just fyi for other folks on my silly mistake.

The correct query to run seems to be: CREATE CONTINUOUS QUERY measurement_cq_a ON metrics BEGIN SELECT SUM(value) as sum_val INTO "measurement_cq_a" FROM "measurement_a" WHERE time > now() - 1h GROUP BY time(5m), tag_a END

I was trying (WRONG):

CREATE CONTINUOUS QUERY measurement_cq_a ON metrics BEGIN SELECT SUM(value) as sum_val, **tag_a** INTO "measurement_cq_a" FROM "measurement_a" WHERE time > now() - 1h GROUP BY time(5m), tag_a END

NOTE: For folks wondering .. I need the WHERE clause in my queries because of a bug in 0.9.0. I think this was fixed in 0.9.1

Upvotes: 4

Related Questions