StreamInsight - 定义正确窗口的问题

时间:2011-05-27 15:09:43

标签: sql-server-2008-r2 streaminsight

我开始使用StreamInsight,我将其用作wcf服务。 我已经尝试在“ Hitchhiker的Microsoft StreamInsight查询指南”中寻求帮助,并尝试了示例以及codeplex中的示例。

我的问题是:

我的事件制作人使用AlertEvent:

为适配器提供信息
public sealed class AlertEvent
{
    public DateTime Date { get; set; }
    public long IDGroup { get; set; }
    public bool IsToNormalize { get; set; }
    public bool IsError { get; set; }
}

当AlertEvent的IsError = false时,标志IsToNormalize为true;

我正在尝试实现的行为是当我收到带有IsError的流时,我想看看在接下来的'x'分钟内是否到达任何带有IsToNormalize的alertEvent。然后我发送输出IsError AlarmEvent,开始搜索。

我所做的是,当我收到与过滤器对应的输入时,我会在'x'分钟内延长其生命周期并创建一个TumblingWindow,以查看在此期间是否另一个AlertEvent与另一个标志一起到达(使用ExtensionMethod迭代窗口中的所有有效负载。)

var stream= from item in input
            where item.IsError
            group item by item.IdGroup into eachGroup
            from window in eachDigital.AlterEventDuration(e => TimeSpan.FromMinutes((double)1.5)).TumblingWindow(TimeSpan.FromSeconds(15), HoppingWindowOutputPolicy.ClipToWindowEnd)
            select new
            {
                Id = eachDigital.Key,
                NormEvents = window.HasNormalizationEvents(),
                Count = window.Count()
            };

然后,为了获得触发TumblingWindow的AlarmEvent,我使用原始输入进行了连接。

var resultStream = from e1 in stream
                   join e2 in input
                   on e1.Id equals e2.DigitalTag
                   where e1.NormEvents != 0
                   select e2;

这根本不起作用......:/有任何想法可以帮助解决这个问题吗?

我的另一个疑问是,是否会为每个通过过滤器的输入创建一个带有新startDate的新窗口,或者只创建一个tumblingWindow。

感谢。

1 个答案:

答案 0 :(得分:2)

试试这个:

// Move all error events
// to the point where the potential timeout would occur.
var timedOut = input
                   .Where(e => e.IsError == true)
                   .ShiftEventTime(e => e.StartTime + TimeSpan.FromMinutes(5));

// Extend all events IsToNormalize by the timeout.
var following = input
                   .Where(e => e. IsToNormalize == true)
                   .AlterEventDuration(e => TimeSpan.FromMinutes(5));

// Mask away the potential timeout events by the extended events.
// - If IsToNormalize did not occur within the timeout, then the shifted error event
// will remain unchanged by the left-anti-semi-join and represent
// the desired output.
var result = from t in timedOut
             where (from c in following
                    where t.IdGroup == c.IdGroup
                    select c).IsEmpty()
             select t; // or some projection on t