"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9383],{91764(T,L,f){f.d(L,{getJoinByLabelsTransformer:()=>E});var M=f(81160),y=f(19560),c=f(17727),h=f(52358),B=f(75251);const E=()=>({id:y.F.joinByLabels,name:(0,h.t)("transformers.get-join-by-labels-transformer.name.join-by-labels","Join by labels"),description:(0,h.t)("transformers.get-join-by-labels-transformer.description.flatten-labeled-results-table-joined-labels","Flatten labeled results into a table joined by labels."),defaultOptions:{},operator:(n,a)=>m=>m.pipe((0,M.T)(t=>E().transformer(n,a)(t))),transformer:n=>a=>!a||!a.length?a:[D(n,a)]});function D(n,a){if(!n.value?.length)return g("No value label configured");const m=(0,B.aG)(a);if(m.size<1)return g("No labels in result");if(!m.has(n.value))return g("Value label not found");let t=n.join?.length?n.join:Array.from(m);t=t.filter(e=>e!==n.value);const p=new Set,b=new Map,d={};for(const e of a)for(const l of e.fields)if(l.labels&&l.type!==c.PU.time){const u=t.map(U=>l.labels[U]),s=u.join(",");let o=b.get(s);o||(o={keys:u,values:{}},b.set(s,o));const r=l.labels[n.value],P=l.values,O=o.values[r];O?o.values[r]=O.concat(P):o.values[r]=P,d[r]||(d[r]=l),p.add(r)}const i=Array.from(p),j=t.map(()=>[]),v=i.map(()=>[]);for(const e of b.values()){let l=-1,u=!1;for(;!u;){l++,u=!0;for(let s=0;s<t.length;s++)j[s].push(e.keys[s]);for(let s=0;s<i.length;s++){const o=i[s],r=e.values[o]??[];v[s].push(r[l]),r.length>l+1&&(u=!1)}}}const _={fields:[],length:v[0].length,refId:`${y.F.joinByLabels}-${a.map(e=>e.refId).join("-")}`};for(let e=0;e<t.length;e++)_.fields.push({name:t[e],config:{},type:c.PU.string,values:j[e]});for(let e=0;e<i.length;e++){const l=d[i[e]];_.fields.push({name:i[e],config:{},type:l.type??c.PU.number,values:v[e]})}return _}function g(n){return{meta:{notices:[{severity:"error",text:n}]},fields:[{name:"Error",type:c.PU.string,config:{},values:[n]}],length:0}}}}]);

//# sourceMappingURL=9383.6d39b633bbb654f54b23.js.map