title: Spark 3.1.1 throws compilation error in generated.java file
body: <p>we are using spark 3.1.1 with java, in that i saw compilation error while processing empty dataset. error is,</p>
  <pre><code>ERROR org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator: failed to compile: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 29, Column 133: IDENTIFIER expected instead of '['
  org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 29, Column 133: IDENTIFIER expected instead of '['
      at org.codehaus.janino.TokenStreamImpl.read(TokenStreamImpl.java:196)
      at org.codehaus.janino.Parser.read(Parser.java:3705)
  
  
  ----
  ----
  ----
  WARN org.apache.spark.sql.execution.WholeStageCodegenExec: Whole-stage codegen disabled for plan (id=30):
  </code></pre>
  <p>In some scenarios, we got empty dataset as follows,</p>
  <pre><code>+------------------+-------------------+------------------+
  |col1              |col2               |col3              |
  +------------------+-------------------+------------------+
  +------------------+-------------------+------------------+
  
  </code></pre>
  <p>if we try to process this dataset or dataset.show(false); throws this compilation error. But application is working fine. To maintain error free console we need to fix this one.
  I tried 2 approaches,</p>
  <p>First Approach,</p>
  <p>Try to add null/empty array (depends on the column datatype) while creating dataset
  like this,</p>
  <pre><code>List&lt;Integer&gt; result = new ArrayList&lt;&gt;();
  dataset.withColumn(&quot;col1&quot;,
              when(col(col1.subElement).isNotNull(), col(&quot;col1&quot;)).otherwise(result));
  </code></pre>
  <p>In our case, col1 is proto field, in that we have multiple elements. this is one of them. subElement:[10,20,30]</p>
  <p>SO i try to pass empty array if it doest't have any data. In that i got error as,</p>
  <pre><code>[main] WARN org.apache.spark.sql.catalyst.util.package - Truncated the string representation of a plan since it was too large. This behavior can be adjusted by setting 'spark.sql.debug.maxToStringFields'.
  </code></pre>
  <p>if we set maxToStringFields, cause performance issue. So i did't go this way.</p>
  <p>Second Approach,</p>
  <p>Try by adding null check while processing this dataset. like this,</p>
  <pre><code>List&lt;Integer&gt; result = new ArrayList&lt;&gt;();
  dataset.withColumn((&quot;col1&quot;),
              when(col(col1.subElement).isNull(), result).otherwise(explode(col(col1.subElement))));
  
  </code></pre>
  <p>Here, issue is we need to explode col1.subElement to many rows as it has array of elements. But i can't do null check on this. got error like below,</p>
  <pre><code>org.apache.spark.sql.AnalysisException: Generators are not supported when it's nested in expressions, but got: CASE WHEN (col1.subElement AS `subElement` IS NULL) THEN NULL ELSE explode(col1.subElement AS `subElement`) END
  
  </code></pre>
  <p>Is there any possible way to fix this issue?</p>