带有 CASE 语句的 Azure 流分析自定义输出数据

Azure stream analytics custom output data with CASE statement

我在计算每个区域的用户时遇到问题,每个用户都会将他们的区域设置发送到服务器。有人可以帮助我实现这一目标,谢谢。 输出流分析应该是这样的:

{
   "sessionId": "sessionId1", -->group by sessionId
   "data": {
        "North America": 0,
        "South America": 0,
        "Europe": 0,
        "Russia": 1,
        "Africa": 2,
        "India": 0,
        "China": 2,
        "Oceania": 0, 
   }
},
{
   "sessionId": "sessionId2", -->group by sessionId
   "data": {
        "North America": 0,
        "South America": 0,
        "Europe": 0,
        "Russia": 0,
        "Africa": 1,
        "India": 0,
        "China": 0,
        "Oceania": 0, 
   }
}

输入数据:

[{"sessionId":"Session1","deviceId":"deviceTest1","locale":"Russia"},{"sessionId":"Session1","deviceId":"deviceTest2","locale":"China"},{"sessionId":"Session1","deviceId":"deviceTest3","locale":"China"},{"sessionId":"Session1","deviceId":"deviceTest4","locale":"Africa"},{"sessionId":"Session1","deviceId":"deviceTest5","locale":"Africa"},{"sessionId":"Session2","deviceId":"deviceTest6","locale":"Africa"}]

我试了几次SQL查询,都不能达到你的要求。我认为这是不可能的,因为你需要 group by sessionId,但是没有 Aggregate Functions 可以得到这种格式。

"data": {
        "North America": 0,
        "South America": 0,
        "Europe": 0,
        "Russia": 0,
        "Africa": 1,
        "India": 0,
        "China": 0,
        "Oceania": 0, 
   }