Intermittent NullPointerException when AQE is enabled

When adaptive query execution (AQE) is enabled, and cluster scales down and loses shuffle data, you can get a `NullPointerException` error.

Written by mathan.pillai

Last published at: May 23rd, 2022


You get an intermittent NullPointerException error when saving your data.

Py4JJavaError: An error occurred while calling
: java.lang.NullPointerException
    at org.apache.spark.sql.execution.adaptive.OptimizeSkewedJoin.$anonfun$getMapSizesForReduceId$1(OptimizeSkewedJoin.scala:167)
    at org.apache.spark.sql.execution.adaptive.OptimizeSkewedJoin.$anonfun$getMapSizesForReduceId$1$adapted(OptimizeSkewedJoin.scala:167)
    at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:238)
    at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at py4j.reflection.MethodInvoker.invoke(
    at py4j.reflection.ReflectionEngine.invoke(
    at py4j.Gateway.invoke(
    at py4j.commands.AbstractCommand.invokeMethod(
    at py4j.commands.CallCommand.execute(


This error can occur if adaptive query execution (AQE) (AWS | Azure) is enabled and you are joining data. If AQE is enabled, skew join is also enabled.

If any of the shuffle data fails due to a cluster scaling down event it generates a NullPointerException error.


Set spark.sql.adaptive.skewJoin.enabled to false in your Spark config (AWS | Azure).