Passing the list of tags in group function

I am running InfluxDB 2.0 and running many tasks as well and everything is running fine.
I am using the group function in my flux query to group the data based on the tag columns.

sample flux query for my task:

option task = { 
  name: "task_name",
  every: 1h,
  offset: 5m
}

f = (a, b) =>
	(from(bucket: a)
	  |> range(start: -51m)
	  |> filter(fn: (r) => r["_measurement"] == "provided")
	  |> filter(fn: (r) => r["_field"] == "provided")
	  |> max(column: "_value")
	  |> duplicate(as: "_time", column: "_stop")
	  |> window(every: inf)
      |> group(columns: ["tag_name1"]) 
	  |> group(columns: ["tag_name2"]) 
	  |> map(fn: (r) =>
			({
				time: r._time,
				_measurement: "provided",
				_field: "provided",
                                tag_name1: r.tag_name1,
                                tag_name2:r.tag_name2,
				_value: r._value,
			}))
	  |> to(bucket: b, org: "org_name", timeColumn: "time"))
	f(a: "provided", b: "provided")
	f(a: "provided", b: "provided")

It’s working and I am getting the output in different measurements. Here I have used two tag_Columns for grouping the data but I want to use all my tag_columns at once.
I have around 10 tag_columns

I am using the below code for getting all tags

import "influxdata/influxdb/schema"
data = schema.measurementTagKeys(
    bucket: "provided",
    measurement: "provided"
    )
    |> yield(name:"value") 

Now I want to pass all the tag_columns in the group function as a list like below code:

f = (a, b) =>
    	(from(bucket: a)
    	  |> range(start: -51m)
    	  |> filter(fn: (r) => r["_measurement"] == "provided")
    	  |> filter(fn: (r) => r["_field"] == "provided")
    	  |> max(column: "_value")
    	  |> duplicate(as: "_time", column: "_stop")
    	  |> window(every: inf)
          |> group(columns: [all tag column list]) 
    	  |> map(fn: (r) =>
    			({
    				time: r._time,
    				_measurement: "provided",
    				_field: "provided",
                                   all_tag_columns: r.all_tag_columns,
    				_value: r._value,
    			}))
    	  |> to(bucket: b, org: "org_name", timeColumn: "time"))

Is there any way I can achieve the above problem?

Thanks

@Ravikant_Gautam You need to extract the list of tag columns as a scalar array. You can use findColumn() to do this and provide the columns to the group() function.

import "influxdata/influxdb/schema"

tags = schema.measurementTagKeys(bucket: "provided", measurement: "provided" )
  |> findColumn(fn: (key) => true, column: "_value")

f = (a, b) =>
  from(bucket: a)
    |> range(start: -51m)
    |> filter(fn: (r) => r["_measurement"] == "provided")
    |> filter(fn: (r) => r["_field"] == "provided")
    |> max(column: "_value")
    |> duplicate(as: "_time", column: "_stop")
    |> window(every: inf)
    |> group(columns: tags) 
    |> map(fn: (r) => ({
        time: r._time,
        _measurement: "provided",
        _field: "provided",
        all_tag_columns: r.all_tag_columns,
        _value: r._value,
    }))
    |> to(bucket: b, org: "org_name", timeColumn: "time")
1 Like

@scott I tried the same providing all the field but its giving the error

type error @14:8-14:28: string is not Record (argument columns)
import "influxdata/influxdb/schema"

tags = schema.measurementTagKeys(bucket: "provided", measurement: "provided" )
  |> findColumn(fn: (key) => true, column: "_value")

f = (a, b) =>
  from(bucket: a)
    |> range(start: -51m)
    |> filter(fn: (r) => r["_measurement"] == "provided")
    |> filter(fn: (r) => r["_field"] == "provided")
    |> max(column: "_value")
    |> duplicate(as: "_time", column: "_stop")
    |> window(every: inf)
    |> group(columns: tags) 
    |> map(fn: (r) => ({
        time: r._time,
        _measurement: "provided",
        _field: "provided",
        all_tag_columns: r.all_tag_columns,
        _value: r._value,
    }))
    |> to(bucket: b, org: "org_name", timeColumn: "time")

above code is giving the error |> group(columns: tags) at this line.