zentol commented on a change in pull request #6367: [FLINK-9850] Add a string 
to the print method to identify output for DataStream
URL: https://github.com/apache/flink/pull/6367#discussion_r210514892
 
 

 ##########
 File path: 
flink-libraries/flink-streaming-python/src/test/python/org/apache/flink/streaming/python/api/test_output_with_sink_identifier.py
 ##########
 @@ -0,0 +1,58 @@
+################################################################################
+#  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.
+################################################################################
+from org.apache.flink.api.common.functions import FlatMapFunction, 
ReduceFunction
+from org.apache.flink.api.java.functions import KeySelector
+from org.apache.flink.streaming.api.windowing.time.Time import milliseconds
+
+from utils import constants
+
+
+class Tokenizer(FlatMapFunction):
+    def flatMap(self, value, collector):
+        collector.collect((1, value))
+
+
+class Sum(ReduceFunction):
+    def reduce(self, input1, input2):
+        count1, val1 = input1
+        count2, val2 = input2
+        return (count1 + count2, val1)
+
+
+class Selector(KeySelector):
+    def getKey(self, input):
+        return input[1]
+
+
+class Main:
+    def run(self, flink):
+        elements = ["aa" if iii % 2 == 0 else "bbb" for iii in 
range(constants.NUM_ELEMENTS_IN_TEST)]
+
+        env = flink.get_execution_environment()
+        env.from_collection(elements) \
+            .flat_map(Tokenizer()) \
+            .key_by(Selector()) \
+            .time_window(milliseconds(10)) \
+            .reduce(Sum()) \
+            .output("testOutputWithIdentifier")
+
+        env.execute()
 
 Review comment:
   yes this is a common issue with the tests, but fixing this isn't too high on 
my priority list, given that most methods are just wrappers around java methods.

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


With regards,
Apache Git Services

Reply via email to