【发布时间】:2018-06-04 12:40:43
【问题描述】:
如何在我的一个输入中返回数组元素的值,它所在的索引不断变化?
我很确定我的查询结构是正确的。我有两个输入,并且正在使用连接,并且成功地从两个表中获取了一些数据。但是,我需要从表 B 中获取 RemoteIpAddress,但它是 json 格式的数组。
如果您想轻松复制、粘贴和/或编辑它,这里是文本:
SELECT
A.context.data.eventTime as eventTime,
A.context.device.type as deviceType,
A.context.[user].anonId as userId,
A.context.device.roleInstance as machineName,
B.context.operation.name as eventName,
B.context.custom.dimensions[0],
--B.GetRecordPropertyValue(GetArrayElement(B.context.custom.dimensions,7), B.RemoteIpAddress) as remoteIpAddress,
--GetArrayElement(B.context.custom.dimensions,3),
--B.GetRecordPropertyValue(GetArrayElement(B.context.custom.dimensions,3), B.userName) as userName,
DATEDIFF(minute,A.context.data.eventTime,B.context.data.eventTime) as durationInMinutes
INTO DevUserlgnsOutput
FROM DevUserlgnsInput A TIMESTAMP BY A.context.data.eventTime
JOIN DevUserlgnsInput2 B TIMESTAMP BY B.context.data.eventTime
ON DATEDIFF(minute,A,B) BETWEEN 0 AND 5
注释掉的行不起作用,所以我把它们注释掉了。
我查看了这个并看到了使用 GetRecordPropertyValue 和 GetArrayElement 的建议,所以我这样做了。我没有收到任何错误,但它返回 null。
我还发现,如果我执行 B.context.custom.dimensions[0],则会返回包含我想要查看的元素的完整数组。
更复杂的是,我意识到我想要的元素在数组中的位置并不总是相同的。在某些示例数据中,它是 7,而在其他示例数据中,它是 3。
提前致谢。
阅读答案后更新:
我的新查询:
SELECT
Events.context.data.eventTime as eventTime,
Events.context.device.type as deviceType,
mDim.ArrayValue.MachineName as machineName,
mDim.ArrayValue.UserId as userID,
mDim.ArrayValue.RemoteIpAddress as remoteIpAddress,
mDim.ArrayValue.UserName as userName,
mDim.ArrayValue.EventName as eventName
INTO DevUserlgnsOutput
FROM DevUserlgnsInput2 Events
CROSS APPLY GetArrayElements(Events.context.custom.dimensions) AS mDim
问题:我现在有多个用于单个事件的行,每行显示我要跟踪的 1 个属性(每行中与数组有关的其余列为 NULL)。关于如何解决这个问题的任何想法?
【问题讨论】:
-
您是否尝试过 GetArrayElements(复数)以交叉应用所有这些元素? msdn.microsoft.com/en-us/azure/stream-analytics/reference/…
-
我尝试过并且正在使用这种方法。我在原始问题中发布了更新后的查询。但是,单个事件显示多行,每行仅显示数组的 1 个属性(与数组相关的所有其他列显示 NULL)。我该如何解决这个问题?
标签: json indexing azure-stream-analytics