<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>StreamInsight Team</title><link>http://sqlblog.com/blogs/stream_insight/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>What Is StreamInsight? A Primer for Non-Programmers</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/11/15/what-is-streaminsight-a-primer-for-non-programmers.aspx</link><pubDate>Fri, 16 Nov 2012 02:48:38 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46232</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/46232.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=46232</wfw:commentRss><description>&lt;p&gt;Are you trying to figure out whether StreamInsight might be something you could use, but you’re having trouble sifting through all the programming jargon that’s used to describe it? StreamInsight is, ultimately, a set of programming tools, and at some point it takes a programmer to implement a StreamInsight solution. But it really should be possible to get a handle on what StreamInsight is all about even if you’re not a programmer yourself.&lt;/p&gt;  &lt;p&gt;A new article published in the TechNet Wiki may be able to help: &lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/14437.streaminsight-for-non-programmers.aspx"&gt;StreamInsight for Non-Programmers&lt;/a&gt;. It gives an overview of the technology, but it leaves out the C# references and relates StreamInsight to more familiar SQL databases and queries. Check it out.&lt;/p&gt;  &lt;p&gt;When you’re done there and are ready to dig a little deeper, take a look at &lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/14436.get-started-with-streaminsight-2-1-en-us.aspx"&gt;Get Started with StreamInsight 2.1&lt;/a&gt;. That article should help you navigate through the StreamInsight official documentation and other resources.&lt;/p&gt;  &lt;p&gt;And, as always, you can post questions or comments here or on the TechNet Wiki.&lt;/p&gt;  &lt;p&gt;Regards,&lt;/p&gt;  &lt;p&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=46232" width="1" height="1"&gt;</description></item><item><title>Getting Started with StreamInsight 2.1</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/09/18/getting-started-with-streaminsight-2-1.aspx</link><pubDate>Wed, 19 Sep 2012 05:57:10 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:45265</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/45265.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=45265</wfw:commentRss><description>&lt;p&gt;If you're just beginning to get familiar with StreamInsight, you may be looking for a way to get started. What are the basics? How can I get my first StreamInsight application running so I can see how it works? Where is the 'front door' that will get me going?&lt;/p&gt;  &lt;p&gt;If that describes you, then this blog entry might be just what you need.&lt;/p&gt;  &lt;p&gt;If you're already a StreamInsight wiz, keep reading anyway - you may find some helpful links here that you weren't aware of. But here's what we'd like from you experienced readers in particular: if you know of other good resources that we missed, please feel free to add them in the comments below. We appreciate you sharing your expertise.&lt;/p&gt;  &lt;h2&gt;The Book&lt;/h2&gt;  &lt;p&gt;The basic documentation for StreamInsight is located in the MSDN Library (&lt;a href="http://msdn.microsoft.com/en-us/library/hh750619(SQL.10).aspx"&gt;Microsoft StreamInsight 2.1&lt;/a&gt;). You'll notice that previous versions of StreamInsight are still there (1.2 and 2.0), but if you're just getting started you can stick to the 2.1 section.&lt;/p&gt;  &lt;p&gt;The documentation has been organized to function as reference material, which is fine after you're familiar with the technology. But if you're trying to learn the basics, you might want to take a different path instead of just starting at the top. &lt;/p&gt;  &lt;p&gt;The following is one map you can use.&lt;/p&gt;  &lt;h2&gt;What Is StreamInsight?&lt;/h2&gt;  &lt;p&gt;Here is a sequence of topics that should give you a good overview of what StreamInsight is and how it works:&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee391416(v=sql.111)"&gt;Overview&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;answers the question, &amp;quot;what is it?&amp;quot;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee391536(SQL.111).aspx"&gt;StreamInsight Server Architecture&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;gives you a quick look at a high-level architectural drawing&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/jj136801(SQL.111).aspx"&gt;StreamInsight Concepts&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;lays out an overview of the basic components&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/jj149394(SQL.111).aspx"&gt;Deploying StreamInsight Entities to a StreamInsight Server&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;describes the mechanics of how these components work together&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;h2&gt;Getting an Example Running&lt;/h2&gt;  &lt;p&gt;Once you have this background, go ahead and install StreamInsight and get a basic example up and running:&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee378749(SQL.111).aspx"&gt;Installation&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;download and install the software&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/jj136799(SQL.111).aspx"&gt;StreamInsight Examples&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;walk through a set of 3 simple StreamInsight applications that work together to demonstrate what you learned in the topics above; you can copy and paste the code into Visual Studio, compile, and run&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;That's it - you now have a real, functioning StreamInsight system! &lt;/p&gt;  &lt;p&gt;Now that you have a handle on the basics, you might want to start digging deeper.&lt;/p&gt;  &lt;h2&gt;Digging Deeper&lt;/h2&gt;  &lt;p&gt;Here's a suggested path through the documentation to help you understand the next layer of StreamInsight technologies:&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/gg144958(SQL.111).aspx"&gt;Using Event Sources and Event Sinks&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;sources supply data and sinks consume it; this topic gives you an overview of how they work&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff518487(SQL.111).aspx"&gt;Publishing and Connecting to the StreamInsight Server&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;practical details on how to set up a StreamInsight server&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://blogs.msdn.com/b/streaminsight/archive/2012/08/01/a-hitchhiker-s-guide-to-streaminsight-2-1-queries.aspx"&gt;A Hitchhiker’s Guide to StreamInsight 2.1 Queries&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;queries are the heart of how StreamInsight performs data analytics, and this whitepaper will help you really understand how they work&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee362394(SQL.111).aspx"&gt;Using StreamInsight LINQ&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;root through this section for technical details on specific query components&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff518532(SQL.111).aspx"&gt;Using the StreamInsight Event Flow Debugger&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;in addition to troubleshooting, the debugger is a great way to learn more about what goes on inside a StreamInsight application&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;h2&gt;And Even Deeper&lt;/h2&gt;  &lt;p&gt;Finally, to get a handle on some of the more complex things you can do with StreamInsight, dig into these:&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh995354(SQL.111).aspx"&gt;Input and Output Adapters&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;adapters can be useful for handling more complex sources and sinks &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh290476(SQL.111).aspx"&gt;Building Resilient StreamInsight Applications&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;a resilient application is able to recover from system failures &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee391224(SQL.111).aspx"&gt;Operations&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;this section will help you monitor and troubleshoot a running StreamInsight system &lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;h2&gt;The StreamInsight Community&lt;/h2&gt;  &lt;p&gt;As you're designing and developing your StreamInsight solutions, you probably will find it helpful to see working examples or to learn tips and tricks from others. Or maybe you need a place to post a vexing question. &lt;/p&gt;  &lt;p&gt;Here are some community resources that we have found useful. If you know of others, please add them in the comments below.&lt;/p&gt;  &lt;h3&gt;Code samples and tools&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://streaminsight.codeplex.com/"&gt;Official StreamInsight code samples&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/streaminsight/archive/2012/06/26/introduction-to-linqpad-driver-for-streaminsight-2-1.aspx"&gt;Introduction to LinqPad Driver for StreamInsight 2.1&lt;/a&gt; - LinqPad is a very useful tool for developing queries&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following case studies are based on earlier versions of StreamInsight, but they still are useful examples: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://channel9.msdn.com/learn/courses/SQL2008R2TrainingKit/SQL10R2UPD00/SQL10R2UPD00_REC_03"&gt;Microsoft Media Analytics&lt;/a&gt; - real-time monitoring and analytic&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/canada/casestudies/Case_Study_Detail.aspx?casestudyid=4000008341"&gt;Edgenet&lt;/a&gt; - responding to information from multiple source&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh849321.aspx"&gt;ICONICS&lt;/a&gt; - managing energy usage &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Blogs&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/streaminsight/"&gt;Microsoft StreamInsight&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.devbiker.net/category/StreamInsight.aspx"&gt;Ruminations of J.net&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://seroter.wordpress.com/category/streaminsight/"&gt;Richard Seroter's Architecture Musings&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blog.pluralsight.com/tag/streaminsight/"&gt;pluralsight&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Forums&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/streaminsight"&gt;MSDN StreamInsight Forum&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://stackoverflow.com/questions/tagged/streaminsight"&gt;stackoverflow&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Training&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://pluralsight.com/training/Courses/TableOfContents?courseName=streaminsight"&gt;Microsoft StreamInsight Fundamentals&lt;/a&gt; (“Introducing StreamInsight” is free) from &lt;a href="http://pluralsight.com/training/"&gt;pluralsight&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Twitter&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="https://twitter.com/streaminsight"&gt;@streaminsight&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;You’re a StreamInsight Expert&lt;/h2&gt;  &lt;p&gt;That should get you going. Please add any other resources you have found useful in the comments below.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Regards,&lt;/p&gt;  &lt;p&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=45265" width="1" height="1"&gt;</description></item><item><title>StreamInsight will not push feature releases through Microsoft Update going forward</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/09/04/streaminsight-will-not-push-feature-releases-through-microsoft-update-going-forward.aspx</link><pubDate>Wed, 05 Sep 2012 03:41:22 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:45001</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/45001.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=45001</wfw:commentRss><description>&lt;p&gt;Until now, we've released StreamInsight through the Microsoft Download Center, and also released it out through Microsoft Update. Going forward, we will only release new StreamInsight versions through the Microsoft Download Center and only use MU to release service packs and security fixes (should any be needed). As a result of this decision, we are pulling off the recent StreamInsight 2.1 release from MU; this release is still available in &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=30149"&gt;Download Center&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Don’t worry: there’s nothing &lt;i&gt;wrong&lt;/i&gt; with the versions we’ve shipped in MU, we’ve just adjusted how we use MU. There is no action necessary from our customers as a result of this change, and we are not rolling back any changes to your current installation, so if you have installed StreamInsight 2.1 recently through the Microsoft Update, they will still work fine.&lt;/p&gt;  &lt;p&gt;Regards,&lt;/p&gt;  &lt;p&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=45001" width="1" height="1"&gt;</description></item><item><title>Using Subjects to Deploy Queries Dynamically</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/08/30/using-subjects-to-deploy-queries-dynamically.aspx</link><pubDate>Thu, 30 Aug 2012 18:13:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44945</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44945.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44945</wfw:commentRss><description>&lt;p&gt;In the previous blog posting, we showed how to construct and deploy query fragments to a StreamInsight server, and how to re-use them later. In today&amp;rsquo;s posting we&amp;rsquo;ll integrate this pattern into a method of dynamically composing a new query with an existing one.&lt;/p&gt;
&lt;p&gt;The construct that enables this scenario in StreamInsight V2.1 is a &lt;em&gt;Subject&lt;/em&gt;. A Subject lets me create a junction element in an existing query that I can tap into while the query is running.&lt;/p&gt;
&lt;p&gt;To set this up as an end-to-end example, let&amp;rsquo;s first define a stream simulator as our data source:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; generator = myApp.DefineObservable( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt; t) =&amp;gt; &lt;span style="color:#2b91af;"&gt;Observable&lt;/span&gt;.Interval(t).Select(_ =&amp;gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SourcePayload&lt;/span&gt;()));&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This &amp;lsquo;generator&amp;rsquo; produces a new instance of &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;SourcePayload&lt;/strong&gt;&lt;/span&gt; with a period of &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;t&lt;/strong&gt;&lt;/span&gt; (system time) as an &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IObservable&lt;/strong&gt;&lt;/span&gt;. &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;SourcePayload&lt;/strong&gt;&lt;/span&gt; happens to have a property of type &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;double&lt;/strong&gt;&lt;/span&gt; as its payload data.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s also define a sink for our example&amp;mdash;an &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IObserver&lt;/strong&gt;&lt;/span&gt; of double values that writes to the console:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; console = myApp.DefineObserver( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; label) =&amp;gt; &lt;span style="color:#2b91af;"&gt;Observer&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#0000ff;"&gt;double&lt;/span&gt;&amp;gt;(e =&amp;gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;"{0}: {1}"&lt;/span&gt;, label, e))) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Deploy(&lt;span style="color:#a31515;"&gt;"ConsoleSink"&lt;/span&gt;);&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The observer takes a string as parameter which is used as a label on the console, so that we can distinguish the output of different sink instances. Note that we also deploy this observer, so that we can retrieve it later from the server from a different process.&lt;/p&gt;
&lt;p&gt;Remember how we defined the aggregation as an &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IQStreamable&lt;/strong&gt;&lt;/span&gt; function in the previous article? We will use that as well:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; avg = myApp &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .DefineStreamable((&lt;span style="color:#2b91af;"&gt;IQStreamable&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;SourcePayload&lt;/span&gt;&amp;gt; s, &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt; w) =&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; s.TumblingWindow(w) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; win.Avg(e =&amp;gt; e.Value)) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Deploy(&lt;span style="color:#a31515;"&gt;"AverageQuery"&lt;/span&gt;);&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then we define the Subject, which acts as an observable sequence as well as an observer. Thus, we can feed a single source into the Subject and have multiple consumers&amp;mdash;that can come and go at runtime&amp;mdash;on the other side:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; subject = myApp.CreateSubject(&lt;span style="color:#a31515;"&gt;"Subject"&lt;/span&gt;, () =&amp;gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Subject&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;SourcePayload&lt;/span&gt;&amp;gt;());&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Subject are always deployed automatically. Their name is used to retrieve them from a (potentially) different process (see below).&lt;/p&gt;
&lt;p&gt;Note that the Subject as we defined it here doesn&amp;rsquo;t know anything about temporal streams. It is merely a sequence of &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;SourcePayload&lt;/strong&gt;&lt;/span&gt;s, without any notion of StreamInsight point events or CTIs. So in order to compose a temporal query on top of the Subject, we need to 'promote' the sequence of &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;SourcePayload&lt;/strong&gt;&lt;/span&gt;s into an &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IQStreamable&lt;/strong&gt;&lt;/span&gt; of point events, including CTIs:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; stream = subject.ToPointStreamable( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; e =&amp;gt; &lt;span style="color:#2b91af;"&gt;PointEvent&lt;/span&gt;.CreateInsert&amp;lt;&lt;span style="color:#2b91af;"&gt;SourcePayload&lt;/span&gt;&amp;gt;(e.Timestamp, e), &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;AdvanceTimeSettings&lt;/span&gt;.StrictlyIncreasingStartTime);&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In a later posting we will show how to use Subjects that have more awareness of time and can be used as a junction between &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;QStreamable&lt;/strong&gt;&lt;/span&gt;s instead of &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IQbservable&lt;/strong&gt;&lt;/span&gt;s.&lt;/p&gt;
&lt;p&gt;Having turned the Subject into a temporal stream, we can now define the aggregate on this stream. We will use the &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IQStreamable&lt;/strong&gt;&lt;/span&gt; entity &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;avg&lt;/strong&gt;&lt;/span&gt; that we defined above:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; longAverages = avg(stream, &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(5));&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In order to run the query, we need to bind it to a sink, and bind the subject to the source:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; standardQuery = longAverages &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Bind(console(&lt;span style="color:#a31515;"&gt;"5sec average"&lt;/span&gt;)) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .With(generator(&lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromMilliseconds(300)).Bind(subject));&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Lastly, we start the process:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;standardQuery.Run(&lt;span style="color:#a31515;"&gt;"StandardProcess"&lt;/span&gt;);&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now we have a simple query running end-to-end, producing results. What follows next is the crucial part of tapping into the Subject and adding another query that runs in parallel, using the same query definition (the &amp;ldquo;AverageQuery&amp;rdquo;) but with a different window length. We are assuming that we connected to the same StreamInsight server from a different process or even client, and thus have to retrieve the previously deployed entities through their names:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#008000;"&gt;// simulate the addition of a 'fast' query from a separate server connection,&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;// by retrieving the aggregation query fragment&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;// (instead of simply using the 'avg' object)&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; averageQuery = myApp &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .GetStreamable&amp;lt;&lt;span style="color:#2b91af;"&gt;IQStreamable&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;SourcePayload&lt;/span&gt;&amp;gt;, &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;"AverageQuery"&lt;/span&gt;); &lt;br /&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;// retrieve the input sequence as a subject&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; inputSequence = myApp &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .GetSubject&amp;lt;&lt;span style="color:#2b91af;"&gt;SourcePayload&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;SourcePayload&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;"Subject"&lt;/span&gt;); &lt;br /&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;// retrieve the registered sink&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; sink = myApp.GetObserver&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;"ConsoleSink"&lt;/span&gt;); &lt;br /&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;// turn the sequence into a temporal stream&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; stream2 = inputSequence.ToPointStreamable( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; e =&amp;gt; &lt;span style="color:#2b91af;"&gt;PointEvent&lt;/span&gt;.CreateInsert&amp;lt;&lt;span style="color:#2b91af;"&gt;SourcePayload&lt;/span&gt;&amp;gt;(e.Timestamp, e), &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;AdvanceTimeSettings&lt;/span&gt;.StrictlyIncreasingStartTime); &lt;br /&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;// apply the query, now with a different window length&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; shortAverages = averageQuery(stream2, &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(1)); &lt;br /&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;// bind new sink to query and run it&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; fastQuery = shortAverages &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Bind(sink(&lt;span style="color:#a31515;"&gt;"1sec average"&lt;/span&gt;)) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Run(&lt;span style="color:#a31515;"&gt;"FastProcess"&lt;/span&gt;);&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The attached solution demonstrates the sample end-to-end.&lt;/p&gt;
&lt;p&gt;Regards, &lt;br /&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44945" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/stream_insight/archive/tags/LINQ/default.aspx">LINQ</category></item><item><title>Parameterized StreamInsight Queries</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/08/28/parameterized-streaminsight-queries.aspx</link><pubDate>Wed, 29 Aug 2012 00:28:09 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44888</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44888.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44888</wfw:commentRss><description>&lt;p&gt;The changes in our APIs enable a set of scenarios that were either not possible before or could only be achieved through workarounds. One such use case that people ask about frequently is the ability to parameterize a query and instantiate it with different values instead of re-deploying the entire statement. I’ll demonstrate how to do this in StreamInsight 2.1 and combine it with a method of using subjects for dynamic query composition in a mini-series of (at least) two blog articles.&lt;/p&gt;  &lt;p&gt;Let’s start with something really simple: I want to deploy a windowed aggregate to a StreamInsight server, and later use it with different window sizes. The LINQ statement for such an aggregate is very straightforward and familiar:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; result = &lt;span&gt;from&lt;/span&gt; win &lt;span&gt;in&lt;/span&gt; stream.TumblingWindow(&lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(5))&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;select&lt;/span&gt; win.Avg(e =&amp;gt; e.Value);&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Obviously, we had to use an existing input stream object as well as a concrete &lt;font face="Consolas"&gt;&lt;strong&gt;TimeSpan&lt;/strong&gt;&lt;/font&gt; value. If we want to be able to re-use this construct, we can define it as a &lt;font face="Consolas"&gt;&lt;strong&gt;IQStreamable&lt;/strong&gt;&lt;/font&gt;:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; avg = myApp      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .DefineStreamable((IQStreamable&amp;lt;&lt;span&gt;SourcePayload&lt;/span&gt;&amp;gt; s, &lt;span&gt;TimeSpan&lt;/span&gt; w) =&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;from&lt;/span&gt; win &lt;span&gt;in&lt;/span&gt; s.TumblingWindow(w)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;select&lt;/span&gt; win.Avg(e =&amp;gt; e.Value));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The &lt;font face="Consolas"&gt;&lt;strong&gt;DefineStreamable&lt;/strong&gt;&lt;/font&gt; API lets us define a function, in our case from a &lt;font face="Consolas"&gt;&lt;strong&gt;IQStreamable&lt;/strong&gt;&lt;/font&gt; (the input stream) and a &lt;font face="Consolas"&gt;&lt;strong&gt;TimeSpan&lt;/strong&gt;&lt;/font&gt; (the window length) to an &lt;font face="Consolas"&gt;&lt;strong&gt;IQStreamable&lt;/strong&gt;&lt;/font&gt; (the result). We can then use it like a function, with the input stream and the window length as parameters:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; result = avg(stream, &lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(5));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Nice, but you might ask: what does this save me, except from writing my own extension method? Well, in addition to &lt;em&gt;defining&lt;/em&gt; the &lt;font face="Consolas"&gt;&lt;strong&gt;IQStreamable&lt;/strong&gt;&lt;/font&gt; function, you can actually &lt;em&gt;deploy&lt;/em&gt; it to the server, to make it re-usable by another process! When we deploy an artifact in V2.1, we give it a name:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; avg = myApp      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .DefineStreamable((&lt;span&gt;IQStreamable&lt;/span&gt;&amp;lt;&lt;span&gt;SourcePayload&lt;/span&gt;&amp;gt; s, &lt;span&gt;TimeSpan&lt;/span&gt; w) =&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;from&lt;/span&gt; win &lt;span&gt;in&lt;/span&gt; s.TumblingWindow(w)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;select&lt;/span&gt; win.Avg(e =&amp;gt; e.Value))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .Deploy(&lt;span&gt;&amp;quot;AverageQuery&amp;quot;&lt;/span&gt;);&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;When connected to the same server, we can now use that name to retrieve the &lt;font face="Consolas"&gt;&lt;strong&gt;IQStreamable &lt;/strong&gt;&lt;/font&gt;and use it with our own parameters:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; averageQuery = myApp      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .GetStreamable&amp;lt;&lt;span&gt;IQStreamable&lt;/span&gt;&amp;lt;&lt;span&gt;SourcePayload&lt;/span&gt;&amp;gt;, &lt;span&gt;TimeSpan&lt;/span&gt;, &lt;span&gt;double&lt;/span&gt;&amp;gt;(&lt;span&gt;&amp;quot;AverageQuery&amp;quot;&lt;/span&gt;);       &lt;br /&gt;      &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; result = averageQuery(stream, &lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(5));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Convenient, isn’t it?&lt;/p&gt;  &lt;p&gt;Keep in mind that, even though the function “AverageQuery” is deployed to the server, its logic will still be instantiated into each process when the process is created. The advantage here is being able to deploy that function, so another client who wants to use it doesn’t need to ask the author for the code or assembly, but just needs to know the name of deployed entity.&lt;/p&gt;  &lt;p&gt;A few words on the function signature of &lt;font face="Consolas"&gt;&lt;strong&gt;GetStreamable&lt;/strong&gt;&lt;/font&gt;: the last type parameter (here: &lt;font face="Consolas"&gt;&lt;strong&gt;double&lt;/strong&gt;&lt;/font&gt;) is the payload type of the result, not the actual result stream’s type itself. The returned object is a function from &lt;font face="Consolas"&gt;&lt;strong&gt;IQStreamable&amp;lt;SourcePayload&amp;gt;&lt;/strong&gt;&lt;/font&gt; and &lt;font face="Consolas"&gt;&lt;strong&gt;TimeSpan&lt;/strong&gt;&lt;/font&gt; to &lt;font face="Consolas"&gt;&lt;strong&gt;IQStreamable&amp;lt;double&amp;gt;&lt;/strong&gt;&lt;/font&gt;.&lt;/p&gt;  &lt;p&gt;In the next article we will integrate this usage of &lt;font face="Consolas"&gt;&lt;strong&gt;IQStreamable&lt;/strong&gt;&lt;/font&gt;s with Subjects in StreamInsight, so stay tuned!&lt;/p&gt;  &lt;p&gt;Regards,    &lt;br /&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44888" width="1" height="1"&gt;</description></item><item><title>A Hitchhiker's Guide to StreamInsight 2.1 Queries</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/08/01/a-hitchhiker-s-guide-to-streaminsight-2-1-queries.aspx</link><pubDate>Thu, 02 Aug 2012 04:42:59 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44556</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44556.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44556</wfw:commentRss><description>&lt;p&gt;Back in 2010 we released the &lt;a href="http://blogs.msdn.com/b/streaminsight/archive/2010/06/08/hitchhiker-s-guide-to-streaminsight-queries.aspx"&gt;first version&lt;/a&gt; of an educational guide to StreamInsight Queries to help developers mind shift into the new paradigm. With the release of StreamInsight 2.1 and introducing the New Programming Model, we thought this was the right time to freshen up this document.&lt;/p&gt;  &lt;p&gt;The format and the storyline stay mostly untouched from the original. There are several improvements to the document. It is updated to the new programming model introduced in v2.1. As a consequence we do not talk about adapters anymore, as they are not necessary to introduce the query language, and it helps simplify the narrative. We have also improved and extended event data visualizations, which makes it easier to understand and follow the queries.&lt;/p&gt;  &lt;p&gt;The guide consists of a &lt;a href="http://go.microsoft.com/fwlink/?LinkId=256236"&gt;PDF document&lt;/a&gt; and a &lt;a href="http://go.microsoft.com/fwlink/?LinkID=259619"&gt;Visual Studio solution&lt;/a&gt; that accompanies the paper.&lt;/p&gt;  &lt;p&gt;The VS solution is also part of the &lt;a href="http://streaminsight.codeplex.com/releases/view/90143"&gt;StreamInsight 2.1 samples&lt;/a&gt; on CodePlex and the queries discussed in the paper are also included in the StreamInsight 2.1 LinqPad samples.&lt;/p&gt;  &lt;p&gt;Regards,&lt;/p&gt;  &lt;p&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44556" width="1" height="1"&gt;</description></item><item><title>Dangers of time travel</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/07/16/dangers-of-time-travel.aspx</link><pubDate>Tue, 17 Jul 2012 00:00:28 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44315</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44315.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44315</wfw:commentRss><description>&lt;p&gt;I tend to partition StreamInsight operators into three classes: the basic “temporal/relational” operators; the “time travel” operators, and; the “elephant” operators. The basic operators illustrate the rules. The time travel operators bend the rules. The scan operators break them altogether. While I’d like to focus on time travel today, we can’t bend the rules before knowing what they are. Let’s begin with the basics! &lt;/p&gt;  &lt;p&gt;A StreamInsight query describes how the results of a normal relational query change over time. The start time of an event indicates the time that a row is inserted into the relational input. The end time indicates when that row is deleted. StreamInsight’s basic temporal/relational operators can be understood in those terms. For instance, the StreamInsight ‘join’ operator produces output for coincident input tuples matching some predicate. Tuples are coincident if their time intervals overlap. Another way of looking at it: all matching tuples across all time logically produce output, but that output may have an empty temporal intersection. The basic temporal/relational operators:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Join&lt;/li&gt;    &lt;li&gt;Left anti-join&lt;/li&gt;    &lt;li&gt;Selection&lt;/li&gt;    &lt;li&gt;Projection&lt;/li&gt;    &lt;li&gt;Group and apply&lt;/li&gt;    &lt;li&gt;Snapshot window operators (aggregate, top-K, user-defined operator).&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Time travel operators bend the rules because they allow an input event to contribute to results outside of their original time interval! The time travel operators: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Hopping/tumbling window operators, because an event contributes to the window result even if was active for only a portion of the window.&lt;/li&gt;    &lt;li&gt;Clip event duration, because the clipper masks the clippee for the rest of time.&lt;/li&gt;    &lt;li&gt;Alter event lifetime, because it changes the time interval for an event.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The fundamental time travel operator is alter event lifetime because the others can be expressed in terms of it. (I’ll leave this as an exercise for the reader). A hint for hopping window operators: one way of thinking about a hopping window is that events belonging to the same window are reassigned to the same time interval so that they can contribute to the same output time interval!) While there are several variations on the alter lifetime operator, they all boil down to the following components:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;An input stream.&lt;/li&gt;    &lt;li&gt;An (optional) function that modifies the start time of events in the stream.&lt;/li&gt;    &lt;li&gt;An (optional) function that modifies the duration of events in the stream.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you do modify start times and durations, make sure that the modifications to start and end times are monotonic. In other words, make sure that the changes do not affect the relative order of start and end edge events. Otherwise, you risk introducing CTI violations. CTI violations bring down the query: they indicate that a new event has arrived affecting a result that has already been committed! Like traveling through time to alter the past, violating CTIs causes (can I even use that word here?) bad things to happen. &lt;/p&gt;  &lt;p&gt;Shifting all events forward or backward by a fixed amount is safe because the CTIs are moving with the events*:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; shiftedBack = source.ShiftEventTime(_ =&amp;gt; &lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(-1));       &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; shiftedForward = source.ShiftEventTime(_ =&amp;gt; &lt;span&gt;TimeSpan&lt;/span&gt;.FromDays(7));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Making time pass faster or slower doesn’t violate the monotonicity requirement, but depending on the nature of the input can introduce CTI violations. If the input stream contains end edge events, then they could also violate CTIs if not modified, as in the following example which attempts to double the speed at which time passes:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; startTime = &lt;span&gt;DateTimeOffset&lt;/span&gt;.UtcNow;       &lt;br /&gt;      &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; source = &lt;span&gt;this&lt;/span&gt;.Application       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .DefineEnumerable(() =&amp;gt; &lt;span&gt;new&lt;/span&gt;[]       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateCti&amp;lt;&lt;span&gt;int&lt;/span&gt;&amp;gt;(startTime),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateStart(startTime, 0),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateCti&amp;lt;&lt;span&gt;int&lt;/span&gt;&amp;gt;(startTime.AddSeconds(10)),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateEnd(startTime, startTime.AddSeconds(10), 0),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateCti&amp;lt;&lt;span&gt;int&lt;/span&gt;&amp;gt;(startTime.AddSeconds(11)),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; })       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .ToStreamable(&lt;span&gt;AdvanceTimeSettings&lt;/span&gt;.StrictlyIncreasingStartTime);       &lt;br /&gt;      &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; fastForward = source.AlterEventStartTime(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; e =&amp;gt; e.StartTime.AddTicks(e.StartTime.Ticks));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;We can address the failure by ensuring that end edges also advance at double-speed:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; fastForward = source.AlterEventLifetime(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; e =&amp;gt; e.StartTime.AddTicks(e.StartTime.Ticks),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; e =&amp;gt; &lt;span&gt;TimeSpan&lt;/span&gt;.FromTicks((e.EndTime - e.StartTime).Ticks * 2L));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;There is a very important loophole that can be exploited for duration modifications. If the duration selector returns a fixed value for every event, StreamInsight no longer needs to produce end edges internally, and those non-existent end edges no longer pose a CTI violation risk:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; fastForwardFixedInterval = source.AlterEventLifetime(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; e =&amp;gt; e.StartTime.AddTicks(e.StartTime.Ticks),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; _ =&amp;gt; &lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(1));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;In summary, there are several completely safe forms of time travel in StreamInsight:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Shift all events forward or backward in time by a fixed amount.&lt;/li&gt;    &lt;li&gt;Established a fixed duration for events.&lt;/li&gt;    &lt;li&gt;Apply modifications that do not affect the relative order of start and end edges.&lt;/li&gt;    &lt;li&gt;The built-in time travel operators, clip and hopping window.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;While it may be safe to stray from these rules for specific data and query combinations, I suggest playing it safe!&lt;/p&gt;  &lt;p&gt;* Notice that the start time selector function does not allow behavior to be affected by event payload. This is because CTI events, which are also modified by the selector, do not carry payloads.&lt;/p&gt;  &lt;p&gt;Regards,   &lt;br /&gt;Colin Meek/The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44315" width="1" height="1"&gt;</description></item><item><title>StreamInsight 2.1, meet LINQ</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/07/09/streaminsight-2-1-meet-linq.aspx</link><pubDate>Tue, 10 Jul 2012 02:17:42 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44229</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44229.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44229</wfw:commentRss><description>&lt;p&gt;Someone recently called LINQ “magic” in my hearing. I leapt to LINQ’s defense immediately. Turns out some people don’t realize “magic” is can be a pejorative term. I thought LINQ needed demystification. Here’s your best demystification resource: &lt;a href="http://blogs.msdn.com/b/mattwar/archive/2008/11/18/linq-links.aspx"&gt;http://blogs.msdn.com/b/mattwar/archive/2008/11/18/linq-links.aspx&lt;/a&gt;. I won’t repeat much of what Matt Warren says in his excellent series, but will talk about some core ideas and how they affect the 2.1 release of StreamInsight.&lt;/p&gt;  &lt;p&gt;Let’s tell the story of a LINQ query.&lt;/p&gt;  &lt;h3&gt;Compile time&lt;/h3&gt;  &lt;p&gt;It begins with some code:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;IQueryable&amp;lt;Product&amp;gt; products = ...;      &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; query = &lt;span&gt;from&lt;/span&gt; p &lt;span&gt;in&lt;/span&gt; products       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;where&lt;/span&gt; p.Name == &lt;span&gt;&amp;quot;Widget&amp;quot;&lt;/span&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;select&lt;/span&gt; p.ProductID;       &lt;br /&gt;&lt;span&gt;foreach&lt;/span&gt; (&lt;span&gt;int&lt;/span&gt; id &lt;span&gt;in&lt;/span&gt; query)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ...&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;When the code is compiled, the C# compiler (among other things) de-sugars the query expression (see &lt;a href="http://msdn.microsoft.com/en-us/library/ms228593.aspx"&gt;C# spec&lt;/a&gt; section 7.16):&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;...      &lt;br /&gt;var query = products.Where(p =&amp;gt; p.Name == &lt;span&gt;&amp;quot;Widget&amp;quot;&lt;/span&gt;).Select(p =&amp;gt; p.ProductID);       &lt;br /&gt;...&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Overload resolution subsequently binds the &lt;b&gt;&lt;font face="Consolas"&gt;Queryable.Where&amp;lt;Product&amp;gt;&lt;/font&gt; &lt;/b&gt;and &lt;b&gt;&lt;font face="Consolas"&gt;Queryable.Select&amp;lt;Product, int&amp;gt;&lt;/font&gt; &lt;/b&gt;extension methods (see &lt;a href="http://msdn.microsoft.com/en-us/library/ms228593.aspx"&gt;C# spec&lt;/a&gt; sections 7.5 and 7.6.5). After overload resolution, the compiler knows something interesting about the anonymous functions (lambda syntax) in the de-sugared code: they must be converted to expression trees, i.e.,“&lt;em&gt;an object structure that represents the structure of the anonymous function itself&lt;/em&gt;” (see &lt;a href="http://msdn.microsoft.com/en-us/library/ms228593.aspx"&gt;C# spec&lt;/a&gt; section 6.5). The conversion is equivalent to the following rewrite:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;...      &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; prm1 = Expression.Parameter(&lt;span&gt;typeof&lt;/span&gt;(Product), &lt;span&gt;&amp;quot;p&amp;quot;&lt;/span&gt;);       &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; prm2 = Expression.Parameter(&lt;span&gt;typeof&lt;/span&gt;(Product), &lt;span&gt;&amp;quot;p&amp;quot;&lt;/span&gt;);       &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; query = Queryable.Select&amp;lt;Product, &lt;span&gt;int&lt;/span&gt;&amp;gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Queryable.Where&amp;lt;Product&amp;gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; products,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Expression.Lambda&amp;lt;&lt;span&gt;Func&lt;/span&gt;&amp;lt;Product, &lt;span&gt;bool&lt;/span&gt;&amp;gt;&amp;gt;(Expression.Property(prm1, &lt;span&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;), prm1)),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Expression.Lambda&amp;lt;&lt;span&gt;Func&lt;/span&gt;&amp;lt;Product, &lt;span&gt;int&lt;/span&gt;&amp;gt;&amp;gt;(Expression.Property(prm2, &lt;span&gt;&amp;quot;ProductID&amp;quot;&lt;/span&gt;), prm2));       &lt;br /&gt;...&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;If the “products” expression had type &lt;b&gt;&lt;font face="Consolas"&gt;IEnumerable&amp;lt;Product&amp;gt;&lt;/font&gt;&lt;/b&gt;, the compiler would have chosen the &lt;b&gt;&lt;font face="Consolas"&gt;Enumerable.Where&lt;/font&gt; &lt;/b&gt;and &lt;b&gt;&lt;font face="Consolas"&gt;Enumerable.Select&lt;/font&gt; &lt;/b&gt;extension methods&lt;b&gt; &lt;/b&gt;instead, in which case the anonymous functions would have been converted to delegates.&lt;/p&gt;  &lt;p&gt;At this point, we’ve reduced the LINQ query to familiar code that will compile in C# 2.0. (Note that I’m using C# snippets to illustrate transformations that occur in the compiler, not to suggest a viable compiler design!)&lt;/p&gt;  &lt;h3&gt;Runtime&lt;/h3&gt;  &lt;p&gt;When the above program is executed, the&lt;b&gt; &lt;font face="Consolas"&gt;Queryable.Where&lt;/font&gt; &lt;/b&gt;method is invoked. It takes two arguments. The first is an &lt;b&gt;&lt;font face="Consolas"&gt;IQueryable&amp;lt;&amp;gt;&lt;/font&gt; &lt;/b&gt;instance that exposes an &lt;b&gt;&lt;font face="Consolas"&gt;Expression&lt;/font&gt; &lt;/b&gt;property and a &lt;b&gt;&lt;font face="Consolas"&gt;Provider&lt;/font&gt; &lt;/b&gt;property. The second is an expression tree. The &lt;b&gt;&lt;font face="Consolas"&gt;Queryable.Where&lt;/font&gt; &lt;/b&gt;method implementation looks something like this:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; IQueryable&amp;lt;T&amp;gt; Where&amp;lt;T&amp;gt;(&lt;span&gt;this&lt;/span&gt; IQueryable&amp;lt;T&amp;gt; source, Expression&amp;lt;&lt;span&gt;Func&lt;/span&gt;&amp;lt;T, &lt;span&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; predicate)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;return&lt;/span&gt; source.Provider.CreateQuery&amp;lt;T&amp;gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Expression.Call(&lt;span&gt;this&lt;/span&gt; method, source.Expression, Expression.Quote(predicate)));       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Notice that the method is really just composing a new expression tree that calls itself with arguments derived from the source and predicate arguments. Also notice that the query object returned from the method is associated with the same provider as the source query.&lt;/p&gt;  &lt;p&gt;By invoking operator methods, we’re constructing an expression tree that describes a query. Interestingly, the compiler and operator methods are colluding to construct a query expression tree. The important takeaway is that expression trees are built in one of two ways: (1) by the compiler when it sees an anonymous function that needs to be converted to an expression tree, and; (2) by a query operator method that constructs a new queryable object with an expression tree rooted in a call to the operator method (self-referential).&lt;/p&gt;  &lt;p&gt;Next we hit the &lt;b&gt;&lt;font face="Consolas"&gt;foreach&lt;/font&gt;&lt;/b&gt; block. At this point, the power of LINQ queries becomes apparent. The provider is able to determine how the query expression tree is evaluated! The code that began our story was intentionally vague about the definition of the “products” collection. Maybe it is a queryable in-memory collection of products:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; products = &lt;span&gt;new&lt;/span&gt;[]      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { &lt;span&gt;new&lt;/span&gt; Product { Name = &lt;span&gt;&amp;quot;Widget&amp;quot;&lt;/span&gt;, ProductID = 1 } }.AsQueryable();&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The in-memory LINQ provider works by rewriting &lt;b&gt;&lt;font face="Consolas"&gt;Queryable&lt;/font&gt; &lt;/b&gt;method calls to &lt;b&gt;&lt;font face="Consolas"&gt;Enumerable&lt;/font&gt;&lt;/b&gt; method calls in the query expression tree. It then compiles the expression tree and evaluates it. It should be mentioned that the provider does not blindly rewrite all &lt;b&gt;&lt;font face="Consolas"&gt;Queryable&lt;/font&gt; &lt;/b&gt;calls. It only rewrites a call when its arguments have been rewritten in a way that introduces a type mismatch, e.g. the first argument to &lt;b&gt;&lt;font face="Consolas"&gt;Queryable.Where&amp;lt;Product&amp;gt;&lt;/font&gt;&lt;/b&gt; being rewritten as an expression of type &lt;b&gt;&lt;font face="Consolas"&gt;IEnumerable&amp;lt;Product&amp;gt;&lt;/font&gt;&lt;/b&gt; from &lt;b&gt;&lt;font face="Consolas"&gt;IQueryable&amp;lt;Product&amp;gt;&lt;/font&gt;&lt;/b&gt;. The type mismatch is triggered initially by a “leaf” expression like the one associated with the &lt;b&gt;&lt;font face="Consolas"&gt;AsQueryable&lt;/font&gt;&lt;/b&gt; query: when the provider recognizes one of its own leaf expressions, it replaces the expression with the original &lt;b&gt;&lt;font face="Consolas"&gt;IEnumerable&amp;lt;&amp;gt;&lt;/font&gt; &lt;/b&gt;constant expression. I like to think of this rewrite process as “type irritation” because the rewritten leaf expression is like a foreign body that triggers an immune response (further rewrites) in the tree. The technique ensures that only those portions of the expression tree constructed by a particular provider are rewritten by that provider: no type irritation, no rewrite.&lt;/p&gt;  &lt;p&gt;Let’s consider the behavior of an alternative LINQ provider. If “products” is a collection created by a LINQ to SQL provider:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; products = &lt;span&gt;new&lt;/span&gt; NorthwindDataContext().Products;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;the provider rewrites the expression tree as a SQL query that is then evaluated by your favorite RDBMS. The predicate may ultimately be evaluated using an index! In this example, the expression associated with the &lt;b&gt;&lt;font face="Consolas"&gt;Products&lt;/font&gt;&lt;/b&gt; property is the “leaf” expression.&lt;/p&gt;  &lt;h3&gt;StreamInsight 2.1&lt;/h3&gt;  &lt;p&gt;For the in-memory LINQ to Objects provider, a leaf is an in-memory collection. For LINQ to SQL, a leaf is a table or view.&lt;/p&gt;  &lt;p&gt;When &lt;a href="http://blogs.msdn.com/b/streaminsight/archive/2012/06/25/streaminsight-2-1-released.aspx"&gt;defining a “process”&lt;/a&gt; in StreamInsight 2.1, what is a leaf? To StreamInsight a leaf is &lt;i&gt;logic&lt;/i&gt;: an adapter, a sequence, or even a query targeting an entirely different LINQ provider! &lt;/p&gt;  &lt;p&gt;How do we represent the logic? Remember that a standing query may outlive the client that provisioned it. A reference to a sequence object in the client application is therefore not terribly useful. But if we instead represent the code constructing the sequence as an expression, we can host the sequence in the server:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;using&lt;/span&gt; (&lt;span&gt;var&lt;/span&gt; server = &lt;span&gt;Server&lt;/span&gt;.Connect(...))       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; app = server.Applications[&lt;span&gt;&amp;quot;my application&amp;quot;&lt;/span&gt;];       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; source = app.DefineObservable(() =&amp;gt; Observable.Range(0, 10, Scheduler.NewThread));       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; query = &lt;span&gt;from&lt;/span&gt; i &lt;span&gt;in&lt;/span&gt; source &lt;span&gt;where&lt;/span&gt; i % 2 == 0 &lt;span&gt;select&lt;/span&gt; i;       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;b&gt;&lt;i&gt;Example 1: defining a source and composing a query&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Let’s look in more detail at what’s happening in example 1. We first connect to the remote &lt;b&gt;&lt;font face="Consolas"&gt;server&lt;/font&gt;&lt;/b&gt; and retrieve an existing &lt;b&gt;&lt;font face="Consolas"&gt;app&lt;/font&gt;&lt;/b&gt;. Next, we define a simple Reactive sequence using the &lt;b&gt;&lt;font face="Consolas"&gt;Observable.Range&lt;/font&gt;&lt;/b&gt; method. Notice that the call to the &lt;b&gt;&lt;font face="Consolas"&gt;Range&lt;/font&gt;&lt;/b&gt; method is in the body of an anonymous function. This is important because it means the &lt;b&gt;&lt;font face="Consolas"&gt;source&lt;/font&gt; &lt;/b&gt;sequence definition is in the form of an expression, rather than simply an opaque reference to an &lt;b&gt;&lt;font face="Consolas"&gt;IObservable&amp;lt;int&amp;gt;&lt;/font&gt;&lt;/b&gt; object. The variation in Example 2 fails. Although it looks similar, the sequence is now a reference to an in-memory observable collection:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; local = Observable.Range(0, 10, Scheduler.NewThread);       &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; source = app.DefineObservable(() =&amp;gt; local); &lt;span&gt;// can’t serialize ‘local’!&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;b&gt;&lt;i&gt;Example 2: error referencing unserializable local object&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The &lt;b&gt;&lt;font face="Consolas"&gt;Define*&lt;/font&gt;&lt;/b&gt; methods support definitions of operator tree leaves that target the StreamInsight server. These methods all have the same basic structure. The definition argument is a lambda expression taking between 0 and 16 arguments and returning a source or sink. The method returns a proxy for the source or sink that can then be used for the usual style of LINQ query composition. The “define” methods exploit the &lt;i&gt;compile-time&lt;/i&gt; C# feature that converts anonymous functions into translatable expression trees!&lt;/p&gt;  &lt;p&gt;Query composition exploits the &lt;i&gt;runtime pattern&lt;/i&gt; that allows expression trees to be constructed by operators taking queryable and expression (&lt;b&gt;&lt;font face="Consolas"&gt;Expression&amp;lt;&amp;gt;&lt;/font&gt;&lt;/b&gt;) arguments. The practical upshot: once you’ve &lt;b&gt;&lt;font face="Consolas"&gt;Define&lt;/font&gt;&lt;/b&gt;d a source, you can compose LINQ queries in the familiar way using query expressions and operator combinators. Notably, queries can be composed using pull-sequences (LINQ to Objects &lt;b&gt;&lt;font face="Consolas"&gt;IQueryable&amp;lt;&amp;gt;&lt;/font&gt; &lt;/b&gt;inputs), push sequences (Reactive &lt;b&gt;&lt;font face="Consolas"&gt;IQbservable&amp;lt;&amp;gt;&lt;/font&gt;&lt;/b&gt; inputs), and temporal sequences (StreamInsight &lt;b&gt;&lt;font face="Consolas"&gt;IQStreamable&amp;lt;&amp;gt;&lt;/font&gt;&lt;/b&gt; inputs). You can even construct processes that span these three domains using “bridge” method overloads (&lt;b&gt;&lt;font face="Consolas"&gt;ToEnumerable&lt;/font&gt;&lt;/b&gt;, &lt;b&gt;&lt;font face="Consolas"&gt;ToObservable&lt;/font&gt;&lt;/b&gt; and &lt;b&gt;&lt;font face="Consolas"&gt;To*Streamable&lt;/font&gt;&lt;/b&gt;).&lt;/p&gt;  &lt;p&gt;Finally, the &lt;i&gt;targeted rewrite&lt;/i&gt; &lt;i&gt;via type irritation &lt;/i&gt;pattern is used to ensure that StreamInsight computations can leverage other LINQ providers as well. Consider the following example (this example depends on &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=27203"&gt;Interactive Extensions&lt;/a&gt;):&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; source = app.DefineEnumerable((&lt;span&gt;int&lt;/span&gt; id) =&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; EnumerableEx.Using(() =&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;new&lt;/span&gt; NorthwindDataContext(), context =&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;from&lt;/span&gt; p &lt;span&gt;in&lt;/span&gt; context.Products       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;where&lt;/span&gt; p.ProductID == id       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;select&lt;/span&gt; p.ProductName));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Within the definition, StreamInsight has no reason to suspect that it ‘owns’ the &lt;b&gt;Queryable.Where &lt;/b&gt;and &lt;b&gt;Queryable.Select &lt;/b&gt;calls, and it can therefore defer to LINQ to SQL! Let’s use this source in the context of a StreamInsight process:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; sink = app.DefineObserver(() =&amp;gt; Observer.Create&amp;lt;&lt;span&gt;string&lt;/span&gt;&amp;gt;(&lt;span&gt;Console&lt;/span&gt;.WriteLine));       &lt;br /&gt;      &lt;br /&gt;&lt;span&gt;var&lt;/span&gt; query = &lt;span&gt;from&lt;/span&gt; name &lt;span&gt;in&lt;/span&gt; source(1).ToObservable()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;where&lt;/span&gt; name == &lt;span&gt;&amp;quot;Widget&amp;quot;&lt;/span&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;select&lt;/span&gt; name;       &lt;br /&gt;      &lt;br /&gt;&lt;span&gt;using&lt;/span&gt; (query.Bind(sink).Run(&lt;span&gt;&amp;quot;process&amp;quot;&lt;/span&gt;))       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ...       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;When we run the binding, the &lt;b&gt;&lt;font face="Consolas"&gt;source&lt;/font&gt;&lt;/b&gt; portion which filters on product ID and projects the product name is evaluated by SQL Server. Outside of the definition, responsibility for evaluation shifts to the StreamInsight server where we create a bridge to the Reactive Framework (using &lt;b&gt;&lt;font face="Consolas"&gt;ToObservable&lt;/font&gt;&lt;/b&gt;) and evaluate an additional predicate.&lt;/p&gt;  &lt;p&gt;It’s incredibly easy to define computations that span multiple domains using these new features in StreamInsight 2.1!&lt;/p&gt;  &lt;p&gt;Regards,    &lt;br /&gt;The StreamInsight Team&lt;/p&gt;  &lt;hr align="left" /&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44229" width="1" height="1"&gt;</description></item><item><title>Taming Hopping Windows</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/07/03/taming-hopping-windows.aspx</link><pubDate>Wed, 04 Jul 2012 00:03:06 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44192</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44192.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44192</wfw:commentRss><description>&lt;p&gt;At first glance, hopping windows seem fairly innocuous and obvious. They organize events into windows with a simple periodic definition: the windows have some duration &lt;i&gt;d &lt;/i&gt;(e.g. a window covers 5 second time intervals), an interval or period &lt;i&gt;p &lt;/i&gt;(e.g. a new window starts every 2 seconds) and an alignment &lt;i&gt;a &lt;/i&gt;(e.g. one of those windows starts at 12:00 PM on March 15, 2012 UTC).&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; wins = xs      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .HoppingWindow(&lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(5),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(2),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;new&lt;/span&gt; &lt;span&gt;DateTime&lt;/span&gt;(2012, 3, 15, 12, 0, 0, &lt;span&gt;DateTimeKind&lt;/span&gt;.Utc));&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Logically, there is a window with start time &lt;i&gt;a &lt;/i&gt;+ &lt;i&gt;np&lt;/i&gt; and end time &lt;i&gt;a &lt;/i&gt;+ &lt;i&gt;np&lt;/i&gt; + &lt;i&gt;d&lt;/i&gt; for every integer &lt;i&gt;n&lt;/i&gt;. That’s a lot of windows. So why doesn’t the following query (always) blow up? &lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; query = wins.Select(win =&amp;gt; win.Count());&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;A few users have asked why StreamInsight doesn’t produce output for empty windows. Primarily it’s because there is an infinite number of empty windows! (Actually, StreamInsight uses &lt;b&gt;DateTimeOffset.MaxValue&lt;/b&gt; to approximate “the end of time” and &lt;b&gt;DateTimeOffset.MinValue&lt;/b&gt; to approximate “the beginning of time”, so the number of windows is lower in practice.)&lt;/p&gt;  &lt;p&gt;That was the good news. Now the bad news. Events also have duration. Consider the following simple input:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;var&lt;/span&gt; xs = &lt;span&gt;this&lt;/span&gt;.Application       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; .DefineEnumerable(() =&amp;gt; &lt;span&gt;new&lt;/span&gt;[]       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateStart(&lt;span&gt;DateTimeOffset&lt;/span&gt;.UtcNow, 0) })       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; .ToStreamable(&lt;span&gt;AdvanceTimeSettings&lt;/span&gt;.IncreasingStartTime);&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Because the event has no explicit end edge, it lasts until the end of time. So there are lots of non-empty windows if we apply a hopping window to that single event! For this reason, we need to be careful with hopping window queries in StreamInsight. Or we can switch to a custom implementation of hopping windows that doesn’t suffer from this shortcoming.&lt;/p&gt;  &lt;p&gt;The alternate window implementation produces output &lt;i&gt;only when the input changes&lt;/i&gt;. We start by breaking up the timeline into non-overlapping intervals assigned to each window. In figure 1, six hopping windows (“Windows”) are assigned to six intervals (“Assignments”) in the timeline. Next we take input events (“Events”) and alter their lifetimes (“Altered Events”) so that they cover the intervals of the windows they intersect. In figure 1, you can see that the first event &lt;i&gt;e&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; intersects windows &lt;i&gt;w&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; and &lt;i&gt;w&lt;/i&gt;&lt;sub&gt;2&lt;/sub&gt; so it is adjusted to cover assignments &lt;i&gt;a&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; and &lt;i&gt;a&lt;/i&gt;&lt;sub&gt;2&lt;/sub&gt;. Finally, we can use snapshot windows (“Snapshots”) to produce output for the hopping windows. Notice however that instead of having six windows generating output, we have only four. The first and second snapshots correspond to the first and second hopping windows. The remaining snapshots however cover two hopping windows each! While in this example we saved only two events, the savings can be more significant when the ratio of event duration to window duration is higher. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/8713.image4.png"&gt;&lt;img style="border:0px currentcolor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/2450.image4_5F00_thumb.png" width="550" height="426" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Figure 1: Timeline&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The implementation of this strategy is straightforward. We need to set the start times of events to the start time of the interval assigned to the earliest window including the start time. Similarly, we need to modify the end times of events to the end time of the interval assigned to the latest window including the end time. The following snap-to-boundary function that rounds a timestamp value &lt;i&gt;t&lt;/i&gt; down to the nearest value &lt;i&gt;t' &lt;/i&gt;&amp;lt;= &lt;i&gt;t&lt;/i&gt; such that &lt;i&gt;t' &lt;/i&gt;is &lt;i&gt;a &lt;/i&gt;+&lt;i&gt; np &lt;/i&gt;for some integer &lt;i&gt;n&lt;/i&gt; will be useful. For convenience, we will represent both DateTime and TimeSpan values using long ticks:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;static&lt;/span&gt; &lt;span&gt;long&lt;/span&gt; SnapToBoundary(&lt;span&gt;long&lt;/span&gt; t, &lt;span&gt;long&lt;/span&gt; a, &lt;span&gt;long&lt;/span&gt; p)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;return&lt;/span&gt; t - ((t - a) % p) - (t &amp;gt; a ? 0L : p);       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;How do we find the earliest window including the start time for an event? It’s the window following the last window that does not include the start time &lt;i&gt;assuming that there are no gaps in the windows (i.e. duration &amp;lt; interval), and limitation of this solution&lt;/i&gt;. To find the end time of that antecedent window, we need to know the alignment of window ends:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;long&lt;/span&gt; e = a + (d % p);&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Using the window end alignment, we are finally ready to describe the start time selector:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;static&lt;/span&gt; &lt;span&gt;long&lt;/span&gt; AdjustStartTime(&lt;span&gt;long&lt;/span&gt; t, &lt;span&gt;long&lt;/span&gt; e, &lt;span&gt;long&lt;/span&gt; p)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;return&lt;/span&gt; SnapToBoundary(t, e, p) + p;       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;To find the latest window including the end time for an event, we look for the last window start time (non-inclusive):&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;long&lt;/span&gt; AdjustEndTime(&lt;span&gt;long&lt;/span&gt; t, &lt;span&gt;long&lt;/span&gt; a, &lt;span&gt;long&lt;/span&gt; d, &lt;span&gt;long&lt;/span&gt; p)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;return&lt;/span&gt; SnapToBoundary(t - 1, a, p) + p + d;       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Bringing it together, we can define the translation from events to ‘altered events’ as in Figure 1:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;IQStreamable&lt;/span&gt;&amp;lt;T&amp;gt; SnapToWindowIntervals&amp;lt;T&amp;gt;(&lt;span&gt;IQStreamable&lt;/span&gt;&amp;lt;T&amp;gt; source, &lt;span&gt;TimeSpan&lt;/span&gt; duration, &lt;span&gt;TimeSpan&lt;/span&gt; interval, &lt;span&gt;DateTime&lt;/span&gt; alignment)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;if&lt;/span&gt; (source == &lt;span&gt;null&lt;/span&gt;) &lt;span&gt;throw&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; &lt;span&gt;ArgumentNullException&lt;/span&gt;(&lt;span&gt;&amp;quot;source&amp;quot;&lt;/span&gt;);       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;// reason about DateTime and TimeSpan in ticks &lt;/span&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;long&lt;/span&gt; d = &lt;span&gt;Math&lt;/span&gt;.Min(&lt;span&gt;DateTime&lt;/span&gt;.MaxValue.Ticks, duration.Ticks);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;long&lt;/span&gt; p = &lt;span&gt;Math&lt;/span&gt;.Min(&lt;span&gt;DateTime&lt;/span&gt;.MaxValue.Ticks, &lt;span&gt;Math&lt;/span&gt;.Abs(interval.Ticks));       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;// set alignment to earliest possible window &lt;/span&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; a = alignment.ToUniversalTime().Ticks % p;       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;// verify constraints of this solution &lt;/span&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;if&lt;/span&gt; (d &amp;lt;= 0L) { &lt;span&gt;throw&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; &lt;span&gt;ArgumentOutOfRangeException&lt;/span&gt;(&lt;span&gt;&amp;quot;duration&amp;quot;&lt;/span&gt;); }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;if&lt;/span&gt; (p == 0L || p &amp;gt; d) { &lt;span&gt;throw&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; &lt;span&gt;ArgumentOutOfRangeException&lt;/span&gt;(&lt;span&gt;&amp;quot;interval&amp;quot;&lt;/span&gt;); }       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;// find the alignment of window ends &lt;/span&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;long&lt;/span&gt; e = a + (d % p);       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;return&lt;/span&gt; source.AlterEventLifetime(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; evt =&amp;gt; ToDateTime(AdjustStartTime(evt.StartTime.ToUniversalTime().Ticks, e, p)),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; evt =&amp;gt; ToDateTime(AdjustEndTime(evt.EndTime.ToUniversalTime().Ticks, a, d, p)) -       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ToDateTime(AdjustStartTime(evt.StartTime.ToUniversalTime().Ticks, e, p)));       &lt;br /&gt;}       &lt;br /&gt;      &lt;br /&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;DateTime&lt;/span&gt; ToDateTime(&lt;span&gt;long&lt;/span&gt; ticks)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;// just snap to min or max value rather than under/overflowing &lt;/span&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;return&lt;/span&gt; ticks &amp;lt; &lt;span&gt;DateTime&lt;/span&gt;.MinValue.Ticks       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ? &lt;span&gt;new&lt;/span&gt; &lt;span&gt;DateTime&lt;/span&gt;(&lt;span&gt;DateTime&lt;/span&gt;.MinValue.Ticks, &lt;span&gt;DateTimeKind&lt;/span&gt;.Utc)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : ticks &amp;gt; &lt;span&gt;DateTime&lt;/span&gt;.MaxValue.Ticks       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ? &lt;span&gt;new&lt;/span&gt; &lt;span&gt;DateTime&lt;/span&gt;(&lt;span&gt;DateTime&lt;/span&gt;.MaxValue.Ticks, &lt;span&gt;DateTimeKind&lt;/span&gt;.Utc)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : &lt;span&gt;new&lt;/span&gt; &lt;span&gt;DateTime&lt;/span&gt;(ticks, &lt;span&gt;DateTimeKind&lt;/span&gt;.Utc);       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Finally, we can describe our custom hopping window operator:&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;IQWindowedStreamable&lt;/span&gt;&amp;lt;T&amp;gt; HoppingWindow2&amp;lt;T&amp;gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;IQStreamable&lt;/span&gt;&amp;lt;T&amp;gt; source,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;TimeSpan&lt;/span&gt; duration,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;TimeSpan&lt;/span&gt; interval,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;DateTime&lt;/span&gt; alignment)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;if&lt;/span&gt; (source == &lt;span&gt;null&lt;/span&gt;) { &lt;span&gt;throw&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; &lt;span&gt;ArgumentNullException&lt;/span&gt;(&lt;span&gt;&amp;quot;source&amp;quot;&lt;/span&gt;); }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;return&lt;/span&gt; SnapToWindowIntervals(source, duration, interval, alignment).SnapshotWindow();       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;By switching from HoppingWindow to HoppingWindow2 in the following example, the query returns quickly rather than gobbling resources and ultimately failing!&lt;/p&gt;  &lt;div class="le-pavsc-container"&gt;   &lt;div style="padding:2px 5px;overflow:auto;max-height:500px;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Main()       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; start = &lt;span&gt;new&lt;/span&gt; &lt;span&gt;DateTimeOffset&lt;/span&gt;(&lt;span&gt;new&lt;/span&gt; &lt;span&gt;DateTime&lt;/span&gt;(2012, 6, 28), &lt;span&gt;TimeSpan&lt;/span&gt;.Zero);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; duration = &lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(5);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; interval = &lt;span&gt;TimeSpan&lt;/span&gt;.FromSeconds(2);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; alignment = &lt;span&gt;new&lt;/span&gt; &lt;span&gt;DateTime&lt;/span&gt;(2012, 3, 15, 12, 0, 0, &lt;span&gt;DateTimeKind&lt;/span&gt;.Utc);       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; events = &lt;span&gt;this&lt;/span&gt;.Application.DefineEnumerable(() =&amp;gt; &lt;span&gt;new&lt;/span&gt;[]       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateStart(start.AddSeconds(0), &lt;span&gt;&amp;quot;e0&amp;quot;&lt;/span&gt;),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateStart(start.AddSeconds(1), &lt;span&gt;&amp;quot;e1&amp;quot;&lt;/span&gt;),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateEnd(start.AddSeconds(1), start.AddSeconds(2), &lt;span&gt;&amp;quot;e1&amp;quot;&lt;/span&gt;),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateStart(start.AddSeconds(3), &lt;span&gt;&amp;quot;e2&amp;quot;&lt;/span&gt;),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateStart(start.AddSeconds(9), &lt;span&gt;&amp;quot;e3&amp;quot;&lt;/span&gt;),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateEnd(start.AddSeconds(3), start.AddSeconds(10), &lt;span&gt;&amp;quot;e2&amp;quot;&lt;/span&gt;),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;EdgeEvent&lt;/span&gt;.CreateEnd(start.AddSeconds(9), start.AddSeconds(10), &lt;span&gt;&amp;quot;e3&amp;quot;&lt;/span&gt;),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }).ToStreamable(&lt;span&gt;AdvanceTimeSettings&lt;/span&gt;.IncreasingStartTime);       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; adjustedEvents = SnapToWindowIntervals(events, duration, interval, alignment);       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;var&lt;/span&gt; query = &lt;span&gt;from&lt;/span&gt; win &lt;span&gt;in&lt;/span&gt; HoppingWindow2(events, duration, interval, alignment)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;select&lt;/span&gt; win.Count();       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; DisplayResults(adjustedEvents, &lt;span&gt;&amp;quot;Adjusted Events&amp;quot;&lt;/span&gt;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; DisplayResults(query, &lt;span&gt;&amp;quot;Query&amp;quot;&lt;/span&gt;);       &lt;br /&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;As you can see, instead of producing a massive number of windows for the open start edge &lt;i&gt;e&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt;, a single window is emitted from 12:00:15 AM until the end of time:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Adjusted Events &lt;/b&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="3"&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;&lt;b&gt;StartTime&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;&lt;b&gt;EndTime&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;&lt;b&gt;Payload&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:01 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;12/31/9999 11:59:59 PM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;e0&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:03 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:07 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;e1&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:05 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:15 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;e2&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:11 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:15 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;e3&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;&lt;b&gt;Query &lt;/b&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="3"&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;&lt;b&gt;StartTime&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;&lt;b&gt;EndTime&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;&lt;b&gt;Payload&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:01 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:03 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;1&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:03 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:05 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;2&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:05 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:07 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;3&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:07 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:11 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;2&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:11 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:15 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;3&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;6/28/2012 12:00:15 AM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;12/31/9999 11:59:59 PM&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;1&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;Regards,   &lt;br /&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44192" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/stream_insight/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://sqlblog.com/blogs/stream_insight/archive/tags/Time/default.aspx">Time</category></item><item><title>Changes to the LINQ-to-StreamInsight Dialect</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/06/28/changes-to-the-linq-to-streaminsight-dialect.aspx</link><pubDate>Thu, 28 Jun 2012 17:09:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44137</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44137.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44137</wfw:commentRss><description>&lt;p&gt;In previous versions of StreamInsight (1.0 through 2.0), &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;CepStream&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt; represents temporal streams of many varieties:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Streams with &amp;lsquo;open&amp;rsquo; inputs (e.g., those defined and composed over &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;CepStream&amp;lt;T&amp;gt;.Create(string streamName)&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Streams with &amp;lsquo;partially bound&amp;rsquo; inputs (e.g., those defined and composed over &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;CepStream&amp;lt;T&amp;gt;.Create(Type adapterFactory, &amp;hellip;))&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Streams with fully bound inputs (e.g., those defined and composed over To*Stream &amp;ndash; sequences or DQC)&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;The stream may be embedded (where &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;Server.Create&lt;/strong&gt;&lt;/span&gt; is used)&lt;/li&gt;
&lt;li&gt;The stream may be remote (where &lt;strong&gt;Server.Connect&lt;/strong&gt; is used)&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;When adding support for new programming primitives in StreamInsight 2.1, we faced a choice: Add a fourth variety (use &lt;strong&gt;CepStream&amp;lt;&amp;gt;&lt;/strong&gt; to represent streams that are bound the new programming model constructs), or introduce a separate type that represents temporal streams in the new user model. We opted for the latter. Introducing a new type has the effect of reducing the number of (confusing) runtime failures due to inappropriate uses of &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;CepStream&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt; instances in the incorrect context. The new types are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IStreamable&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt;, which logically represents a temporal stream.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IQStreamable&amp;lt;&amp;gt; : IStreamable&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt;, which represents a &lt;i&gt;queryable&lt;/i&gt; temporal stream. Its relationship to &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IStreamable&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt; is analogous to the relationship of &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IQueryable&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt; to &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IEnumerable&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt;. The developer can compose temporal queries over remote stream sources using this type.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The syntax of temporal queries composed over &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IQStreamable&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt; is mostly consistent with the syntax of our existing &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;CepStream&amp;lt;&amp;gt;&lt;/strong&gt;&lt;/span&gt;-based LINQ provider. However, we have taken the opportunity to refine certain aspects of the language surface. Differences are outlined below. Because 2.1 introduces new types to represent temporal queries, the changes outlined in this post do no impact existing StreamInsight applications using the existing types!&lt;/p&gt;
&lt;h1&gt;SelectMany&lt;/h1&gt;
&lt;p&gt;StreamInsight does not support the &lt;b&gt;SelectMany&lt;/b&gt; operator in its usual form (which is analogous to SQL&amp;rsquo;s &amp;ldquo;CROSS APPLY&amp;rdquo; operator):&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;R&amp;gt; SelectMany&amp;lt;T, R&amp;gt;(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt; source, Func&amp;lt;T, &lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;R&amp;gt;&amp;gt; collectionSelector)&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It instead uses &lt;b&gt;SelectMany&lt;/b&gt; as a convenient syntactic representation of an inner join. The parameter to the selector function is thus unavailable. Because the parameter isn&amp;rsquo;t supported, its type in StreamInsight 1.0 &amp;ndash; 2.0 wasn&amp;rsquo;t carefully scrutinized. Unfortunately, the type chosen for the parameter is nonsensical to LINQ programmers:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;CepStream&lt;/span&gt;&amp;lt;R&amp;gt; SelectMany&amp;lt;T, R&amp;gt;(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;CepStream&lt;/span&gt;&amp;lt;T&amp;gt; source, Expression&amp;lt;&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;CepStream&lt;/span&gt;&amp;lt;T&amp;gt;, &lt;span style="color:#2b91af;"&gt;CepStream&lt;/span&gt;&amp;lt;R&amp;gt;&amp;gt;&amp;gt; streamSelector)&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Using &lt;b&gt;Unit&lt;/b&gt; as the type for the parameter accurately reflects the StreamInsight&amp;rsquo;s capabilities:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IQStreamable&lt;/span&gt;&amp;lt;R&amp;gt; SelectMany&amp;lt;T, R&amp;gt;(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IQStreamable&lt;/span&gt;&amp;lt;T&amp;gt; source, Expression&amp;lt;&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;Unit, &lt;span style="color:#2b91af;"&gt;IQStreamable&lt;/span&gt;&amp;lt;R&amp;gt;&amp;gt;&amp;gt; streamSelector)&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For queries that succeed &amp;ndash; that is, queries that do not reference the stream selector parameter &amp;ndash; there is no difference between the code written for the two overloads:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs &lt;br /&gt;from y &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; ys &lt;br /&gt;select f(x, y)&lt;/div&gt;
&lt;/div&gt;
&lt;h1&gt;Top-K&lt;/h1&gt;
&lt;p&gt;The &lt;b&gt;Take&lt;/b&gt; operator used in StreamInsight causes confusion for LINQ programmers because it is applied to the (unbounded) stream rather than the (bounded) window, suggesting that the query as a whole will return &lt;i&gt;k &lt;/i&gt;rows:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;(&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; win &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;orderby&lt;/span&gt; x.A &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; x.B).Take(k)&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The use of &lt;b&gt;SelectMany&lt;/b&gt; is also unfortunate in this context because it implies the availability of the window parameter within the remainder of the comprehension. The following compiles but fails at runtime:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;(&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; win &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;orderby&lt;/span&gt; x.A &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; win).Take(k)&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;b&gt;Take &lt;/b&gt;operator in 2.1 is applied to the window rather than the stream:&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Before&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;After&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;(&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; win &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;orderby&lt;/span&gt; x.A &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; x.B).Take(k)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;from b &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; win &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;orderby&lt;/span&gt; x.A &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; x.B).Take(k) &lt;br /&gt;select b&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;h1&gt;Multicast&lt;/h1&gt;
&lt;p&gt;We are introducing an explicit multicast operator in order to preserve expression identity, which is important given the semantics about moving code to and from StreamInsight. This also better matches existing LINQ dialects, such as Reactive. This pattern enables expressing multicasting in two ways:&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Implicit&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Explicit&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; ys = &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; x.A &amp;gt; 1 &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; x; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; zs = &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; y1 &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; ys &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; y2 &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; ys.ShiftEventTime(_ =&amp;gt; &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(1)) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; y1 + y2;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; ys = &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; x.A &amp;gt; 1 &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; x; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; zs = ys.Multicast(ys1 =&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; y1 &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; ys1 &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; y2 &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; ys1.ShiftEventTime(_ =&amp;gt; &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(1)) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; y1 + y2;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;p&gt;Notice the product translates an expression using implicit multicast into an expression using the explicit multicast operator. The user does not see this translation.&lt;/p&gt;
&lt;h1&gt;Default window policies&lt;/h1&gt;
&lt;p&gt;Only default window policies are supported in the new surface. Other policies can be simulated by using &lt;b&gt;AlterEventLifetime&lt;/b&gt;.&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Before&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;After&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.SnapshotWindow( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;WindowInputPolicy&lt;/span&gt;.ClipToWindow, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SnapshotWindowInputPolicy.Clip)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.SnapshotWindow()&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.TumblingWindow( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(1), &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;HoppingWindowOutputPolicy&lt;/span&gt;.PointAlignToWindowEnd)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.TumblingWindow( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(1))&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.TumblingWindow( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(1), &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;HoppingWindowOutputPolicy&lt;/span&gt;.ClipToWindowEnd)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;i&gt;Not supported&lt;/i&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;hellip;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;h1&gt;LeftAntiJoin&lt;/h1&gt;
&lt;p&gt;Representation of LASJ as a correlated sub-query in the LINQ surface is problematic as the StreamInsight engine does not support correlated sub-queries (see discussion of SelectMany). The current syntax requires the introduction of an otherwise unsupported &amp;lsquo;&lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;IsEmpty()&lt;/strong&gt;&lt;/span&gt;&amp;rsquo; operator. As a result, the pattern is not discoverable and implies capabilities not present in the server. The direct representation of LASJ is used instead:&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Before&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;After&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs &lt;br /&gt;where &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (from y &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; ys &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where x.A &amp;gt; y.B &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select y).IsEmpty() &lt;br /&gt;select x&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.LeftAntiJoin(ys, (x, y) =&amp;gt; x.A &amp;gt; y.B)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs &lt;br /&gt;where &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (from y &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; ys &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where x.A == y.B &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select y).IsEmpty() &lt;br /&gt;select x&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.LeftAntiJoin(ys, x =&amp;gt; x.A, y =&amp;gt; y.B)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;h1&gt;ApplyWithUnion&lt;/h1&gt;
&lt;p&gt;The ApplyWithUnion methods have been deprecated since their signatures are redundant given the standard SelectMany overloads:&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Before&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;After&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.GroupBy(x =&amp;gt; x.A).ApplyWithUnion(gs =&amp;gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; gs.SnapshotWindow() &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; win.Count())&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.GroupBy(x =&amp;gt; x.A).SelectMany( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gs =&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; gs.SnapshotWindow() &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; win.Count())&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.GroupBy(x =&amp;gt; x.A).ApplyWithUnion(gs =&amp;gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; gs.SnapshotWindow() &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; win.Count(), r =&amp;gt; &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; { r.Key, Count = r.Payload })&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from x &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs &lt;br /&gt;group x by x.A into gs &lt;br /&gt;from win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; gs.SnapshotWindow() &lt;br /&gt;select &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; { gs.Key, Count = win.Count() }&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;h1&gt;Alternate UDO syntax&lt;/h1&gt;
&lt;p&gt;The representation of UDOs in the StreamInsight LINQ dialect confuses cardinalities. Based on the semantics of user-defined operators in StreamInsight, one would expect to construct queries in the following form:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;from y &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; MyUdo(win) &lt;br /&gt;select y&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Instead, the UDO proxy method is referenced within a projection, and the (many) results returned by the user code are automatically flattened into a stream:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;select MyUdo(win)&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &amp;ldquo;many-or-one&amp;rdquo; confusion is exemplified by the following example that compiles but fails at runtime:&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;select MyUdo(win) + win.Count()&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The above query must fail because the UDO is in fact returning many values per window while the count aggregate is returning one.&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Original syntax&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;New alternate syntax&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;select win.UdoProxy(1)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;from win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;from y &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; win.UserDefinedOperator(() =&amp;gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Udo(1)) &lt;br /&gt;select y&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;-&lt;i&gt;or&lt;/i&gt;-&lt;/p&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; xs.SnapshotWindow() &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; y &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; win.UdoMacro(1) &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; y&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;p&gt;Notice that this formulation also sidesteps the dynamic type pitfalls of the existing &amp;ldquo;proxy method&amp;rdquo; approach to UDOs, in which the type of the UDO implementation (&lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;TInput, TOuput&lt;/strong&gt;&lt;/span&gt;) and the type of its constructor arguments (&lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;TConfig&lt;/strong&gt;&lt;/span&gt;) need to align in a precise and non-obvious way with the argument and return types for the corresponding proxy method.&lt;/p&gt;
&lt;h1&gt;UDSO syntax&lt;/h1&gt;
&lt;p&gt;UDSO currently leverages the DataContractSerializer to clone initial state for logical instances of the user operator. Initial state will instead be described by an expression in the new LINQ surface.&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Before&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;After&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.Scan(&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Udso())&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class="le-pavsc-container"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:500px;background-color:#ffffff;"&gt;xs.Scan(() =&amp;gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Udso())&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;h1&gt;Name changes&lt;/h1&gt;
&lt;p&gt;&lt;i&gt;ShiftEventTime =&amp;gt;&lt;/i&gt;&lt;i&gt; AlterEventStartTime&lt;/i&gt;&lt;b&gt;: &lt;/b&gt;The alter event lifetime overload taking a new start time value has been renamed.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;CountByStartTimeWindow =&amp;gt;&lt;/i&gt; &lt;i&gt;CountWindow&lt;/i&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44137" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/stream_insight/archive/tags/LINQ/default.aspx">LINQ</category></item><item><title>Introduction to LinqPad Driver for StreamInsight 2.1</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/06/26/introduction-to-linqpad-driver-for-streaminsight-2-1.aspx</link><pubDate>Tue, 26 Jun 2012 17:56:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44095</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44095.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44095</wfw:commentRss><description>&lt;p&gt;We are announcing the availability of the LinqPad driver for &lt;a href="http://sqlblog.com/b/streaminsight/archive/2012/06/25/streaminsight-2-1-released.aspx"&gt;StreamInsight 2.1&lt;/a&gt;. The purpose of this blog post is to offer a quick introduction into the new features that we added to the StreamInsight LinqPad driver. We’ll show you how to connect to a remote server, how to inspect the entities present of that server, how to compose on top of them and how to manage their lifetime.&lt;/p&gt;
&lt;h1&gt;Installing the driver&lt;/h1&gt;
&lt;p&gt;Info on how to install the driver can be found in &lt;a href="http://sqlblog.com/b/streaminsight/archive/2010/11/24/streaminsight-linqpad-driver.aspx"&gt;an earlier blog post here&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;Establishing connections&lt;/h1&gt;
&lt;p&gt;As you click on the “Add Connection” link in the left pane you will notice that now it’s possible to build the data context automatically. The new driver appears as an option in the upper list, and if you pick it you will open a connection dialog that lets you connect to a remote StreamInsight server.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/1524.image_5F00_2.png"&gt;&lt;img style="display:inline;background-image:none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/7823.image_5F00_thumb.png" width="589" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The connection dialog lets you specify the address of the remote server. You will notice that it’s possible to pick up the binding information from the configuration file of the LinqPad application (which is normally in the same folder as LinqPad.exe and is called LinqPad.exe.config).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/4760.image_5F00_4.png"&gt;&lt;img style="display:inline;background-image:none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/7888.image_5F00_thumb_5F00_1.png" width="340" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order for the context to be generated you need to pick an application from the server. The control is editable hence you can create a new application if you don’t want to make changes to an existing application. If you choose a new application name you will be prompted for confirmation before this gets created.&lt;/p&gt;

&lt;p&gt;Once you click OK the connection is created and you can start issuing queries against the remote server. If there’s any connectivity error the connection is marked with a red X and you can see the error message informing you what went wrong (i.e., the remote server could not be reached etc.).&lt;/p&gt;
&lt;h1&gt;The context for remote servers&lt;/h1&gt;
&lt;p&gt;Let’s take a look at what happens after we are connected successfully. Every LinqPad query runs inside a context – think of it as a class that wraps all the code that you’re writing. If you’re connecting to a live server the context will contain the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The application object itself.&lt;/li&gt;

&lt;li&gt;All entities present in this application (sources, sinks, subjects and processes).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The picture below shows a snapshot of the left pane of LinqPad after a successful connection. Every entity on the server has a different icon which will allow users to figure out its purpose. You will also notice that some entities have a string in parentheses following the name. It should be interpreted as such: the first name is the name of the property of the context class and the second name is the name of the entity as it exists on the server. Not all valid entity names are valid identifier names so in cases where we had to make a transformation you see both.&lt;/p&gt;

&lt;p&gt;Note also that as you hover over the entities you get IntelliSense with their types – more on that later.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/3286.image_5F00_6.png"&gt;&lt;img style="display:inline;background-image:none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/2438.image_5F00_thumb_5F00_2.png" width="473" height="276"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Remoting is not supported&lt;/h1&gt;
&lt;p&gt;As you play with the entities exposed by the context you will notice that you can’t read and write directly to/from them. If for instance you’re trying to dump the content of an entity you will get an error message telling you that in the current version remoting is not supported. This is because the entity lives on the remote server and dumping its content means reading the events produced by this entity into the local process.&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;ObservableSource.Dump();&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Will yield the following error:&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Reading from a remote 'System.Reactive.Linq.IQbservable`1[System.Int32]' is not supported. Use the 'Microsoft.ComplexEventProcessing.Linq.RemoteProvider.Bind' method to read from the source using a remote observer.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This basically tells you that you can call the Bind() method to direct the output of this source to a sink that has to be defined on the remote machine as well. You can’t bring the results to the LinqPad window unless you write code specifically for that.&lt;/p&gt;
&lt;h1&gt;Compose queries&lt;/h1&gt;
&lt;p&gt;You may ask – what's the purpose of all that? After all the same information is present in the EventFlowDebugger, why bother with showing it in LinqPad? First of all, What gets exposed in LinqPad is not what you see in the debugger. In LinqPad we have a property on the context class for every entity that lives on the server. Because LinqPad offers IntelliSense we in fact have much more information about the entity, and more importantly we can compose with that entity very easily. &lt;br&gt;For example, let’s say that this code creates an entity:&lt;/p&gt;
&lt;div style="font-size:10pt;"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:300px;"&gt;&lt;span&gt;using&lt;/span&gt; (&lt;span&gt;var&lt;/span&gt; server = &lt;span&gt;Server&lt;/span&gt;.Connect(...)) &lt;br&gt;{ &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;var&lt;/span&gt; a = server.CreateApplication(&lt;span&gt;"WhiteFish"&lt;/span&gt;); &lt;br&gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;var&lt;/span&gt; src = a &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .DefineObservable&amp;lt;&lt;span&gt;int&lt;/span&gt;&amp;gt;(() =&amp;gt; Observable.Range(0, 3)) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Deploy(&lt;span&gt;"ObservableSource"&lt;/span&gt;);&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If later we want to compose with the source we have to fetch it and then we can bind something to&lt;/p&gt;
&lt;div style="font-size:10pt;"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:300px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.GetObservable&amp;lt;&lt;span&gt;int&lt;/span&gt;&amp;gt;(&lt;span&gt;"ObservableSource)"&lt;/span&gt;).Bind(...&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This means that we had to know a bunch of things about this: that it’s a source, that it’s an observable, it produces a result with payload Int32 and it’s named “ObservableSource”. Only the second and last bits of information are present in the debugger, by the way.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/6724.image_5F00_8.png"&gt;&lt;img style="display:inline;background-image:none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/2022.image_5F00_thumb_5F00_3.png" width="628" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you type in the query window you see that all the entities are present, you get IntelliSense support for them and it’s much easier to make sense of what’s available.&lt;/p&gt;

&lt;p&gt;Let’s look at a scenario where composition is plausible. With the new programming model it’s possible to create “cold” sources that are parameterized. There was a way to accomplish that even in the previous version by passing parameters to the adapters, but this time it’s much more elegant because the expression declares what parameters are required. Say that we hover the mouse over the ThrottledSource source – we will see that its type is &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;Func&amp;lt;int, int, IQbservable&amp;lt;int&amp;gt;&amp;gt;&lt;/strong&gt;&lt;/span&gt; - this in effect means that we need to pass two int parameters before we can get a source that produces events, and the type for those events is int – in the particular case of my example I had the source produce a range of integers and the two parameters were the start and end of the range. So we see how a developer can create a source that is not running yet. Then someone else (e.g. an administrator) can pass whatever parameters appropriate and run the process.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/7317.image_5F00_10.png"&gt;&lt;img style="display:inline;background-image:none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/1524.image_5F00_thumb_5F00_4.png" width="628" height="270"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Proxy Types&lt;/h1&gt;
&lt;p&gt;Here’s an interesting scenario – what if someone created a source on a server but they forgot to tell you what type they used. Worse yet, they might have used an anonymous type and even though they can refer to it by name you can’t figure out how to use that type.&lt;/p&gt;

&lt;p&gt;Let’s walk through an example that shows how you can compose against types you don’t need to have the definition of. This is how we can create a source that returns an anonymous type:&lt;/p&gt;
&lt;div style="font-size:10pt;"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:300px;"&gt;&lt;span&gt;Application&lt;/span&gt;.DefineObservable(() =&amp;gt; Observable.Range(1, 10).Select(i =&amp;gt; &lt;span&gt;new&lt;/span&gt; { I = i })).Deploy(&lt;span&gt;"O1"&lt;/span&gt;);&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now if we refresh the connection we can see the new source named O1 appear in the list. But what’s more important is that we now have a type to work with. So we can compose a query that refers to the anonymous type.&lt;/p&gt;
&lt;div style="font-size:10pt;"&gt;
&lt;div style="padding:2px 5px;overflow:auto;max-height:300px;"&gt;&lt;span&gt;var&lt;/span&gt; threshold = &lt;span&gt;new&lt;/span&gt; StreamInsightDynamicDriver.TypeProxies.AnonymousType1_0&amp;lt;&lt;span&gt;int&lt;/span&gt;&amp;gt;(5); &lt;br&gt; &lt;br&gt;&lt;span&gt;var&lt;/span&gt; filter = &lt;span&gt;from&lt;/span&gt; i &lt;span&gt;in&lt;/span&gt; O1 &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;where&lt;/span&gt; i &amp;gt; threshold &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;select&lt;/span&gt; i; &lt;br&gt; &lt;br&gt;filter.Deploy(&lt;span&gt;"O2"&lt;/span&gt;);&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You will notice that the anonymous type defined with this statement: &lt;strong&gt;&lt;span style="font-family:Consolas;"&gt;new { I = i }&lt;/span&gt;&lt;/strong&gt; can now be manipulated by a client that does not have access to it because the LinqPad driver has generated another type in its stead, named &lt;span style="font-family:Consolas;"&gt;&lt;strong&gt;StreamInsightDynamicDriver.TypeProxies.AnonymousType1_0&lt;/strong&gt;&lt;/span&gt;. This type has all the properties and fields of the type defined on the server, except in this case we can instantiate values and use it to compose more queries.&lt;/p&gt;

&lt;p&gt;It is worth noting that the same thing works for types that are not anonymous – the test is if the LinqPad driver can resolve the type or not. If it’s not possible then a new type will be generated that approximates the type that exists on the server.&lt;/p&gt;
&lt;h1&gt;Control metadata&lt;/h1&gt;
&lt;p&gt;In addition to composing processes on top of the existing entities we can do other useful things. We can delete them – nothing new here as we simply access the entities through the Entities collection of the application class. Here is where having their real name in parentheses comes handy.&lt;/p&gt;

&lt;p&gt;There’s another way to find out what’s behind a property – dump its expression. The first line in the output tells us what’s the name of the entity used to build this property in the context.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/1537.image_5F00_12.png"&gt;&lt;img style="display:inline;background-image:none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/4274.image_5F00_thumb_5F00_5.png" width="628" height="201"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Runtime information&lt;/h1&gt;
&lt;p&gt;So let’s create a process to see what happens. We can bind a source to a sink and run the resulting process. If you right click on the connection you can refresh it and see the process present in the list of entities. Then you can drag the process to the query window and see that you can have access to process object in the Processes collection of the application. You can then manipulate the process (delete it, read its diagnostic view etc.).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/3286.image_5F00_14.png"&gt;&lt;img style="display:inline;background-image:none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/2438.image_5F00_thumb_5F00_6.png" width="628" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Regards, &lt;br&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44095" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/stream_insight/archive/tags/LINQPad/default.aspx">LINQPad</category><category domain="http://sqlblog.com/blogs/stream_insight/archive/tags/Release/default.aspx">Release</category></item><item><title>StreamInsight 2.1 Released</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/06/25/streaminsight-2-1-released.aspx</link><pubDate>Mon, 25 Jun 2012 15:33:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44069</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/44069.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=44069</wfw:commentRss><description>&lt;p&gt;&lt;span&gt;The wait is over&amp;mdash;we are pleased to announce the release of StreamInsight 2.1. Since the release of version 1.2, we have heard your feedbacks and suggestions and based on that we have come up with a whole new set of features. Here are some of the highlights:&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;A New Programming Model &amp;ndash; A more clear and consistent object model, eliminating the need for complex input and output adapters (though they are still completely supported). This new model allows you to provision, name, and manage data sources and sinks in the StreamInsight server.&lt;/span&gt; &lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;Tight integration with Reactive Framework (Rx) &amp;ndash; You can write reactive queries hosted inside StreamInsight as well as compose temporal queries on reactive objects.&lt;/span&gt; &lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;High Availability &amp;ndash; Check-pointing over temporal streams and multiple processes with shared computation.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Here is how simple coding can be with the 2.1 Programming Model:&lt;/span&gt;&lt;/p&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Program&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;[] args)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff;"&gt;using &lt;/span&gt;(Server server = Server.Create("&lt;span style="color:#8b0000;"&gt;Default&lt;/span&gt;"))&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="color:#008000;font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Create an app&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Application app = server.CreateApplication("&lt;span style="color:#8b0000;"&gt;app&lt;/span&gt;");&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="color:#008000;font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Define a simple observable which generates an integer every second&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var source = app.DefineObservable(() =&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Observable.Interval(TimeSpan.FromSeconds(1)));&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="color:#008000;font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Define a sink.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var sink = app.DefineObserver(() =&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Observer.Create&amp;lt;&lt;span style="color:#0000ff;"&gt;long&lt;/span&gt;&amp;gt;(x =&amp;gt; Console.WriteLine(x)));&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="color:#008000;font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Define a query to filter the events&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var query = from e &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; source&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where e % 2 == 0&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select e;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="color:#008000;font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Bind the query to the sink and create a runnable process&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (IDisposable proc = query.Bind(sink).Run("&lt;span style="color:#8b0000;"&gt;MyProcess&lt;/span&gt;"))&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.WriteLine("&lt;span style="color:#8b0000;"&gt;Press a key to dispose the process...&lt;/span&gt;");&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.ReadKey();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0em;width:100%;font-family:consolas,'Courier New',courier,monospace;font-size:16px;background-color:#e6e8ff;"&gt;&lt;span style="font-size:small;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;That&amp;rsquo;s how easily you can define a source, sink and compose a query and run it. Note that we did not replace the existing APIs, they co-exist with the new surface.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Stay tuned, you will see a series of articles coming out over the next few weeks about the new features and how to use them.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Come and grab it from our &lt;/span&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=253700"&gt;&lt;span&gt;download center page&lt;/span&gt;&lt;/a&gt;&lt;span&gt; and let us know what you think! You can find the updated &lt;/span&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=254640"&gt;&lt;span&gt;MSDN documentation here&lt;/span&gt;&lt;/a&gt;&lt;span&gt;, and we would appreciate if you could provide feedback to the docs as well&amp;mdash;best via email to &lt;a href="mailto:garye@microsoft.com"&gt;garye@microsoft.com&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Moreover, we updated &lt;a href="http://streaminsight.codeplex.com/releases/view/90143"&gt;our samples&lt;/a&gt; to demonstrate the new programming surface.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards, &lt;br /&gt;The StreamInsight Team&lt;/span&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=44069" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/stream_insight/archive/tags/Release/default.aspx">Release</category></item><item><title>Building the Internet of Things – with Microsoft StreamInsight and the Microsoft .Net Micro Framework</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/04/05/building-the-internet-of-things-with-microsoft-streaminsight-and-the-microsoft-net-micro-framework.aspx</link><pubDate>Fri, 06 Apr 2012 00:41:33 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:42710</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/42710.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=42710</wfw:commentRss><description>&lt;p&gt;Fresh from the press – The March 2012 issue of MSDN Magazine features an article about the Internet of Things. It discusses in depth how you can use StreamInsight to process all the data that is continuously produced in typical Internet of Things scenarios. It also gives you an end-to-end perspective on developing Internet of Things solutions in the .NET world, ranging from the .NET Micro Framework application running on the device, the communication between the devices and the server-side all the way to powerful cross-device streaming analytics implemented in StreamInsight LINQ.&lt;/p&gt;  &lt;p&gt;You can find an online version of the article &lt;a href="http://msdn.microsoft.com/en-us/magazine/hh852591.aspx"&gt;here&lt;/a&gt;. Happy reading!&lt;/p&gt;  &lt;p&gt;Regards,   &lt;br /&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=42710" width="1" height="1"&gt;</description></item><item><title>LINQPad for StreamInsight 2.0</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/03/20/linqpad-for-streaminsight-2-0.aspx</link><pubDate>Tue, 20 Mar 2012 23:53:52 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:42415</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/42415.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=42415</wfw:commentRss><description>&lt;p&gt;This has come up several times in the wake of our 2.0 release: The new LINQPad driver supporting StreamInsight 2.0 is now live! You can download it as usual through the LINQPad UI:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/7380.lp20_5F00_1AFBC5DB.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="lp20" border="0" alt="lp20" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-27-92-metablogapi/6523.lp20_5F00_thumb_5F00_5AC5AC60.png" width="663" height="515" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;There are separate versions of the driver only because assembly references are not automatically forwarded for StreamInsight 2.0.&lt;/p&gt;  &lt;p&gt;Regards,   &lt;br /&gt;The StreamInsight Team&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=42415" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/stream_insight/archive/tags/Release/default.aspx">Release</category></item><item><title>White Paper/Case Study on ICONICS’ Use of StreamInsight for its Energy AnalytiX&amp;#174; Solution</title><link>http://sqlblog.com/blogs/stream_insight/archive/2012/03/16/white-paper-case-study-on-iconics-use-of-streaminsight-for-its-energy-analytix-174-solution.aspx</link><pubDate>Fri, 16 Mar 2012 23:40:46 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:42368</guid><dc:creator>Roman Schindlauer</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stream_insight/comments/42368.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stream_insight/commentrss.aspx?PostID=42368</wfw:commentRss><description>&lt;p&gt;A couple of days ago, we released a new StreamInsight white paper/case study on TechNet and MSDN. The paper is joint work with ICONICS and discusses how ICONICS is using StreamInsight technology for its Energy AnalytiX® solution. The paper is available for &lt;a href="http://msdn.microsoft.com/en-us/library/hh849321.aspx" target="_blank"&gt;download here&lt;/a&gt; in the Technical Articles section of the StreamInsight documentation.&lt;/p&gt;  &lt;p&gt;Today, businesses and organizations need to pay more and more attention to energy usage, as customers and the general public are becoming increasingly concerned about a respectful and sustainable use of resources. Organizations therefore need to carefully manage their use of energy and provide better visibility into their energy consumption. In this paper, we discuss how software solutions can help address these challenges.&lt;/p&gt;  &lt;p&gt;Besides providing some background on the drivers behind energy management, the paper discusses how organizations manage their use of energy with current product and service offerings from Microsoft and ICONICS. In the main body of the paper, a case study explains in depth how ICONICS Energy AnalytiX® is using Microsoft data platform components such as SQL Server StreamInsight to deliver market leading energy management solutions.&lt;/p&gt;  &lt;p&gt;Regards,   &lt;br /&gt;The StreamInsight Team    &lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=42368" width="1" height="1"&gt;</description></item></channel></rss>