使用时间戳时,Azure 流分析查询不返回结果集
Azure Stream analytics query not returning result set when using timestamp by
我正在尝试提取每分钟生产的零件数,其中 v 是到那时为止生产的零件数的汇总计数器。
我的天蓝色SQL查询如下
select
x.fqn,
( max(cast(y.arrayvalue.v as BIGINT))-(min(cast(y.arrayvalue.v as BIGINT)))) as ppm
from
(SELECT
TS.ArrayIndex,
TS.ArrayValue.FQN,
TS.ArrayValue.vqts
FROM
[EventHubInput] as hub
timestamp by y.arrayvalue.t
CROSS APPLY GetArrayElements(hub.timeseries) AS TS) as x
cross apply GetArrayElements(x.vqts) AS y
where x.fqn like '%Production%' and y.arrayvalue.q=192
group by tumblingwindow(minute,1),x.fqn
我的输入数据是这样的
{
"timeSeries": [
{
"fqn":"MyEnterprise.Gateways.GatewayE.CLX.Tags.StateBasic",
"vqts":[
{
"v": "" ,
"q": 192 ,
"t":"2016-06-24T16:39:45.683+0000"
}
]
}, {
"fqn":"MyEnterprise.Gateways.GatewayE.CLX.Tags.ProductionCount",
"vqts":[
{
"v": 264 ,
"q": 192 ,
"t":"2016-06-24T16:39:45.683+0000"
}
]
}, {
"fqn":".Gateways.GatewayE.CLX.Tags.StateDetailed",
"vqts":[
{
"v": "" ,
"q": 192 ,
"t":"2016-06-24T16:39:45.683+0000"
}
]
} ]
我的查询returns没有结果。当我通过 y.arrayvalue.t 删除时间戳时
并在 group by 子句中添加 y.arrayvalue.t,我得到了一些结果。我意识到这可能是因为我为每个事件设置了多个时间戳字段,所以我想知道是否可以将第一个数组的时间数据分配给时间戳...类似于 y[0] 的时间戳.t
截至今天,Azure 流分析不支持数组内的值的时间戳。所以你的问题"if it is possible to assign the time data of the first array to timestamp by"的答案是否定的
您可以使用以下解决方法:
首先,将一个作业中的输入消息展平并输出到暂存事件中心:
WITH flattenTS AS
(
SELECT
TS.ArrayIndex,
TS.ArrayValue.FQN,
TS.ArrayValue.vqts
FROM [EventHubInput]
CROSS APPLY GetArrayElements(hub.timeseries) AS TS
)
, flattenVQTS AS
(
SELECT
ArrayIndex
,FQN
,vqts.ArrayValue.v as v
,vqts.ArrayValue.q as q
,vqts.ArrayValue.t as t
FROM flattenTS TS
CROSS APPLY GetArrayElements(TS.vqts) AS vqts
)
SELECT *
INTO [staging_eventhub]
FROM flattenVQTS
然后,使用另一个作业读取扁平化的消息并进行窗口聚合:
SELECT
FQN
,MAX(CAST(v as BIGINT))-MIN(CAST(v as BIGINT)) as ppm
FROM [staging_eventhub] timestamp by t
WHERE fqn LIKE '%Production%' and q=192
GROUP BY tumblingwindow(minute,1), fqn
您可能想知道我们是否可以将以上两个作业合并为单个作业中的多个步骤并避免暂存事件中心。不幸的是,当您今天从 CTE 或子查询 select 时,您不能使用 "timestamp by"。
我正在尝试提取每分钟生产的零件数,其中 v 是到那时为止生产的零件数的汇总计数器。
我的天蓝色SQL查询如下
select
x.fqn,
( max(cast(y.arrayvalue.v as BIGINT))-(min(cast(y.arrayvalue.v as BIGINT)))) as ppm
from
(SELECT
TS.ArrayIndex,
TS.ArrayValue.FQN,
TS.ArrayValue.vqts
FROM
[EventHubInput] as hub
timestamp by y.arrayvalue.t
CROSS APPLY GetArrayElements(hub.timeseries) AS TS) as x
cross apply GetArrayElements(x.vqts) AS y
where x.fqn like '%Production%' and y.arrayvalue.q=192
group by tumblingwindow(minute,1),x.fqn
我的输入数据是这样的
{
"timeSeries": [
{
"fqn":"MyEnterprise.Gateways.GatewayE.CLX.Tags.StateBasic",
"vqts":[
{
"v": "" ,
"q": 192 ,
"t":"2016-06-24T16:39:45.683+0000"
}
]
}, {
"fqn":"MyEnterprise.Gateways.GatewayE.CLX.Tags.ProductionCount",
"vqts":[
{
"v": 264 ,
"q": 192 ,
"t":"2016-06-24T16:39:45.683+0000"
}
]
}, {
"fqn":".Gateways.GatewayE.CLX.Tags.StateDetailed",
"vqts":[
{
"v": "" ,
"q": 192 ,
"t":"2016-06-24T16:39:45.683+0000"
}
]
} ]
我的查询returns没有结果。当我通过 y.arrayvalue.t 删除时间戳时 并在 group by 子句中添加 y.arrayvalue.t,我得到了一些结果。我意识到这可能是因为我为每个事件设置了多个时间戳字段,所以我想知道是否可以将第一个数组的时间数据分配给时间戳...类似于 y[0] 的时间戳.t
截至今天,Azure 流分析不支持数组内的值的时间戳。所以你的问题"if it is possible to assign the time data of the first array to timestamp by"的答案是否定的
您可以使用以下解决方法:
首先,将一个作业中的输入消息展平并输出到暂存事件中心:
WITH flattenTS AS
(
SELECT
TS.ArrayIndex,
TS.ArrayValue.FQN,
TS.ArrayValue.vqts
FROM [EventHubInput]
CROSS APPLY GetArrayElements(hub.timeseries) AS TS
)
, flattenVQTS AS
(
SELECT
ArrayIndex
,FQN
,vqts.ArrayValue.v as v
,vqts.ArrayValue.q as q
,vqts.ArrayValue.t as t
FROM flattenTS TS
CROSS APPLY GetArrayElements(TS.vqts) AS vqts
)
SELECT *
INTO [staging_eventhub]
FROM flattenVQTS
然后,使用另一个作业读取扁平化的消息并进行窗口聚合:
SELECT
FQN
,MAX(CAST(v as BIGINT))-MIN(CAST(v as BIGINT)) as ppm
FROM [staging_eventhub] timestamp by t
WHERE fqn LIKE '%Production%' and q=192
GROUP BY tumblingwindow(minute,1), fqn
您可能想知道我们是否可以将以上两个作业合并为单个作业中的多个步骤并避免暂存事件中心。不幸的是,当您今天从 CTE 或子查询 select 时,您不能使用 "timestamp by"。