You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hop.apache.org by "hansva (via GitHub)" <gi...@apache.org> on 2023/03/17 14:50:59 UTC

[GitHub] [hop] hansva opened a new issue, #2676: [Feature Request]: Beam State and Side Inputs

hansva opened a new issue, #2676:
URL: https://github.com/apache/hop/issues/2676

   ### What would you like to happen?
   
   Migration: https://issues.apache.org/jira/browse/HOP-4114
   
   Missing support for Beam state and side-inputs.
   Please see the attached PipelineWithStateExample.java
   
   ```
   package com.nokia.nwdaf.edge.flink.ue.mobility.pipeline;
   
   import com.nokia.nwdaf.edge.commons.model.CommonDateFormats;
   import com.nokia.nwdaf.edge.commons.model.generated.*;
   import org.apache.beam.sdk.coders.AvroCoder;
   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.sdk.values.PCollectionView;
   
   import java.time.Instant;
   import java.time.LocalDateTime;
   import java.util.*;
   
   public class PipelineWithState {
       public static void main(String[] args) {
           try {
               PipelineUtil pipelineUtil = new PipelineUtil();
               Pipeline pipeline = pipelineUtil.createPipeline(args);
   
               // ...
   
               // Scheduler events arrive once in X seconds
               PCollection<KV<String, Iterable<String>>> schedularTriggerResults = schedulerTrigger.apply(GroupByKey.create());
   
               // A PCollectionView is built based on inference results. This is another part of the pipeline that is unrelated to the scheduler at this stage.
               PCollectionView<Map<String, Iterable<InferenceResultList>>> handleInferenceResults = windowInferenceResultsIter.apply("handleInferenceResults", ParDo.of(new HandleInferenceResults())).apply(View.asMultimap());
   
               // Combine both of them. Pass the inference results view as a side input to the DoFn.
               PCollection<KV<String, AnalyticsOutput>> analyticsOutput = schedularTriggerResults.apply(ParDo.of(new RetrieveInferenceResults(handleInferenceResults)).withSideInput("results", handleInferenceResults));
   
               // ...
   
               pipeline.run();
           } catch (Exception e) {
               log.atError().withThrowable(e).log("Exception thrown while running pipeline");
           }
       }
   }
   
   
   public class HandleInferenceResults extends DoFn<KV<String, Iterable<InferenceOutput>>, KV<String, InferenceResultList>> {
   
       @StateId("inferenceResults")
       private final StateSpec<ValueState<InferenceResultList>> inferenceResultState =
               StateSpecs.value(AvroCoder.of(InferenceResultList.class));
   
       @ProcessElement
       public void processElement(
               ProcessContext c,
               @StateId("inferenceResults") ValueState<InferenceResultList> inferenceResultState) {
   
           // ...
   
           InferenceResultList readInfList = inferenceResultState.read();
   
           // ...
   
           inferenceResultState.clear();
           inferenceResultState.write(newInferenceResultList);
   
       }
   }
   
   
   public class RetrieveInferenceResults extends DoFn<KV<String, Iterable<String>>, KV<String, AnalyticsOutput>> {
   
       private final PCollectionView<Map<String, Iterable<InferenceResultList>>> inferenceResultListView;
   
       public RetrieveInferenceResults(PCollectionView<Map<String, Iterable<InferenceResultList>>> inferenceResultListView) {
           this.inferenceResultListView = inferenceResultListView;
       }
   
       @ProcessElement
       public void processElement(ProcessContext c) {
           Map<String, Iterable<InferenceResultList>> inferenceResultTable = c.sideInput(inferenceResultListView);
   
           // ...
   
       }
   }
   ```
   
   
   ### Issue Priority
   
   Priority: 3
   
   ### Issue Component
   
   Component: Beam


-- 
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: issues-unsubscribe@hop.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Feature Request]: Beam State and Side Inputs (hop)

Posted by "mattcasters (via GitHub)" <gi...@apache.org>.
mattcasters closed issue #2676: [Feature Request]: Beam State and Side Inputs
URL: https://github.com/apache/hop/issues/2676


-- 
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: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org