Skip to content

Commit

Permalink
bug fix: mergeWithMetastoreSchema with Uuniform lower case comparison
Browse files Browse the repository at this point in the history
(cherry picked from commit f47a765)
  • Loading branch information
CodeGod committed Mar 7, 2019
1 parent a0e26cf commit dec978d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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

0 comments on commit dec978d

Please sign in to comment.