![]() | CYQ.Data componentsCYQ.Data support multi-database application [Txt,Xml,Access, MSSQL, Oracle,SQLite,MySql], help easily and quickly to develop your project |
框架项目案例二:全速连锁管理网上管理系统
Project-Case |
|
|
| #TopicOwner |
上篇博文介绍了如何在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 weatherStream where e.Temperature > -5.0 select e; 接下去使用下述语句将filterQuery中的Insert事件导出到LINQPad输出窗口: (from e in filterQuery.ToPointEnumerable() where e.EventKind == EventKind.Insert select e).Dump(); 最终的3个过滤事件结果如下: 问题2:怎样进行多条件过滤? StreamInsight支持多条件过滤,只需要在where子句中指明多个过滤条件即可。问题1中我们过滤出了温度高于零下5度的所有事件;那么如果我们想要过滤出不仅温度高于零下5度,而且风速超过40的事件,该怎么做呢?很简单,只需要在where子句中增加e.WindSpeed > 40就可以了,如下: var filterQuery2 = from e in weatherStream where e.Temperature > -5.0 && e.WindSpeed > 40 select e; (from e in filterQuery2.ToPointEnumerable() where e.EventKind == EventKind.Insert select e).Dump(); 最终过滤出的2个事件如下: 下篇文章将介绍StreamInsight基础操作操作中的聚合部分。 作者: StreamInsight 发表于 2011-08-21 09:29 原文链接 ![]() |
zhouxuancq2011/3/7 3:48:36 | #1 | |
![]() | 下载地址在哪 reply: 这只是网友的案例,网友是不提供系统下载的,框架的下载在下载中心。 |
Post Comment
Bulletin
Article Search
Categories
- Platform for dynamic (20)
- Feedback (9)
- Guide (33)
- Principles (19)
- Project-Case (8)
- Business & Buy (2)
- Technology exchange (45)
New Article
- CYQ.Data Components Getting Started Guide [Part 5]-[MProc Execute Stored Procedures or SQL]
- CYQ.Data Components Getting Started Guide [Part 4]-[MAction Insert Delete Update]
- CYQ.Data Components Getting Started Guide [Part 3]-[MAction Get And Set Value]
- CYQ.Data Components Getting Started Guide [Part 2]-[MAction Data Query- Fill And Select]
- CYQ.Data Components Getting Started Guide [Part 1]
New Comment
- When some one searches for his necessary thing, therefore he/she wishes to be available that in detail, so that thing is maintained over here.
- This is my first time pay a quick visit at here and i am in fact happy to read everthing at alone place.
- I truly appreciate this blog article.Really thank you! Cool.
- please pay a visit to the web sites we follow, like this one particular, as it represents our picks in the web
- Really enjoyed this post.Really thank you!
- Really enjoyed this article.Really looking forward to read more. Great.
- poker bonuses What are the norms of copyright of web content? How as it different from Patent?
- Wow! Thank you! I permanently needed to write on my blog something like that. Can I implement a fragment of your post to my site?
- This website was how do I say it? Relevant!! Finally I ave found something that helped me. Cheers!
- I was reading through some of your content on this internet site and I believe this web site is very informative ! Continue posting.