Aggregate measurement with tasks

Hey guys I am new to InfluxDB having trouble wrapping my head around writing the right query for my task. below is a sudo of what i am trying to achieve:
Get points filtered by { task window (every 30m), measurement (“measurement name”) }

Aggregate points by a particular tag ( “location”)

Reduce locations found to one record per distinct location with a _field(count ) updated to the occurrence of said location.

Write into downsample bucket.

Managed to build a query that does what I expect
aggregate based on distinct tag and perform sum function on the value of a particular _field. Here is the flux representation :
from(bucket: “test-bucket”)
|> range(start: -100w)
|> filter(fn: (r) => r._measurement == “CLICK”)
|> filter(fn: (r) => r._field == “count” )
|> aggregateWindow( every: 1h, fn: sum, createEmpty: false )
|> sum()

Theres one tiny problem writing to the downsampled bucket [.to( downsampleBucket, orgName )
(flux-dsl java)]seems to just write all the data in the previous bucket @Anaisdg can you help :slight_smile:

Hello @williamxo,
Welcome!
Sorry for the delay!
I’m happy you were able to find the flux query.

from(bucket: “test-bucket”)
|> range(start: -100w)
|> filter(fn: (r) => r._measurement == “CLICK”)
|> filter(fn: (r) => r._field == “count” )
|> aggregateWindow( every: 1h, fn: sum, createEmpty: false )
|> sum()
|> yield(name: "results to write")
|> to(bucket: "downsampleBucket")

you can use the yield() function to verify that you’re writing the data you expect to write before the yield function.
I would expect to see x number of tables for x tags and one record in each table.

1 Like

Works like a charm. Thanks :slight_smile:

1 Like