这样的事情怎么样?(它的输出模式与您最初在问题中提到的输出模式略有不同)
datatable(Computer:string, CounterName:string, CounterValue:double, TimeGenerated:datetime)
[
"comp1", "counter1", 1.0, datetime(2019-02-07 16:31:15),
"comp2", "counter1", 1.1, datetime(2019-02-07 16:31:15),
"comp3", "counter1", 1.2, datetime(2019-02-07 16:31:15),
"comp4", "counter1", 1.3, datetime(2019-02-07 16:31:16),
"comp2", "counter2", 1.4, datetime(2019-02-07 16:31:16),
"comp3", "counter3", 1.5, datetime(2019-02-07 16:31:16),
"comp4", "counter2", 1.6, datetime(2019-02-07 16:31:14),
]
| summarize TimeGenerated = any(TimeGenerated), d = make_dictionary(pack(CounterName, CounterValue)) by Computer
| evaluate bag_unpack(d)
将输出:
| Computer | TimeGenerated | counter1 | counter2 | counter3 |
|----------|-----------------------------|----------|----------|----------|
| comp1 | 2019-02-07 16:31:15.0000000 | 1 | | |
| comp2 | 2019-02-07 16:31:15.0000000 | 1.1 | 1.4 | |
| comp3 | 2019-02-07 16:31:15.0000000 | 1.2 | | 1.5 |
| comp4 | 2019-02-07 16:31:16.0000000 | 1.3 | 1.6 | |
你也可以这样做:
datatable(Computer:string, CounterName:string, CounterValue:double, TimeGenerated:datetime)
[
"comp1", "counter1", 1.0, datetime(2019-02-07 16:31:15),
"comp2", "counter1", 1.1, datetime(2019-02-07 16:31:15),
"comp3", "counter1", 1.2, datetime(2019-02-07 16:31:15),
"comp4", "counter1", 1.3, datetime(2019-02-07 16:31:16),
"comp2", "counter2", 1.4, datetime(2019-02-07 16:31:16),
"comp3", "counter3", 1.5, datetime(2019-02-07 16:31:16),
"comp4", "counter2", 1.6, datetime(2019-02-07 16:31:14),
]
| summarize arg_max(TimeGenerated, *) by Computer, CounterName
| summarize d = make_dictionary(pack(CounterName, CounterValue, "TimeGenerated", TimeGenerated)) by Computer
| evaluate bag_unpack(d)
这将输出:
| Computer | TimeGenerated | counter1 | counter2 | counter3 |
|----------|-----------------------------|----------|----------|----------|
| comp1 | 2019-02-07 16:31:15.0000000 | 1 | | |
| comp2 | 2019-02-07 16:31:15.0000000 | 1.1 | 1.4 | |
| comp3 | 2019-02-07 16:31:15.0000000 | 1.2 | | 1.5 |
| comp4 | 2019-02-07 16:31:16.0000000 | 1.3 | 1.6 | |