You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Takuya Ueshin (Jira)" <ji...@apache.org> on 2023/03/22 21:57:00 UTC

[jira] [Updated] (SPARK-42899) DataFrame.to(schema) fails with the schema of itself.

     [ https://issues.apache.org/jira/browse/SPARK-42899?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Takuya Ueshin updated SPARK-42899:
----------------------------------
    Description: 
{{DataFrame.to(schema)}} fails when it contains non-nullable nested field in nullable field:
{code: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.
{code}

  was:
{{DataFrame.to(schema)}} fails with the schema of itself, when it contains non-nullable nested field in nullable field:

{code: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.
{code}



> DataFrame.to(schema) fails with the schema of itself.
> -----------------------------------------------------
>
>                 Key: SPARK-42899
>                 URL: https://issues.apache.org/jira/browse/SPARK-42899
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 3.4.0
>            Reporter: Takuya Ueshin
>            Priority: Major
>
> {{DataFrame.to(schema)}} fails when it contains non-nullable nested field in nullable field:
> {code: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.
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org