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

Fix error when casting from a nested null in a struct

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.4.3, 3.0.0
    • 2.4.4, 3.0.0
    • SQL
    • None

    Description

      When a null in a nested field in struct, casting from the struct throws error, currently.

      scala> sql("select cast(struct(1, null) as struct<a:int,b:int>)").show
      scala.MatchError: NullType (of class org.apache.spark.sql.types.NullType$)                                                                             
        at org.apache.spark.sql.catalyst.expressions.Cast.castToInt(Cast.scala:447)                                                                          
        at org.apache.spark.sql.catalyst.expressions.Cast.cast(Cast.scala:635)                                                                               
        at org.apache.spark.sql.catalyst.expressions.Cast.$anonfun$castStruct$1(Cast.scala:603)   
      
      scala> sql("select * FROM VALUES (('a', (10, null))), (('b', (10, 50))), (('c', null)) AS tab(x, y)").show                                             
      org.apache.spark.sql.AnalysisException: failed to evaluate expression named_struct('col1', 10, 'col2', NULL): NullType (of class org.apache.spark.sql.t
      ypes.NullType$); line 1 pos 14                                                                                                                         
        at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:47)                                                     
        at org.apache.spark.sql.catalyst.analysis.ResolveInlineTables.$anonfun$convert$6(ResolveInlineTables.scala:106)        
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            viirya L. C. Hsieh
            viirya L. C. Hsieh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment