Java Code Examples for org.apache.beam.sdk.coders.CoderRegistry#registerCoderForClass()

The following examples show how to use org.apache.beam.sdk.coders.CoderRegistry#registerCoderForClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NexmarkUtils.java    From beam with Apache License 2.0 5 votes vote down vote up
/** Setup pipeline with codes and some other options. */
public static void setupPipeline(CoderStrategy coderStrategy, Pipeline p) {
  CoderRegistry registry = p.getCoderRegistry();
  switch (coderStrategy) {
    case HAND:
      registry.registerCoderForClass(Auction.class, Auction.CODER);
      registry.registerCoderForClass(AuctionBid.class, AuctionBid.CODER);
      registry.registerCoderForClass(AuctionCount.class, AuctionCount.CODER);
      registry.registerCoderForClass(AuctionPrice.class, AuctionPrice.CODER);
      registry.registerCoderForClass(Bid.class, Bid.CODER);
      registry.registerCoderForClass(CategoryPrice.class, CategoryPrice.CODER);
      registry.registerCoderForClass(Event.class, Event.CODER);
      registry.registerCoderForClass(IdNameReserve.class, IdNameReserve.CODER);
      registry.registerCoderForClass(NameCityStateId.class, NameCityStateId.CODER);
      registry.registerCoderForClass(Person.class, Person.CODER);
      registry.registerCoderForClass(SellerPrice.class, SellerPrice.CODER);
      registry.registerCoderForClass(Done.class, Done.CODER);
      registry.registerCoderForClass(BidsPerSession.class, BidsPerSession.CODER);
      break;
    case AVRO:
      registry.registerCoderProvider(AvroCoder.getCoderProvider());
      break;
    case JAVA:
      registry.registerCoderProvider(SerializableCoder.getCoderProvider());
      break;
  }
}
 
Example 2
Source File: HL7v2IO.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public Result expand(PCollection<String> msgIds) {
  CoderRegistry coderRegistry = msgIds.getPipeline().getCoderRegistry();
  coderRegistry.registerCoderForClass(HL7v2Message.class, HL7v2MessageCoder.of());
  return new Result(
      msgIds.apply(
          ParDo.of(new FetchHL7v2Message.HL7v2MessageGetFn())
              .withOutputTags(HL7v2IO.Read.OUT, TupleTagList.of(HL7v2IO.Read.DEAD_LETTER))));
}
 
Example 3
Source File: HL7v2IO.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public PCollection<HL7v2Message> expand(PBegin input) {
  CoderRegistry coderRegistry = input.getPipeline().getCoderRegistry();
  coderRegistry.registerCoderForClass(HL7v2Message.class, HL7v2MessageCoder.of());
  return input
      .apply(Create.ofProvider(this.hl7v2Stores, ListCoder.of(StringUtf8Coder.of())))
      .apply(FlatMapElements.into(TypeDescriptors.strings()).via((x) -> x))
      .apply(ParDo.of(new ListHL7v2MessagesFn(filter, initialSplitDuration)))
      .setCoder(HL7v2MessageCoder.of())
      // Break fusion to encourage parallelization of downstream processing.
      .apply(Reshuffle.viaRandomKey());
}
 
Example 4
Source File: CalculateCoverage.java    From dataflow-java with Apache License 2.0 5 votes vote down vote up
public static void registerPipelineCoders(Pipeline p) {
  CoderRegistry cr = p.getCoderRegistry();
  cr.registerCoderForClass(Annotation.class,
    (Coder<Annotation>) GenericJsonCoder.of(Annotation.class));
  cr.registerCoderForClass(AnnotationSet.class,
    (Coder<AnnotationSet>) GenericJsonCoder.of(AnnotationSet.class));
  cr.registerCoderForClass(BatchCreateAnnotationsRequest.class,
    (Coder<BatchCreateAnnotationsRequest>) GenericJsonCoder
      .of(BatchCreateAnnotationsRequest.class));
  cr.registerCoderForClass(PosRgsMq.class,
    (Coder<PosRgsMq>) GenericJsonCoder.of(PosRgsMq.class));
  cr.registerCoderForClass(Position.class,
    (Coder<Position>) GenericJsonCoder.of(Position.class));
}
 
Example 5
Source File: HL7v2IO.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
public Result expand(PCollection<String> input) {
  CoderRegistry coderRegistry = input.getPipeline().getCoderRegistry();
  coderRegistry.registerCoderForClass(HL7v2Message.class, HL7v2MessageCoder.of());
  return input.apply("Fetch HL7v2 messages", new FetchHL7v2Message());
}
 
Example 6
Source File: HL7v2IO.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
public Result expand(PCollection<HL7v2Message> messages) {
  CoderRegistry coderRegistry = messages.getPipeline().getCoderRegistry();
  coderRegistry.registerCoderForClass(HL7v2Message.class, HL7v2MessageCoder.of());
  return messages.apply(new WriteHL7v2(this.getHL7v2Store(), this.getWriteMethod()));
}
 
Example 7
Source File: VerifyBamId.java    From dataflow-java with Apache License 2.0 4 votes vote down vote up
public static void registerPipelineCoders(Pipeline p) {
  CoderRegistry cr = p.getCoderRegistry();
  cr.registerCoderForClass(ReadCounts.class,
    (Coder<ReadCounts>) GenericJsonCoder.of(ReadCounts.class));
  cr.registerCoderForClass(Position.class, ProtoCoder.of(Position.class));
}