【问题标题】:Azure Stream Analytics - Joining Two Streaming SourceAzure 流分析 - 加入两个流式源
【发布时间】:2021-11-16 03:09:17
【问题描述】:

我正在尝试加入从 EventHub 产生相同数据输出的 2 个 Streaming Source。 我试图每 5 分钟找到股票的最高开盘价,并试图将其写入表格。我对股票最大的 5 分钟窗口内的时间和窗口时间感兴趣。 我使用了下面提到的查询,但它没有产生任何相同的输出。 我想我搞砸了加入条件。


WITH Source1 AS (
SELECT
    System.TimeStamp() as TimeSlot,max([open]) as 'MaxOpenPrice'
    FROM
    EventHubInputData  TIMESTAMP BY TimeSlot
GROUP BY TumblingWindow(minute,5)
),
Source2 AS(
SELECT EventEnqueuedUtcTime,[open]
FROM EventHubInputDataDup TIMESTAMP BY EventEnqueuedUtcTime),
Source3 as (
select Source2.EventEnqueuedUtcTime as datetime,Source1.MaxOpenPrice,System.TimeStamp() as TimeSlot 
    FROM  Source1
    JOIN Source2 
    ON Source2.[Open] = Source1.[MaxOpenPrice] AND DATEDIFF (minute,Source1,Source2) BETWEEN 0 AND 5
    )
SELECT datetime,MaxOpenPrice,TimeSlot
INTO EventHubOutPutSQLDB
FROM Source3   ```


【问题讨论】:

  • 我不确定我是否理解以下几点: - 为什么您在 Source1 中使用 TimeSlot 并在 Source 2 中使用 EventEngueuedUtcTime 时间戳? - 为什么你觉得你需要复制输入? EventHubInputData 和 EventHubInputDataDup?
  • @FlorianEiden :我们需要在两个来源之间设置时间差。是的,我可以使用相同的输入并使用不同的名称作为别名。我也试过了,但没有得到结果,为了清楚起见,我使用了 2 个不同的输入。我在 Source1 的 TimeSlot 上加上时间戳,因为它是计算最高价格的时间,而下一个是 EvenEnqueued 的时间从源中获取 openprice 数据的位置..

标签: azure azure-eventhub azure-stream-analytics azure-eventhub-capture


【解决方案1】:

这里的逻辑很好。首先确定每个 5 分钟窗口的最大值,然后在原始流中查找它发生的时间。

WITH MaxOpen5MinTumbling AS (
SELECT
   --TickerId,
   System.TimeStamp() AS WindowEnd, --this always return the end of the window when windowing
   MAX([open]) AS 'MaxOpenPrice'
FROM EventHubInputData --no need to timestamp if using ingestion time
GROUP BY TumblingWindow(minute,5)
)

SELECT
   --M.TickedId,
   M.WindowEnd,
   M.MaxOpenPrice,
   O.EventEnqueuedUtcTime AS MaxOpenPriceTime
FROM MaxOpen5MinTumbling M
LEFT JOIN EventHubInputData O
   ON M.MaxOpenPrice = o.[open]
   AND DATEDIFF(minute,M,O) BETWEEN -5 AND 0 --The new timestamp is at the end of the window, you need to look back 5 minutes
   --AND M.TickerId = O.TickerId

请注意,此时如果最高价格发生多次,您可能会在每个时间窗口获得多个结果。

【讨论】:

  • 所以我认为这是我搞砸的 DATEDIFF。感谢您的输入。会让你知道结果..
猜你喜欢
  • 2021-07-14
  • 1970-01-01
  • 2020-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-23
相关资源
最近更新 更多