[Original] streaminsight query series (12)-event alignment in query mode

Source: Internet
Author: User

In the previous article, we introduced the window alignment section in the query mode. This blog post will introduce event alignment.

Test data preparation

To facilitate test query, we first prepare a static test data source:

var sourceIntervalDataType = new []{    new { Id = "A", StartTime = DateTime.Parse("10/23/2009 11:59:01 PM"), EndTime = DateTime.Parse("10/23/2009 11:59:59 PM") },    new { Id = "A", StartTime = DateTime.Parse("10/23/2009 4:12:00 PM"), EndTime = DateTime.Parse("10/24/2009 4:12:01 PM") },    new { Id = "A", StartTime = DateTime.Parse("10/31/2009 11:59:59 PM"), EndTime = DateTime.Parse("11/1/2009 12:00:00 AM") },    new { Id = "A", StartTime = DateTime.Parse("11/1/2009 12:00:00 AM"), EndTime = DateTime.Parse("11/1/2009 12:00:00 PM") },    new { Id = "A", StartTime = DateTime.Parse("11/2/2009 12:00:01 AM"), EndTime = DateTime.Parse("11/2/2009 12:00:02 AM") },    new { Id = "A", StartTime = DateTime.Parse("11/3/2009 11:59:59 PM"), EndTime = DateTime.Parse("11/4/2009 12:00:01 AM") },};

 

Next, we will change sourceintervaldatatype to an interval-type complex event stream:

var source = sourceIntervalDataType.ToIntervalStream(Application, ev =>                    IntervalEvent.CreateInsert(ev.StartTime.ToLocalTime(), ev.EndTime.ToLocalTime(), new { ev.Id }),                    AdvanceTimeSettings.StrictlyIncreasingStartTime);

 

Event alignment

Question 1: How to move/align the event to a.m. (that is, the day that begins) and keep the end time unchanged?

The function that changes the life cycle of an event has already been seen before. Good, it's altereventduration! However, it is an extended duration and cannot change the start time of an event. To Solve Problem 1, you need to use another function, altereventlifetime, to change the life cycle.

var alignStream = source.AlterEventLifetime(    e => e.StartTime.Date, e => e.EndTime - e.StartTime.Date);

Altereventlifetime, as its name implies, is to change the lifecycle of an event. It can modify the event duration or the event start time. In the above Code, the previous part specifies the start time as a.m. of the current day, and the later part specifies the duration to ensure that the end time after modification is consistent with the previous one. The result of the event stream after the change is as follows:

Question 2: How to move/align the event to a.m. (that is, starting on the current day) and keep the duration unchanged?

Similarly, modify the duration of the second parameter of altereventlifetime. The Code is as follows:

var alignStream = source.AlterEventLifetime(    e => e.StartTime.Date, e => e.EndTime - e.StartTime);

The output result is as follows:

The next section describes the basic modes in the streaminsight query mode.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.