忽略流分析输入数组中包含特定值的数据

时间:2019-01-09 23:12:47

标签: azure-stream-analytics

使用此示例数据:

{
"device":"TestDevice",
"id":30,
"flags":[ "New", "Ignore"]
}

我想选择所有没有标志“ Ignore”的数据,我将其与udf一起使用:

SELECT 
 device, id, flags
 FROM input
 WHERE udf.ArrayContains(flags, "Ignore) = 0

是否可以在没有用户定义功能的情况下执行此操作?

1 个答案:

答案 0 :(得分:1)

这可以解决问题

with cte as 
(
    select
        i.*        
    from
        localInput as i
    outer APPLY
        getarrayelements(i.flags) ae
    where   
        ae.ArrayValue != 'Ignore'    
    or 
        getarraylength(i.flags) = 0
)
select
    c.id,    
    c.device,
    c.flags
from    
    cte c
group by  
    c.id,    
    c.device,
    c.flags,
    System.Timestamp
having
    count(*) = getarraylength(c.flags) 
or 
    getarraylength(c.flags) = 0

我用以下示例数据对其进行了测试:

{"device":"TestDevice1","id":1,"flags":[ "New", "Ignore"]}
{"device":"TestDevice2","id":2,"flags":[ "New"]}
{"device":"TestDevice3","id":3,"flags":[ "Ignore"]}
{"device":"TestDevice2","id":4,"flags":[ "Something", "Else"]}
{"device":"TestDevice2","id":5,"flags":[]}