How to change windows size dynamically in a query?

Answered How to change windows size dynamically in a query?

  • Monday, October 08, 2012 11:23 AM
     
      Has Code

    For example I have this code in a query:

            protected override CepStream<Alert> CreateOutputStream(CepStream<MessageDeliveredEvent> inputStream)
            {
                var x = GetPeriod();
    
                return inputStream
                    .HoppingWindow(TimeSpan.FromMinutes(x),
                                   TimeSpan.FromMinutes(OutputUpdatingFrequency),
                                   HoppingWindowOutputPolicy.ClipToWindowEnd)
                    .Select(w => w.GetAlerts())
                    .ToPointEventStream();
            }

    I need to implement method  GetPeriod() to set  HoppingWindow size dynamically 

All Replies

  • Monday, October 08, 2012 6:34 PM
     
     

    I'm not sure that I understand the question here.

    We do change the window size from configuration and pass the value into the query all the time. However, if you are looking to change the window/hop size as the query is running, you can't do that.

    Can you provide more details on your use case?


    DevBiker (aka J Sawyer)
    Microsoft MVP - Sql Server (StreamInsight)


    Ruminations of J.net


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

  • Tuesday, October 09, 2012 10:42 AM
     
     
    I need to change it while the query is running to reflect the current time of the day, for example, at night the windows size should be bigger
  • Tuesday, October 09, 2012 1:18 PM
     
     Answered Has Code

    Once the query is started, you can't change the window size.

    What you can do, however, is manipulate your event's temporal properties to get them to fit in the window and base that on the time of day. Because AlterEventDuration take a lambda, you can call a custom method to set the temporal properties based on time of day or even the temporal properties of the event.

    Here's a quick sample from LinqPad that proves this out. Of course, your logic for GetExtendingTimespan would be different but it should show the concept.

    void Main()
    {
        var weatherData = Application.DefineEnumerable(() => new[]
        {
            new { Timestamp = new DateTime(2010, 1, 1, 0, 00, 00, DateTimeKind.Utc), Temperature = -9.0,	StationCode = 71395,	WindSpeed = 4	}, 
            new { Timestamp = new DateTime(2010, 1, 1, 0, 30, 00, DateTimeKind.Utc), Temperature = -4.5,	StationCode = 71801,	WindSpeed = 41	}, 
            new { Timestamp = new DateTime(2010, 1, 1, 1, 00, 00, DateTimeKind.Utc), Temperature = -8.8,	StationCode = 71395,	WindSpeed =	6	}, 
            new { Timestamp = new DateTime(2010, 1, 1, 1, 30, 00, DateTimeKind.Utc), Temperature = -4.4,	StationCode = 71801,	WindSpeed =	39	}, 
            new { Timestamp = new DateTime(2010, 1, 1, 2, 00, 00, DateTimeKind.Utc), Temperature = -9.7,	StationCode = 71395,	WindSpeed =	9	}, 
            new { Timestamp = new DateTime(2010, 1, 1, 2, 30, 00, DateTimeKind.Utc), Temperature = -4.6,	StationCode = 71801,	WindSpeed =	59	}, 
            new { Timestamp = new DateTime(2010, 1, 1, 3, 00, 00, DateTimeKind.Utc), Temperature = -9.6,	StationCode = 71395,	WindSpeed =	9	},
        });
        
        var weather = weatherData.ToPointStreamable(
            t => PointEvent.CreateInsert(t.Timestamp, t),
            AdvanceTimeSettings.IncreasingStartTime);
        
    	
    	var incremented = weather.AlterEventDuration(e=> GetExtendingTimespan()); 
    	weather.ToIntervalEnumerable().Dump("Original"); 
    	incremented.ToIntervalEnumerable().Dump("Extending Timespan"); 
    }
    private static int _callCount = 10; 
    public static TimeSpan GetExtendingTimespan(){
    	return TimeSpan.FromMinutes(Interlocked.Increment(ref _callCount)); 
    }


    DevBiker (aka J Sawyer)
    Microsoft MVP - Sql Server (StreamInsight)


    Ruminations of J.net


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

  • Tuesday, October 16, 2012 10:29 AM
     
     
    Actually I'm using TumblingWindow, HoppingWindow was just for the example. So I ended up using the method AlterEventLifetime instead of AlterEventDuration. Thanks for answer!