Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-27080][SQL]bug fix: mergeWithMetastoreSchema with uniform lower case comparison #24001

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ private[hive] object HiveMetastoreCatalog {
// Merge missing nullable fields to inferred schema and build a case-insensitive field map.
val inferredFields = StructType(inferredSchema ++ missingNullables)
.map(f => f.name.toLowerCase -> f).toMap
StructType(metastoreSchema.map(f => f.copy(name = inferredFields(f.name.toLowerCase).name)))
// scalastyle:on caselocale
StructType(metastoreSchema.map(f => f.copy(name = inferredFields(f.name).name)))
} catch {
case NonFatal(_) =>
val msg = s"""Detected conflicting schemas when merging the schema obtained from the Hive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,32 @@ class HiveSchemaInferenceSuite
StructType(Seq(StructField("lowerCase", BinaryType))))
}

// Parquet schema is subset of metaStore schema and has uppercase field name
assertResult(
StructType(Seq(
StructField("UPPERCase", DoubleType, nullable = true),
StructField("lowerCase", BinaryType, nullable = true)))) {

HiveMetastoreCatalog.mergeWithMetastoreSchema(
StructType(Seq(
StructField("UPPERCase", DoubleType, nullable = true),
StructField("lowerCase", BinaryType, nullable = true))),

StructType(Seq(
StructField("lowerCase", BinaryType, nullable = true))))
}

// Metastore schema contains additional nullable fields.
assert(intercept[Throwable] {
HiveMetastoreCatalog.mergeWithMetastoreSchema(
StructType(Seq(
StructField("UPPERCase", DoubleType, nullable = false),
StructField("lowerCase", BinaryType, nullable = true))),

StructType(Seq(
StructField("lowerCase", BinaryType, nullable = true))))
}.getMessage.contains("Detected conflicting schemas"))

// Check that merging missing nullable fields works as expected.
assertResult(
StructType(Seq(
Expand Down