You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/01/10 22:52:25 UTC
[GitHub] [spark] karenfeng opened a new pull request #35158: [SPARK-37859] Do not check for metadata during schema comparison
karenfeng opened a new pull request #35158:
URL: https://github.com/apache/spark/pull/35158
### What changes were proposed in this pull request?
Ignores the metadata when comparing the user-provided schema and the actual schema during BaseRelation resolution.
### Why are the changes needed?
Makes it possible to read tables with Spark 3.2 that were written with Spark 3.1, as https://github.com/apache/spark/blob/bd24b4884b804fc85a083f82b864823851d5980c/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala#L312 added a new metadata field that broke compatibility.
### Does this PR introduce _any_ user-facing change?
Yes. Previously, an error was thrown when a SQL table written with JDBC in Spark 3.1 was read in Spark 3.2. Now, no error is thrown.
### How was this patch tested?
Unit test and manual test
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] yikf commented on a change in pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
yikf commented on a change in pull request #35158:
URL: https://github.com/apache/spark/pull/35158#discussion_r781738126
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
##########
@@ -353,7 +353,7 @@ case class DataSource(
case (dataSource: RelationProvider, Some(schema)) =>
val baseRelation =
dataSource.createRelation(sparkSession.sqlContext, caseInsensitiveOptions)
- if (baseRelation.schema != schema) {
+ if (baseRelation.schema.withoutMetadata != schema.withoutMetadata) {
Review comment:
It ignore `nullable`, It is possible have a chance to occur failure in query later? For example, In old 3.1, nullable is true, and there are some null value actually, But nullable is false now, I'm not sure that if have a chance to occur failure of the query.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] huaxingao commented on a change in pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
huaxingao commented on a change in pull request #35158:
URL: https://github.com/apache/spark/pull/35158#discussion_r781756275
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
##########
@@ -353,7 +353,7 @@ case class DataSource(
case (dataSource: RelationProvider, Some(schema)) =>
val baseRelation =
dataSource.createRelation(sparkSession.sqlContext, caseInsensitiveOptions)
- if (baseRelation.schema != schema) {
+ if (baseRelation.schema.withoutMetadata != schema.withoutMetadata) {
Review comment:
I also think we shouldn't ignore `nullable`.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35158:
URL: https://github.com/apache/spark/pull/35158#issuecomment-1010542163
The failed test was added to make sure we can't specify the schema: https://github.com/apache/spark/commit/6463e0b9e8067cce70602c5c9006a2546856a9d6#diff-4c2ebb37fe41af1f32693661d48ddee85146a14a6b0803a4955ada357bfd1076R332
Later on, we changed the test to make sure the user-specified schema matches the actual data source schema. I think we should update the test again to use a truly unmatched schema, like `i: STRING`
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35158:
URL: https://github.com/apache/spark/pull/35158#issuecomment-1009564516
This seems like a 3.2 regression, shall we include it in 3.2.1?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] huaxingao commented on a change in pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
huaxingao commented on a change in pull request #35158:
URL: https://github.com/apache/spark/pull/35158#discussion_r781756977
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
##########
@@ -508,6 +508,15 @@ case class StructType(fields: Array[StructField]) extends DataType with Seq[Stru
f(this) || fields.exists(field => field.dataType.existsRecursively(f))
}
+ private[sql] def withoutMetadata: StructType = {
+ val newFields = fields.map {
+ case StructField(name, dataType, nullable, metadata) =>
Review comment:
super nit: `metadata` is not used. Change to `_`?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35158:
URL: https://github.com/apache/spark/pull/35158#discussion_r781730686
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
##########
@@ -353,7 +353,7 @@ case class DataSource(
case (dataSource: RelationProvider, Some(schema)) =>
val baseRelation =
dataSource.createRelation(sparkSession.sqlContext, caseInsensitiveOptions)
- if (baseRelation.schema != schema) {
+ if (baseRelation.schema.withoutMetadata != schema.withoutMetadata) {
Review comment:
seems we can just call `DataType.equalsIgnoreCompatibleNullability(baseRelation.schema, schema)`
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35158:
URL: https://github.com/apache/spark/pull/35158#discussion_r781757984
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
##########
@@ -353,7 +353,7 @@ case class DataSource(
case (dataSource: RelationProvider, Some(schema)) =>
val baseRelation =
dataSource.createRelation(sparkSession.sqlContext, caseInsensitiveOptions)
- if (baseRelation.schema != schema) {
+ if (baseRelation.schema.withoutMetadata != schema.withoutMetadata) {
Review comment:
The user-specified schema is ignored at the end. Technically we can completely ignore it and don't do any checks. The check is to make sure the user-specified schema is not too wrong. If we can ignore the metadata, it seems to me that compatible nullability can also be ignored. e.g. the actual column is not nullable but is marked as nullable in the user-specified schema, we can still pass the check.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #35158:
URL: https://github.com/apache/spark/pull/35158#issuecomment-1012703190
offline synced. It's because of a bug in my reverted fix. should be fine to go and merge 👍
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35158:
URL: https://github.com/apache/spark/pull/35158#issuecomment-1012171688
Seems all tests passed but the notification doesn't work. @HyukjinKwon is it safe to merge it?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan closed pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #35158:
URL: https://github.com/apache/spark/pull/35158
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] huaxingao commented on a change in pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
huaxingao commented on a change in pull request #35158:
URL: https://github.com/apache/spark/pull/35158#discussion_r781763456
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
##########
@@ -353,7 +353,7 @@ case class DataSource(
case (dataSource: RelationProvider, Some(schema)) =>
val baseRelation =
dataSource.createRelation(sparkSession.sqlContext, caseInsensitiveOptions)
- if (baseRelation.schema != schema) {
+ if (baseRelation.schema.withoutMetadata != schema.withoutMetadata) {
Review comment:
Agree. Thanks for the explanation.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35158:
URL: https://github.com/apache/spark/pull/35158#issuecomment-1010539234
`org.apache.spark.sql.sources.TableScanSuite` is failing.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] huaxingao commented on pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
huaxingao commented on pull request #35158:
URL: https://github.com/apache/spark/pull/35158#issuecomment-1009492471
@karenfeng Does this need to be in 3.2.1?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35158:
URL: https://github.com/apache/spark/pull/35158#discussion_r781757984
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
##########
@@ -353,7 +353,7 @@ case class DataSource(
case (dataSource: RelationProvider, Some(schema)) =>
val baseRelation =
dataSource.createRelation(sparkSession.sqlContext, caseInsensitiveOptions)
- if (baseRelation.schema != schema) {
+ if (baseRelation.schema.withoutMetadata != schema.withoutMetadata) {
Review comment:
The user-specified schema is ignored at the end. Technically we can completely ignore it and don't do any checks. The check is to make sure the user-specified schema is not too wrong. If we can ignore the metadata, it seems to me that compatible nullability can also be ignored. e.g. the actual column is not nullable but is marked as nullable in the user-specified schema.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #35158: [SPARK-37859][SQL] Do not check for metadata during schema comparison
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35158:
URL: https://github.com/apache/spark/pull/35158#issuecomment-1012703463
thanks, merging to master/3.2!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org