You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by GitBox <gi...@apache.org> on 2018/12/19 19:28:40 UTC
[GitHub] nwangtw commented on a change in pull request #3125: Add
KVStreamlet and keyBy() operation
nwangtw commented on a change in pull request #3125: Add KVStreamlet and keyBy() operation
URL: https://github.com/apache/incubator-heron/pull/3125#discussion_r243045776
##########
File path: heron/api/src/java/org/apache/heron/streamlet/impl/operators/KeyByOperator.java
##########
@@ -0,0 +1,53 @@
+/**
+ * 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.heron.streamlet.impl.operators;
+
+import org.apache.heron.api.tuple.Tuple;
+import org.apache.heron.api.tuple.Values;
+import org.apache.heron.streamlet.KeyValue;
+import org.apache.heron.streamlet.SerializableFunction;
+
+/**
+ * KeyByOperator is the class that implements keyBy functionality.
+ * It takes in a key extractor and a value extractor as input.
+ * For every tuple, the bolt convert the steam to a key-value pair tuple
+ * by applying the extractors.
+ */
+public class KeyByOperator<R, K, V> extends StreamletOperator<R, KeyValue<K, V>> {
Review comment:
Yeah. The function simply converts a data into a stream of k-v pair. This is a fairly standard function in other frameworks:
KeyBy() in Flink: https://ci.apache.org/projects/flink/flink-docs-stable/dev/api_concepts.html,
GroupByKey() in kafkastreams: https://kafka.apache.org/10/documentation/streams/developer-guide/dsl-api.html
GroupByKey() in Beam: https://beam.apache.org/releases/javadoc/2.0.0/org/apache/beam/sdk/transforms/GroupByKey.html
groupBy() in Summingbird:
groupBy() in Storm: http://storm.apache.org/releases/1.0.6/Trident-API-Overview.html
However, the difference might be that in those frameworks, operations on keyed stream cannot be applied on non-keyed stream so keyBy is necessary and currently in streamlet, you "have to" provide key extractor to all keyed operation. It is flexible but could be painful to users.
Currently a custom field grouping is applied. However I am thinking that maybe it is not needed? The grouping should be applied afterwards.
I think the use case is to formalize a stream with complicated data structure to make it easier to use in the next steps. It could be convenient especially when there are multiple keyed operations. For example, with the function we can do:
keyedStream = source // Streamlet<COMPLICATED_DATA_STRUCTURE>
.keyBy(keyextractor, valueextractor)
keyedStream.reduceByKey(reduceFunc1)....
keyedStream.reduceByKey(reduceFunc2)....
keyedStream.reduceByKeyAndWindow(windowConf, reduceFunc3)....
Currently it looks like:
source.reduceByKey(keyextractor, valueextractor, reduceFunc1)....
source.reduceByKey(keyextractor, valueextractor, reduceFunc2)....
source.reduceByKey(keyextractor, valueextractor, windowConf, reduceFunc3)....
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services