ueshin opened a new pull request, #40526:
URL: https://github.com/apache/spark/pull/40526

   ### What changes were proposed in this pull request?
   
   Fixes `DataFrame.to(schema)` to handle the case where there is a 
non-nullable nested field in a nullable field.
   
   ### Why are the changes needed?
   
   `DataFrame.to(schema)` fails when it contains non-nullable nested field in 
nullable field:
   
   ```scala
   scala> val df = spark.sql("VALUES (1, STRUCT(1 as i)), (NULL, NULL) as t(a, 
b)")
   df: org.apache.spark.sql.DataFrame = [a: int, b: struct<i: int>]
   scala> df.printSchema()
   root
    |-- a: integer (nullable = true)
    |-- b: struct (nullable = true)
    |    |-- i: integer (nullable = false)
   
   scala> df.to(df.schema)
   org.apache.spark.sql.AnalysisException: [NULLABLE_COLUMN_OR_FIELD] Column or 
field `b`.`i` is nullable while it's required to be non-nullable.
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   Added the related tests.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to