You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/07/22 17:37:08 UTC

[GitHub] [flink] sjwiesman commented on a change in pull request #9192: [FLINK-12749] [docs] [examples] Initial Version of Flink Cluster Playground

sjwiesman commented on a change in pull request #9192: [FLINK-12749] [docs] [examples] Initial Version of Flink Cluster Playground
URL: https://github.com/apache/flink/pull/9192#discussion_r305946262
 
 

 ##########
 File path: flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/clickeventcount/functions/ClickEventStatisticsCollector.java
 ##########
 @@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.examples.windowing.clickeventcount.functions;
+
+import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
+import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
+import org.apache.flink.streaming.examples.windowing.clickeventcount.records.ClickEvent;
+import org.apache.flink.streaming.examples.windowing.clickeventcount.records.ClickEventStatistics;
+import org.apache.flink.util.Collector;
+
+/**
+ * A simple {@link ProcessWindowFunction}, which wraps a count of {@link ClickEvent}s into an
+ * instance of {@link ClickEventStatistics}.
+ *
+ **/
+public class ClickEventStatisticsCollector
+		extends ProcessWindowFunction<Long, ClickEventStatistics, String, TimeWindow> {
+
+	@Override
+	public void process(
+			final String page,
+			final Context context,
+			final Iterable<Long> elements,
+			final Collector<ClickEventStatistics> out) throws Exception {
+
+		Long count = elements.iterator().next();
+
+		out.collect(new ClickEventStatistics(context.window().getStart(), context.window().getEnd(), page, count));
 
 Review comment:
   I originally started to write a comment that you should have `CountingAggregator#getResult` return a `ClickEventStatistics` object but now I see you are getting the start and stop times of the window. Maybe add a comment for new users who make the same mistake I did :) 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services