Skip to content

Instantly share code, notes, and snippets.

@jlewi
Created March 26, 2015 04:48
Show Gist options
  • Save jlewi/917a82ab8556d3bc4fb7 to your computer and use it in GitHub Desktop.
Save jlewi/917a82ab8556d3bc4fb7 to your computer and use it in GitHub Desktop.
SerializableCoder - setCoder
package snippets;
import java.util.ArrayList;
import java.util.List;
import com.google.cloud.dataflow.sdk.Pipeline;
import com.google.cloud.dataflow.sdk.coders.DefaultCoder;
import com.google.cloud.dataflow.sdk.coders.SerializableCoder;
import com.google.cloud.dataflow.sdk.options.PipelineOptions;
import com.google.cloud.dataflow.sdk.options.PipelineOptionsFactory;
import com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner;
import com.google.cloud.dataflow.sdk.transforms.Create;
import com.google.cloud.dataflow.sdk.values.PCollection;
public class SerializableCoderIssue {
@DefaultCoder(SerializableCoder.class)
public static class CustomType implements java.io.Serializable {
public int a,b;
}
public static void main(String[] args) {
PipelineOptions popts = PipelineOptionsFactory.fromArgs(args).create();
// force local run
popts.setRunner(DirectPipelineRunner.class);
Pipeline pipeline = Pipeline.create(popts);
List<CustomType> lst = new ArrayList<CustomType>();
PCollection<CustomType> reads = pipeline.apply(Create.of(lst)).setCoder(SerializableCoder.of(CustomType.class));
pipeline.run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment