NullPointerException when outputting TableRow with null value
NullPointerException when outputting TableRow with null value
I am trying to build a TableRow
object to eventually be written to a BigQuery table, but I get a NullPointerException
if I include a null
value in the row. This is the full stacktrace:
TableRow
NullPointerException
null
Exception in thread "main" org.apache.beam.sdk.Pipeline$PipelineExecutionException: java.lang.NullPointerException
at org.apache.beam.runners.direct.DirectRunner$DirectPipelineResult.waitUntilFinish(DirectRunner.java:349)
at org.apache.beam.runners.direct.DirectRunner$DirectPipelineResult.waitUntilFinish(DirectRunner.java:319)
at org.apache.beam.runners.direct.DirectRunner.run(DirectRunner.java:210)
at org.apache.beam.runners.direct.DirectRunner.run(DirectRunner.java:66)
at org.apache.beam.sdk.Pipeline.run(Pipeline.java:311)
at org.apache.beam.sdk.Pipeline.run(Pipeline.java:297)
at dataflowsandbox.StarterPipeline.runTest(StarterPipeline.java:224)
at dataflowsandbox.StarterPipeline.main(StarterPipeline.java:83)
Caused by: java.lang.NullPointerException
at com.google.api.client.util.ArrayMap$Entry.hashCode(ArrayMap.java:419)
at java.util.AbstractMap.hashCode(AbstractMap.java:530)
at java.util.Arrays.hashCode(Arrays.java:4146)
at java.util.Objects.hash(Objects.java:128)
at org.apache.beam.sdk.util.WindowedValue$ValueInGlobalWindow.hashCode(WindowedValue.java:245)
at java.util.HashMap.hash(HashMap.java:339)
at java.util.HashMap.get(HashMap.java:557)
at org.apache.beam.repackaged.beam_runners_direct_java.com.google.common.collect.AbstractMapBasedMultimap.put(AbstractMapBasedMultimap.java:191)
at org.apache.beam.repackaged.beam_runners_direct_java.com.google.common.collect.AbstractSetMultimap.put(AbstractSetMultimap.java:130)
at org.apache.beam.repackaged.beam_runners_direct_java.com.google.common.collect.HashMultimap.put(HashMultimap.java:48)
at org.apache.beam.runners.direct.ImmutabilityCheckingBundleFactory$ImmutabilityEnforcingBundle.add(ImmutabilityCheckingBundleFactory.java:111)
at org.apache.beam.runners.direct.ParDoEvaluator$BundleOutputManager.output(ParDoEvaluator.java:242)
at org.apache.beam.repackaged.beam_runners_direct_java.runners.core.SimpleDoFnRunner.outputWindowedValue(SimpleDoFnRunner.java:219)
at org.apache.beam.repackaged.beam_runners_direct_java.runners.core.SimpleDoFnRunner.access$700(SimpleDoFnRunner.java:69)
at org.apache.beam.repackaged.beam_runners_direct_java.runners.core.SimpleDoFnRunner$DoFnProcessContext.output(SimpleDoFnRunner.java:517)
at org.apache.beam.repackaged.beam_runners_direct_java.runners.core.SimpleDoFnRunner$DoFnProcessContext.output(SimpleDoFnRunner.java:505)
at dataflowsandbox.StarterPipeline$6.procesElement(StarterPipeline.java:202)
Process finished with exit code 1
This is the code that triggers the NullPointerException
:
NullPointerException
Pipeline p = Pipeline.create( options );
p.apply( "kicker", Create.of( "Kick!" ) )
.apply( "Read values", ParDo.of( new DoFn<String, TableRow>() {
@ProcessElement
public void procesElement( ProcessContext c ) {
TableRow row = new TableRow();
row.set( "ev_id", "2323423423" );
row.set( "customer_id", "111111" );
row.set( "org_id", null ); // Without this line, no NPE
c.output( row );
} }) )
.apply( BigQueryIO.writeTableRows()
.to( DATA_TABLE_OUT )
.withCreateDisposition( CREATE_NEVER )
.withWriteDisposition( WRITE_APPEND ) );
PipelineResult result = p.run();
My actual code is a little more complicated, but I should be able to catch the null
value and just not set it in the row, but maybe I don't understand something about TableRows
.
null
TableRows
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.