xinyuiscool commented on code in PR #24276:
URL: https://github.com/apache/beam/pull/24276#discussion_r1040212756


##########
runners/samza/src/main/java/org/apache/beam/runners/samza/translation/ParDoBoundMultiTranslator.java:
##########
@@ -377,17 +392,15 @@ public Map<String, String> createConfig(
     if (signature.usesState()) {
       // set up user state configs
       for (DoFnSignature.StateDeclaration state : 
signature.stateDeclarations().values()) {
-        final String storeId = state.id();
-
-        // TODO: remove validation after we support same state id in different 
ParDo.
-        if (!ctx.addStateId(storeId)) {
-          throw new IllegalStateException(
-              "Duplicate StateId " + storeId + " found in multiple ParDo.");
+        final String stateId = state.id();
+        String storeId = stateId;

Review Comment:
   Same above, add a StoreIdGenerator inside ConfigContext and use that here.



##########
runners/samza/src/main/java/org/apache/beam/runners/samza/translation/ConfigContext.java:
##########
@@ -35,12 +34,13 @@ public class ConfigContext {
   private final Map<PValue, String> idMap;
   private AppliedPTransform<?, ?, ?> currentTransform;
   private final SamzaPipelineOptions options;
-  private final Set<String> stateIds;
+  private final Set<String> nonUniqueStateIds;

Review Comment:
   Please take a look at the comments below to wrap this in a StoreIdGenerator 
class.



##########
runners/samza/src/main/java/org/apache/beam/runners/samza/translation/TranslationContext.java:
##########
@@ -83,6 +83,7 @@ public class TranslationContext {
   private final Map<PValue, String> idMap;
   private final Map<String, MessageStream> registeredInputStreams = new 
HashMap<>();
   private final Map<String, Table> registeredTables = new HashMap<>();
+  private final Set<String> nonUniqueStateIds;

Review Comment:
   See comments above to wrap this in a StoreIdGenerator class.



##########
runners/samza/src/main/java/org/apache/beam/runners/samza/translation/ParDoBoundMultiTranslator.java:
##########
@@ -161,6 +163,17 @@ private static <InT, OutT> void doTranslate(
     Map<String, PCollectionView<?>> sideInputMapping =
         ParDoTranslation.getSideInputMapping(ctx.getCurrentTransform());
 
+    final DoFnSignature signature = 
DoFnSignatures.getSignature(transform.getFn().getClass());
+    final Map<String, String> stateIdToStoreMapping = new HashMap<>();
+    for (String stateId : signature.stateDeclarations().keySet()) {
+      String storeId = stateId;

Review Comment:
   Seems line 169 - 173 is duplicated below in the config part too. Could you 
consolidate the logic and encapsulate it in a single class, e.g. a 
StoreIdGenerator class which takes in the nonUniqueStateId set as the 
constructor, and expose a function of getId(stateId, transformFullName). So in 
both ConfigContext and TranslationContext, you can expose this helper class 
instance, e.g.:
   
   final String storeId = ctx.getStoreIdGenerator().getId(stateId, 
transformFullName);
   



##########
runners/samza/src/main/java/org/apache/beam/runners/samza/util/StoreIdUtils.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.runners.samza.util;
+
+public class StoreIdUtils {

Review Comment:
   We can move this method in this class into the new StoreIdGenerator.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to