日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【原创】StreamInsight查询系列(三)——基本查询操作之过滤

發布時間:2023/12/18 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【原创】StreamInsight查询系列(三)——基本查询操作之过滤 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

上篇博文介紹了如何在LINQPad中輸出StreamInsight查詢結果。這篇文章將主要介紹StreamInsight基礎查詢操作中的過濾部分。

測試數據準備

為了方便測試查詢,我們首先準備一個靜態的測試數據源:

var weatherData = new[] {new { Timestamp = new DateTime(2010, 1, 1, 0, 00, 00), Temperature = -9.0, StationCode = 71395, WindSpeed = 4}, new { Timestamp = new DateTime(2010, 1, 1, 0, 30, 00), Temperature = -4.5, StationCode = 71801, WindSpeed = 41},new { Timestamp = new DateTime(2010, 1, 1, 1, 00, 00), Temperature = -8.8, StationCode = 71395, WindSpeed = 6}, new { Timestamp = new DateTime(2010, 1, 1, 1, 30, 00), Temperature = -4.4, StationCode = 71801, WindSpeed = 39},new { Timestamp = new DateTime(2010, 1, 1, 2, 00, 00), Temperature = -9.7, StationCode = 71395, WindSpeed = 9}, new { Timestamp = new DateTime(2010, 1, 1, 2, 30, 00), Temperature = -4.6, StationCode = 71801, WindSpeed = 59},new { Timestamp = new DateTime(2010, 1, 1, 3, 00, 00), Temperature = -9.6, StationCode = 71395, WindSpeed = 9}, };

weatherData代表了一系列的天氣信息(時間戳、溫度、氣象站編碼以及風速)。

接下去將weatherData轉變為點類型復雜事件流:

var weatherStream = weatherData.ToPointStream(Application,t => PointEvent.CreateInsert(t.Timestamp, t),AdvanceTimeSettings.IncreasingStartTime);// 統計事件總數 weatherStream.ToPointEnumerable().Count().Dump("Total number of events");

細心的讀者會發現事件總數是15,而不是weatherData的元素個數7。這是因為在使用AdvanceTimeSettings.IncreasingStartTime標志創建weatherStream后,StreamInsight引擎會為每一個事件后緊跟一個相同時間戳的CTI事件,因此事件個數為7*2=14。那么為什么總數變成了15呢?那是因為AdvanceTimeSettings.IncreasingStartTime默認指定了AdvanceToInfinityOnShutdown為true,即確定在關閉查詢時應插入具有正無窮大的時間戳的最終CTI,用來刷新所有剩余事件。因此加上這個正無窮大的CTI事件,總的事件總數為15。感興趣的讀者可以調用weatherStream.ToPointEnumerable().Dump() 查看15個事件的具體內容。

基礎過濾

問題1:怎樣過濾事件流以保留特定的事件?

對weatherStream過濾可以使用LINQ中的where子句,如保留那些溫度高于零下5度的事件:

var filterQuery = from e in weatherStreamwhere e.Temperature > -5.0select e;

接下去使用下述語句將filterQuery中的Insert事件導出到LINQPad輸出窗口:

(from e in filterQuery.ToPointEnumerable()where e.EventKind == EventKind.Insertselect e).Dump();

最終的3個過濾事件結果如下:

問題2:怎樣進行多條件過濾?

StreamInsight支持多條件過濾,只需要在where子句中指明多個過濾條件即可。問題1中我們過濾出了溫度高于零下5度的所有事件;那么如果我們想要過濾出不僅溫度高于零下5度,而且風速超過40的事件,該怎么做呢?很簡單,只需要在where子句中增加e.WindSpeed > 40就可以了,如下:

var filterQuery2 = from e in weatherStreamwhere e.Temperature > -5.0 && e.WindSpeed > 40select e; (from e in filterQuery2.ToPointEnumerable()where e.EventKind == EventKind.Insertselect e).Dump();

最終過濾出的2個事件如下:

下篇文章將介紹StreamInsight基礎操作操作中的聚合部分。

轉載于:https://www.cnblogs.com/StreamInsight/archive/2011/08/21/StreamInsight-Query-Series-Part3-Basic-Queries-Filters.html

總結

以上是生活随笔為你收集整理的【原创】StreamInsight查询系列(三)——基本查询操作之过滤的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。