J'ai le tableau suivant en langage Kusto :

let my_data = datatable(Environment: string, Service:string, Url:string, Release: string)
[
    "dev", "Service1", "Url1", "Release1",
    "uat", "Service1", "Url2", "Release2",
    "dev", "Service2", "Url3", "Release3",
    "uat", "Service2", "Url4", "Release4",
    "dev", "Service3", "Url5", "Release5",
    "uat", "Service3", "Url6", "Release6",
];

Et j'aimerais le transformer en :

let transformed = datatable(Service: string, dev_url: string, dev_release: string, uat_url: string, uat_release: string)
[
    "Service1", "Url1", "Release1", "Url2", "Release2",
    "Service2", "Url3", "Release3", "Url4", "Release4",
    "Service3", "Url5", "Release5", "Url6", "Release6"
];

Mais par hasard, je ne peux pas le comprendre. Est-ce que quelqu'un peut aider? :)

0
Jakub Dropia 8 oct. 2020 à 17:14

1 réponse

Meilleure réponse

Vous pouvez utiliser join avec des filtres

let my_data = datatable(Environment: string, Service:string, Url:string, Release: string)
[
    "dev", "Service1", "Url1", "Release1",
    "uat", "Service1", "Url2", "Release2",
    "dev", "Service2", "Url3", "Release3",
    "uat", "Service2", "Url4", "Release4",
    "dev", "Service3", "Url5", "Release5",
    "uat", "Service3", "Url6", "Release6",
];
my_data| where Environment=='dev'
| join (my_data | where Environment=='uat') on Service
| project Service, dev_url=Url, dev_release=Release, uat_url=Url1, uat_realase=Release1

UPDATE j'ai trouvé le moyen de le faire avec Environment dynamique

let my_data = datatable(Environment: string, Service:string, Url:string, Release: string)
[
    "dev", "Service1", "Url1", "Release1",
    "uat", "Service1", "Url2", "Release2",
    "xyz", "Service1", "Url3", "Release2",
    "dev", "Service2", "Url3", "Release3",
    "uat", "Service2", "Url4", "Release4",
    "dev", "Service3", "Url5", "Release5",
    "uat", "Service3", "Url6", "Release6",
];
let relases = my_data
| summarize d = make_bag(pack(strcat(Environment,"_release"), Release)) by Service
| evaluate bag_unpack(d);
let urls = my_data
| summarize d = make_bag(pack(strcat(Environment,"_url"), Url)) by Service
| evaluate bag_unpack(d);
relases
| join urls on Service
| project-away Service1
| project-reorder Service , * asc 
0
Piotr Stapp 8 oct. 2020 à 15:13