static void Main(string[] args) { // 创建 execution environment var env = StreamExecutionEnvironment.GetExecutionEnvironment() // 告诉系统按照 EventTime 处理 .SetStreamTimeCharacteristic(TimeCharacteristic.EventTime) // 为了打印到控制台的结果不乱序,我们配置全局的并发为1,改变并发对结果正确性没有影响 .SetParallelism(1); var file = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "UserBehavior.csv"); var pojoType = TypeExtractor.CreateTypeInfo <UserBehavior>() as PojoTypeInfo <UserBehavior>; var stream = env.ReadCsvFile <UserBehavior>("") // 创建数据源,得到UserBehavior类型的DataStream .AssignTimestampsAndWatermarks(new UserBehaviorAscendingTimestampExtractor()) // 抽取出时间和生成watermark .Filter(new UserBehaviorFilter()) // 过滤出只有点击的数据 .KeyBy("itemId") // 按商品分区统计 .TimeWindow(TimeSpan.FromMinutes(60), TimeSpan.FromMinutes(5)) // 窗口大小是一小时,每隔5分钟滑动一次 .Aggregate(new CountAggregator(), new WindowResultFunction()) // 获得每个窗口的点击量的数据流 .KeyBy("windowEnd") // 为了统计每个窗口下最热门的商品,再次按窗口进行分组. .Process(new TopNHotProducts(3)); // 计算点击量排名前3名的商品 stream.Print(); // 控制台打印输出 env.Execute("Hot Products Job"); }
protected TypeHint() { try { TypeInfo = TypeExtractor.CreateTypeInfo <T>(); } catch (InvalidTypesException e) { throw new FLinkRuntimeException("The TypeHint is using a generic variable." + "This is not supported, generic types must be fully specified for the TypeHint."); } }