You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "pan3793 (via GitHub)" <gi...@apache.org> on 2025/09/16 14:30:38 UTC
[PR] [SPARK-53598][SQL] Check numParts field for Hive tables before reading data source schema [spark]
pan3793 opened a new pull request, #52355:
URL: https://github.com/apache/spark/pull/52355
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
This PR proposes to fix a regression caused by SPARK-33812 (3.2.0).
We hit an error when upgrading Spark from 3.1 to 3.3, the table is a Hive SerDe Parquet table, which TBLPROPERTIES looks like malformed (not sure how this happen), the table can be read and write normally with Spark 3.1, but fails on reading with Spark 3.3.
```
CREATE EXTERNAL TABLE `foo`.`bar`(
`id` bigint,
...
) PARTITIONED BY (`dt` string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
'hdfs://...'
TBLPROPERTIES (
...
'spark.sql.sources.schema.partCol.0'='dt',
'transient_lastDdlTime'='1727333678')
```
```
org.apache.spark.sql.AnalysisException: Cannot read table property 'spark.sql.sources.schema' as it's corrupted.
at org.apache.spark.sql.errors.QueryCompilationErrors$.cannotReadCorruptedTablePropertyError(QueryCompilationErrors.scala:840) ~[spark-catalyst_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.catalyst.catalog.CatalogTable$.$anonfun$readLargeTableProp$1(interface.scala:502) ~[spark-catalyst_2.12-3.3.4.104.jar:3.3.4.104]
at scala.Option.orElse(Option.scala:447) ~[scala-library-2.12.18.jar:?]
at org.apache.spark.sql.catalyst.catalog.CatalogTable$.readLargeTableProp(interface.scala:497) ~[spark-catalyst_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.hive.HiveExternalCatalog.getSchemaFromTableProperties(HiveExternalCatalog.scala:839) ~[spark-hive_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.hive.HiveExternalCatalog.restoreHiveSerdeTable(HiveExternalCatalog.scala:809) ~[spark-hive_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.hive.HiveExternalCatalog.restoreTableMetadata(HiveExternalCatalog.scala:765) ~[spark-hive_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.hive.HiveExternalCatalog.$anonfun$getTable$1(HiveExternalCatalog.scala:734) ~[spark-hive_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.hive.HiveExternalCatalog.withClient(HiveExternalCatalog.scala:101) ~[spark-hive_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.hive.HiveExternalCatalog.getTable(HiveExternalCatalog.scala:734) ~[spark-hive_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.catalyst.catalog.ExternalCatalogWithListener.getTable(ExternalCatalogWithListener.scala:138) ~[spark-catalyst_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.catalyst.catalog.SessionCatalog.getTableRawMetadata(SessionCatalog.scala:544) ~[spark-catalyst_2.12-3.3.4.104.jar:3.3.4.104]
at org.apache.spark.sql.catalyst.catalog.SessionCatalog.getTableMetadata(SessionCatalog.scala:529) ~[spark-catalyst_2.12-3.3.4.104.jar:3.3.4.104]
...
```
Behavior change is caused by https://github.com/apache/spark/commit/de234eec8febce99ede5ef9ae2301e36739a0f85, previously, it skips infer schema from table properties if `spark.sql.sources.schema.numParts` missing.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
Restore behavior before Spark 3.2.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
Yes, restores behavior before Spark 3.2.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
UT is added.
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
No.
--
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
Re: [PR] [SPARK-53598][SQL] Check the existence of numParts before reading large table property [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #52355:
URL: https://github.com/apache/spark/pull/52355#discussion_r2357443745
##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala:
##########
@@ -1378,62 +1378,78 @@ class MetastoreDataSourcesSuite extends QueryTest
}
test("read table with corrupted schema") {
- try {
- val schema = StructType(StructField("int", IntegerType) :: Nil)
- val hiveTableWithoutNumPartsProp = CatalogTable(
- identifier = TableIdentifier("t", Some("default")),
- tableType = CatalogTableType.MANAGED,
- schema = HiveExternalCatalog.EMPTY_DATA_SCHEMA,
- provider = Some("json"),
- storage = CatalogStorageFormat.empty,
- properties = Map(
- DATASOURCE_PROVIDER -> "json",
- DATASOURCE_SCHEMA_PART_PREFIX + 0 -> schema.json))
-
- hiveClient.createTable(hiveTableWithoutNumPartsProp, ignoreIfExists = false)
-
- checkError(
- exception = intercept[AnalysisException] {
- sharedState.externalCatalog.getTable("default", "t")
- },
- condition = "INSUFFICIENT_TABLE_PROPERTY.MISSING_KEY",
- parameters = Map("key" -> toSQLConf("spark.sql.sources.schema"))
- )
-
- val hiveTableWithNumPartsProp = CatalogTable(
- identifier = TableIdentifier("t2", Some("default")),
- tableType = CatalogTableType.MANAGED,
- schema = HiveExternalCatalog.EMPTY_DATA_SCHEMA,
- provider = Some("json"),
- storage = CatalogStorageFormat.empty,
- properties = Map(
- DATASOURCE_PROVIDER -> "json",
- DATASOURCE_SCHEMA_PREFIX + "numParts" -> "3",
- DATASOURCE_SCHEMA_PART_PREFIX + 0 -> schema.json))
-
- hiveClient.createTable(hiveTableWithNumPartsProp, ignoreIfExists = false)
+ Seq(true, false).foreach { isHiveTable =>
+ try {
+ val schema = StructType(StructField("int", IntegerType) :: Nil)
+ val hiveTableWithoutNumPartsProp = CatalogTable(
Review Comment:
this requires parameterizing more things, I prefer to keep it as-is unless you strongly disagree
--
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
Re: [PR] [SPARK-53598][SQL] Check the existence of numParts before reading large table property [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #52355:
URL: https://github.com/apache/spark/pull/52355#issuecomment-3306464442
thanks, merging to master/4.0!
--
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
Re: [PR] [SPARK-53598][SQL] Check numParts field for Hive tables before reading schema [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #52355:
URL: https://github.com/apache/spark/pull/52355#discussion_r2354414353
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala:
##########
@@ -763,11 +763,17 @@ object CatalogTable {
}
}
- def readLargeTableProp(props: Map[String, String], key: String): Option[String] = {
+ def readLargeTableProp(
+ props: Map[String, String],
+ key: String,
+ failIfNumPartsMissing: Boolean = true): Option[String] = {
Review Comment:
Before SPARK-33812, it performs `true` for the DS table on schema reading, but `false` for the Hive SerDe table, I'm trying to restore such behavior.
SPARK-33812 introduces another case - ColumStats histogram, when `numParts` is missing, it fails here and
https://github.com/apache/spark/blob/f2e9c680ed398b3797f7293c6f50979c457e9e37/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala#L1009-L1032
--
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
Re: [PR] [SPARK-53598][SQL] Check the existence of numParts before reading large table property [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #52355: [SPARK-53598][SQL] Check the existence of numParts before reading large table property
URL: https://github.com/apache/spark/pull/52355
--
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
Re: [PR] [SPARK-53598][SQL] Check numParts field for Hive tables before reading schema [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52355:
URL: https://github.com/apache/spark/pull/52355#discussion_r2354402938
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala:
##########
@@ -763,11 +763,17 @@ object CatalogTable {
}
}
- def readLargeTableProp(props: Map[String, String], key: String): Option[String] = {
+ def readLargeTableProp(
+ props: Map[String, String],
+ key: String,
+ failIfNumPartsMissing: Boolean = true): Option[String] = {
Review Comment:
when it's needed to be true? I think it's fine to always be more lenient, as the consequence is simply doing a schema inference, which is better than 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
Re: [PR] [SPARK-53598][SQL] Check the existence of numParts before reading large table property [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #52355:
URL: https://github.com/apache/spark/pull/52355#issuecomment-3306471174
please open new PRs if you want to backport further.
--
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
Re: [PR] [SPARK-53598][SQL] Check the existence of numParts before reading large table property [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #52355:
URL: https://github.com/apache/spark/pull/52355#issuecomment-3306688128
@cloud-fan thanks, I opened https://github.com/apache/spark/pull/52385 for 3.5
--
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
Re: [PR] [SPARK-53598][SQL] Check the existence of numParts before reading large table property [spark]
Posted by "vrozov (via GitHub)" <gi...@apache.org>.
vrozov commented on code in PR #52355:
URL: https://github.com/apache/spark/pull/52355#discussion_r2356971223
##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala:
##########
@@ -1378,62 +1378,78 @@ class MetastoreDataSourcesSuite extends QueryTest
}
test("read table with corrupted schema") {
- try {
- val schema = StructType(StructField("int", IntegerType) :: Nil)
- val hiveTableWithoutNumPartsProp = CatalogTable(
- identifier = TableIdentifier("t", Some("default")),
- tableType = CatalogTableType.MANAGED,
- schema = HiveExternalCatalog.EMPTY_DATA_SCHEMA,
- provider = Some("json"),
- storage = CatalogStorageFormat.empty,
- properties = Map(
- DATASOURCE_PROVIDER -> "json",
- DATASOURCE_SCHEMA_PART_PREFIX + 0 -> schema.json))
-
- hiveClient.createTable(hiveTableWithoutNumPartsProp, ignoreIfExists = false)
-
- checkError(
- exception = intercept[AnalysisException] {
- sharedState.externalCatalog.getTable("default", "t")
- },
- condition = "INSUFFICIENT_TABLE_PROPERTY.MISSING_KEY",
- parameters = Map("key" -> toSQLConf("spark.sql.sources.schema"))
- )
-
- val hiveTableWithNumPartsProp = CatalogTable(
- identifier = TableIdentifier("t2", Some("default")),
- tableType = CatalogTableType.MANAGED,
- schema = HiveExternalCatalog.EMPTY_DATA_SCHEMA,
- provider = Some("json"),
- storage = CatalogStorageFormat.empty,
- properties = Map(
- DATASOURCE_PROVIDER -> "json",
- DATASOURCE_SCHEMA_PREFIX + "numParts" -> "3",
- DATASOURCE_SCHEMA_PART_PREFIX + 0 -> schema.json))
-
- hiveClient.createTable(hiveTableWithNumPartsProp, ignoreIfExists = false)
+ Seq(true, false).foreach { isHiveTable =>
+ try {
+ val schema = StructType(StructField("int", IntegerType) :: Nil)
+ val hiveTableWithoutNumPartsProp = CatalogTable(
Review Comment:
Can construction of `CatalogTable` be refactored to a separate method that takes 3 parameters (table name, table type and num of part) to avoid code duplication here and on line 1405?
--
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
Re: [PR] [SPARK-53598][SQL] Check numParts field for Hive tables before reading schema [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #52355:
URL: https://github.com/apache/spark/pull/52355#discussion_r2354414353
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala:
##########
@@ -763,11 +763,17 @@ object CatalogTable {
}
}
- def readLargeTableProp(props: Map[String, String], key: String): Option[String] = {
+ def readLargeTableProp(
+ props: Map[String, String],
+ key: String,
+ failIfNumPartsMissing: Boolean = true): Option[String] = {
Review Comment:
Before SPARK-33812, it performs `true` for the DS table on schema reading, but `false` for the Hive SerDe table, I'm trying to restore such behavior.
SPARK-33812 introduces another case - ColumStats histogram, when `numParts` is missing, it fails here and the exception will be caught at
https://github.com/apache/spark/blob/f2e9c680ed398b3797f7293c6f50979c457e9e37/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala#L1009-L1032
--
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
Re: [PR] [SPARK-53598][SQL] Check numParts field for Hive tables before reading data source schema [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #52355:
URL: https://github.com/apache/spark/pull/52355#issuecomment-3299390437
cc @cloud-fan as you are the author of SPARK-33812(https://github.com/apache/spark/commit/de234eec8febce99ede5ef9ae2301e36739a0f85)
--
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
Re: [PR] [SPARK-53598][SQL] Check numParts field for Hive tables before reading schema [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #52355:
URL: https://github.com/apache/spark/pull/52355#discussion_r2354983545
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala:
##########
@@ -763,11 +763,17 @@ object CatalogTable {
}
}
- def readLargeTableProp(props: Map[String, String], key: String): Option[String] = {
+ def readLargeTableProp(
+ props: Map[String, String],
+ key: String,
+ failIfNumPartsMissing: Boolean = true): Option[String] = {
Review Comment:
@cloud-fan I updated the code as you suggested, could you take another look?
--
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