scio
scio copied to clipboard
How to deal with CoderException: cannot encode a null String without wrapping all coders in NullableCoders
Scio version: 0.7.3 Google Dataflow: 2.10.0
I'm trying to run a Dataflow that uses both a PubsubIO and a sc.protobufFile.
I'll occasionally receive empty messages from the PubSubclient (I only use the attributes).
I've been forced to use --nullableCoders=true because the following code does not seem to work (with nullableCoders=false):
val defaultPubsubCoder = sc.pipeline.getCoderRegistry.getCoder(classOf[PubsubMessage])
// <org.apache.beam.sdk.io.gcp.pubsub.PubsubMessageWithAttributesCoder>
val nullableCoder = NullableCoder.of(defaultPubsubCoder)
// NullableCoder(org.apache.beam.sdk.io.gcp.pubsub.PubsubMessageWithAttributesCoder)
// Doesn't seem to work
sc.pipeline.getCoderRegistry.registerCoderForClass(classOf[PubsubMessage], nullableCoder)
This code here does not seem to work either:
val notifications = sc.withName("getting from pubsub")
.customInput("pubsub", PubsubIO.readMessagesWithAttributes().fromSubscription(subscriptionId))
notifications.setCoder(nullableCoder)
The real issue occurs because the ProtoCoder factory used for ProtocolBuffers cannot run properly with nullableCoders=true, yielding this error:
om.spotify.scio.coders.CoderException: NullableCoder expects either a byte valued 0 (null) or 1 (present), got 10
org.apache.beam.sdk.coders.NullableCoder.decode(NullableCoder.java:90)
com.spotify.scio.coders.WrappedBCoder$$anonfun$decode$2.apply(Coder.scala:200)
com.spotify.scio.coders.WrappedBCoder.catching(Coder.scala:188)
com.spotify.scio.coders.WrappedBCoder.decode(Coder.scala:200)
org.apache.beam.sdk.util.CoderUtils.decodeFromSafeStream(CoderUtils.java:115)
org.apache.beam.sdk.util.CoderUtils.decodeFromByteArray(CoderUtils.java:98)
org.apache.beam.sdk.util.CoderUtils.decodeFromByteArray(CoderUtils.java:92)
com.spotify.scio.coders.AvroBytesUtil$.decode(AvroBytesUtil.scala:51)
com.spotify.scio.avro.ObjectFileIO$$anon$1.processElement(AvroIO.scala:59)
com.spotify.scio.avro.ObjectFileIO$$anon$1$DoFnInvoker.invokeProcessElement(Unknown Source)
org.apache.beam.runners.dataflow.worker.repackaged.org.apache.beam.runners.core.SimpleDoFnRunner.invokeProcessElement(SimpleDoFnRunner.java:275)
org.apache.beam.runners.dataflow.worker.repackaged.org.apache.beam.runners.core.SimpleDoFnRunner.processElement(SimpleDoFnRunner.java:240)
...
Could I either confirm that
- these two sources cannot be run together because of the apparent incompatibility with a NullableCoder and
- that setting either a non-nullable coder for Protobuf or a nullable coder for Pubsub explicitly won't work either?