Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-21413

Multiple projections with CASE WHEN fails to run generated codes

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.3.0
    • Fix Version/s: None
    • Component/s: SQL
    • Labels:
      None

      Description

      Scala codes to reproduce are as below:

      import org.apache.spark.sql.functions._
      import org.apache.spark.sql.types._
      import org.apache.spark.sql.Row
      
      val schema = StructType(StructField("fieldA", IntegerType) :: Nil)
      var df = spark.createDataFrame(spark.sparkContext.parallelize(Seq(Row(1))), schema)
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df.show()
      

      Calling explain() on the dataframe in the former case shows a huge case-when projection and show() fails with the exception as below:

      ...
      Caused by: org.codehaus.janino.JaninoRuntimeException: Code of method "apply_0$(Lorg/apache/spark/sql/catalyst/expressions/GeneratedClass$SpecificUnsafeProjection;Lorg/apache/spark/sql/catalyst/InternalRow;)V" of class "org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection" grows beyond 64 KB
        at org.codehaus.janino.CodeContext.makeSpace(CodeContext.java:949)
        at org.codehaus.janino.CodeContext.write(CodeContext.java:839)
        at org.codehaus.janino.UnitCompiler.writeOpcode(UnitCompiler.java:11081)
        at org.codehaus.janino.UnitCompiler.pushConstant(UnitCompiler.java:9674)
        at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4911)
        at org.codehaus.janino.UnitCompiler.access$7700(UnitCompiler.java:206)
        at org.codehaus.janino.UnitCompiler$12.visitIntegerLiteral(UnitCompiler.java:3776)
      ...
      

      Note that, I could not reproduce this with local relation (this one appears by ConvertToLocalRelation).

      import org.apache.spark.sql.functions._
      
      var df = Seq(1).toDF("fieldA")
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df = df.withColumn("fieldA", when($"fieldA" === 0, null).otherwise($"fieldA"))
      df.show()
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                hyukjin.kwon Hyukjin Kwon
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: