Skip to content
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 @@ -269,15 +269,11 @@ private[parquet] object ParquetReadSupport {
*/
private def clipParquetGroupFields(
parquetRecord: GroupType, structType: StructType): Seq[Type] = {
val parquetFieldMap = parquetRecord.getFields.asScala
.map(f => f.getName -> f).toMap
val caseInsensitiveParquetFieldMap = parquetRecord.getFields.asScala
.map(f => f.getName.toLowerCase -> f).toMap
val parquetFieldMap = parquetRecord.getFields.asScala.map(f => f.getName -> f).toMap
val toParquet = new ParquetSchemaConverter(writeLegacyParquetFormat = false)
structType.map { f =>
parquetFieldMap
.get(f.name)
.orElse(caseInsensitiveParquetFieldMap.get(f.name.toLowerCase))
.map(clipParquetType(_, f.dataType))
.getOrElse(toParquet.convertField(f))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,34 +1080,6 @@ class ParquetSchemaSuite extends ParquetSchemaTest {
}
}

testSchemaClipping(
"falls back to case insensitive resolution",

parquetSchema =
"""message root {
| required group A {
| optional int32 B;
| }
| optional int32 c;
|}
""".stripMargin,

catalystSchema = {
val nestedType = new StructType().add("b", IntegerType, nullable = true)
new StructType()
.add("a", nestedType, nullable = true)
.add("c", IntegerType, nullable = true)
},

expectedSchema =
"""message root {
| required group A {
| optional int32 B;
| }
| optional int32 c;
|}
""".stripMargin)

testSchemaClipping(
"simple nested struct",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,7 @@ private[orc] object OrcRelation extends HiveInspectors {

def setRequiredColumns(
conf: Configuration, physicalSchema: StructType, requestedSchema: StructType): Unit = {
val caseInsensitiveFieldMap: Map[String, Int] = physicalSchema.fieldNames
.zipWithIndex
.map(f => (f._1.toLowerCase, f._2))
.toMap
val ids = requestedSchema.map { a =>
val exactMatch: Option[Int] = physicalSchema.getFieldIndex(a.name)
val res = exactMatch.getOrElse(
caseInsensitiveFieldMap.getOrElse(a.name,
throw new IllegalArgumentException(s"""Field "$a.name" does not exist.""")))
res: Integer
}
val ids = requestedSchema.map(a => physicalSchema.fieldIndex(a.name): Integer)
val (sortedIDs, sortedNames) = ids.zip(requestedSchema.fieldNames).sorted.unzip
HiveShim.appendReadColumns(conf, sortedIDs, sortedNames)
}
Expand Down