File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
main/scala/org/apache/spark/sql/hive/orc
test/scala/org/apache/spark/sql/hive/orc Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -313,7 +313,17 @@ private[orc] object OrcRelation extends HiveInspectors {
313313
314314 def setRequiredColumns (
315315 conf : Configuration , physicalSchema : StructType , requestedSchema : StructType ): Unit = {
316- val ids = requestedSchema.map(a => physicalSchema.fieldIndex(a.name): Integer )
316+ val caseInsensitiveFieldMap : Map [String , Int ] = physicalSchema.fieldNames
317+ .zipWithIndex
318+ .map(f => (f._1.toLowerCase, f._2))
319+ .toMap
320+ val ids = requestedSchema.map { a =>
321+ val exactMatch : Option [Int ] = physicalSchema.getFieldIndex(a.name)
322+ val res = exactMatch.getOrElse(
323+ caseInsensitiveFieldMap.getOrElse(a.name,
324+ throw new IllegalArgumentException (s """ Field " $a.name" does not exist. """ )))
325+ res : Integer
326+ }
317327 val (sortedIDs, sortedNames) = ids.zip(requestedSchema.fieldNames).sorted.unzip
318328 HiveShim .appendReadColumns(conf, sortedIDs, sortedNames)
319329 }
Original file line number Diff line number Diff line change @@ -474,6 +474,28 @@ class OrcQuerySuite extends QueryTest with BeforeAndAfterAll with OrcTest {
474474 }
475475 }
476476
477+ test(" converted ORC table supports resolving mixed case field" ) {
478+ withSQLConf(HiveUtils .CONVERT_METASTORE_ORC .key -> " true" ) {
479+ withTable(" dummy_orc" ) {
480+ withTempPath { dir =>
481+ val df = spark.range(5 ).selectExpr(" id" , " id as valueField" , " id as partitionValue" )
482+ df.write
483+ .partitionBy(" partitionValue" )
484+ .mode(" overwrite" )
485+ .orc(dir.getAbsolutePath)
486+
487+ spark.sql(s """
488+ |create external table dummy_orc (id long, valueField long)
489+ |partitioned by (partitionValue int)
490+ |stored as orc
491+ |location " ${dir.getAbsolutePath}" """ .stripMargin)
492+ spark.sql(s " msck repair table dummy_orc " )
493+ checkAnswer(spark.sql(" select * from dummy_orc" ), df)
494+ }
495+ }
496+ }
497+ }
498+
477499 test(" SPARK-14962 Produce correct results on array type with isnotnull" ) {
478500 withSQLConf(SQLConf .ORC_FILTER_PUSHDOWN_ENABLED .key -> " true" ) {
479501 val data = (0 until 10 ).map(i => Tuple1 (Array (i)))
You can’t perform that action at this time.
0 commit comments