You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/06/05 14:38:20 UTC

[GitHub] [beam] steveniemitz commented on a change in pull request #11919: [BEAM-10114] Copy Pub/Sub Lite IO from Pub/Sub Lite github to beam.

steveniemitz commented on a change in pull request #11919:
URL: https://github.com/apache/beam/pull/11919#discussion_r435965759



##########
File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsublite/DeduplicationFn.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.beam.sdk.io.gcp.pubsublite;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.DelegateCoder;
+import org.apache.beam.sdk.coders.InstantCoder;
+import org.apache.beam.sdk.coders.ListCoder;
+import org.apache.beam.sdk.coders.MapCoder;
+import org.apache.beam.sdk.state.SetState;
+import org.apache.beam.sdk.state.StateSpec;
+import org.apache.beam.sdk.state.StateSpecs;
+import org.apache.beam.sdk.state.ValueState;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Lists;
+import org.joda.time.Instant;
+
+// A DeduplicationFn takes a KV from a hashed version of KeyT to a KV of KeyT and ValueT and
+// deduplicates based on KeyT. KeyT must provide a non-identity implementation of equals.
+class DeduplicationFn<KeyT, ValueT> extends DoFn<KV<Integer, KV<KeyT, ValueT>>, KV<KeyT, ValueT>> {
+  private final DeduplicationFnOptions<KeyT> options;
+
+  // A state cell holding the set of recently received keys.
+  @SuppressWarnings("unused")
+  @StateId("keySet")
+  private final StateSpec<SetState<KeyT>> keySetSpec;

Review comment:
       this will fail on dataflow, it doesn't support SetState or MapState yet.  Dataflow does have its own deduplicate implementation [1] that pushes the work to windmill's own exactly-once impl, you might be able to override this transform w/ that in the runner?  There's also a Deduplicate transform [2] in beam now, but I don't think it'd scale very well.
   
   [1] https://github.com/apache/beam/blob/8aedab2da96e1324f8433df3c772d59346f825b4/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java#L1729
   
   [2] https://github.com/apache/beam/blob/8aedab2da96e1324f8433df3c772d59346f825b4/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Deduplicate.java




----------------------------------------------------------------
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