How can I rearrange (pivot ?) my data to display it in Stacked Colored Bars?

Hello,

I’m using Grafana 9.3.1 deployed on a Linux machine.
I’m submitting JUnit test performances to an InfluxDB server, and from there I visualize the data in Grafana.
Every time I start a session of tests, I use a distinct JobID (marked as field “Job”).
For each Job, I run several classes that all extend the same parent class (and thus run the same methods, but just with different workload).
Entries in the InfluxDB contain basically everything there is to know, including: JobID, ClassName, MethodName, Execution Duration.

At the end of this post I included a sample of such data: 5 executions (5 Jobs), 3 classes each time.

What I have until now:

Here is the query that I run:

from(bucket: "myBucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "Test" and r._field == "Duration" and r["Method"] =~ /${Method:regex}/ and r.Branch =~ /${Branch:regex}/)
  |> group(columns: ["Job"])

This screenshot attachment shows how I see that data in Grafana, after I configured a Bar Chart visualization (with Stacking set to Normal).

So for a specific method, I have one “entry” for each Job execution (each entry colored differently).
One entry = one bar for each class that executed the method.

What I need to do next: rearrange the data, so that for each “Job Execution” I get one stacked colored bar, that would include several different colors, one color for each class.

I had some attempts using pivot but I could not understand exactly what I should pivot and how.

Any help at this point would be much appreciated.

Thank you.

Here is the sample .csv data that I obtain when I run the query directly in InfluxDB

#group,false,false,true,true,false,false,false,false,false,true,false,false,false,false
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string,string,string,string,string,string
#default,_result,,,,,,,,,,,,,
,result,table,_start,_stop,_time,_value,Branch,Classname,Commit,Job,Method,Pipeline,_field,_measurement
,,0,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T11:00:03.463Z,7404,SampleBranch,mycompany.MyTests$My50Tests,AnotherCommit,DEV_JOB_2024-02-16T10:59:52.118821900Z,testedOperation,DEV_PIPELINE_2024-02-16T10:59:52.111876200Z,Duration,Test
,,0,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T10:59:52.758Z,3195,SampleBranch,mycompany.MyTests$My10Tests,AnotherCommit,DEV_JOB_2024-02-16T10:59:52.118821900Z,testedOperation,DEV_PIPELINE_2024-02-16T10:59:52.111876200Z,Duration,Test
,,0,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T11:00:29.554Z,23448,SampleBranch,mycompany.MyTests$My200Tests,AnotherCommit,DEV_JOB_2024-02-16T10:59:52.118821900Z,testedOperation,DEV_PIPELINE_2024-02-16T10:59:52.111876200Z,Duration,Test
,,1,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T11:12:05.413Z,7374,SampleBranch,mycompany.MyTests$My50Tests,AnotherCommit,DEV_JOB_2024-02-16T11:11:53.851304700Z,testedOperation,DEV_PIPELINE_2024-02-16T11:11:53.845506400Z,Duration,Test
,,1,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T11:12:31.45Z,23486,SampleBranch,mycompany.MyTests$My200Tests,AnotherCommit,DEV_JOB_2024-02-16T11:11:53.851304700Z,testedOperation,DEV_PIPELINE_2024-02-16T11:11:53.845506400Z,Duration,Test
,,1,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T11:11:54.536Z,3134,SampleBranch,mycompany.MyTests$My10Tests,AnotherCommit,DEV_JOB_2024-02-16T11:11:53.851304700Z,testedOperation,DEV_PIPELINE_2024-02-16T11:11:53.845506400Z,Duration,Test
,,2,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T11:57:55.393Z,3234,SampleBranch,mycompany.MyTests$My10Tests,AnotherCommit,DEV_JOB_2024-02-16T11:57:54.757507400Z,testedOperation,DEV_PIPELINE_2024-02-16T11:57:54.751217600Z,Duration,Test
,,2,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T11:58:06.193Z,7369,SampleBranch,mycompany.MyTests$My50Tests,AnotherCommit,DEV_JOB_2024-02-16T11:57:54.757507400Z,testedOperation,DEV_PIPELINE_2024-02-16T11:57:54.751217600Z,Duration,Test
,,2,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T11:58:32.794Z,23463,SampleBranch,mycompany.MyTests$My200Tests,AnotherCommit,DEV_JOB_2024-02-16T11:57:54.757507400Z,testedOperation,DEV_PIPELINE_2024-02-16T11:57:54.751217600Z,Duration,Test
,,3,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T12:44:05.54Z,23564,SampleBranch,mycompany.MyTests$My200Tests,AnotherCommit,DEV_JOB_2024-02-16T12:43:27.433103200Z,testedOperation,DEV_PIPELINE_2024-02-16T12:43:27.427725500Z,Duration,Test
,,3,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T12:43:28.206Z,3122,SampleBranch,mycompany.MyTests$My10Tests,AnotherCommit,DEV_JOB_2024-02-16T12:43:27.433103200Z,testedOperation,DEV_PIPELINE_2024-02-16T12:43:27.427725500Z,Duration,Test
,,3,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T12:43:39.174Z,7419,SampleBranch,mycompany.MyTests$My50Tests,AnotherCommit,DEV_JOB_2024-02-16T12:43:27.433103200Z,testedOperation,DEV_PIPELINE_2024-02-16T12:43:27.427725500Z,Duration,Test
,,4,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T13:50:21.838Z,23413,SampleBranch,mycompany.MyTests$My200Tests,AnotherCommit,DEV_JOB_2024-02-16T13:49:47.667616100Z,testedOperation,DEV_PIPELINE_2024-02-16T13:49:47.661616200Z,Duration,Test
,,4,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T13:49:48.282Z,3139,SampleBranch,mycompany.MyTests$My10Tests,AnotherCommit,DEV_JOB_2024-02-16T13:49:47.667616100Z,testedOperation,DEV_PIPELINE_2024-02-16T13:49:47.661616200Z,Duration,Test
,,4,2024-02-16T10:54:49.299446005Z,2024-02-16T13:54:49.299446005Z,2024-02-16T13:49:58.885Z,7321,SampleBranch,mycompany.MyTests$My50Tests,AnotherCommit,DEV_JOB_2024-02-16T13:49:47.667616100Z,testedOperation,DEV_PIPELINE_2024-02-16T13:49:47.661616200Z,Duration,Test