diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala index ea48256147857..e2b79e9145db0 100644 --- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala +++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala @@ -1017,9 +1017,9 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat predicates: Seq[Expression]): Seq[CatalogTablePartition] = withClient { val rawTable = getRawTable(db, table) val catalogTable = restoreTableMetadata(rawTable) - val partitionColumnNames = catalogTable.partitionColumnNames.toSet + val partitionColumnNames = catalogTable.partitionColumnNames.map(_.toLowerCase).toSet val nonPartitionPruningPredicates = predicates.filterNot { - _.references.map(_.name).toSet.subsetOf(partitionColumnNames) + _.references.map(_.name.toLowerCase).toSet.subsetOf(partitionColumnNames) } if (nonPartitionPruningPredicates.nonEmpty) { @@ -1037,7 +1037,7 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat val boundPredicate = InterpretedPredicate.create(predicates.reduce(And).transform { case att: AttributeReference => - val index = partitionSchema.indexWhere(_.name == att.name) + val index = partitionSchema.indexWhere(_.name.toLowerCase == att.name.toLowerCase) BoundReference(index, partitionSchema(index).dataType, nullable = true) }) clientPrunedPartitions.filter { p => boundPredicate(p.toRow(partitionSchema)) } diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala index dd278f683a3cd..4c1640cf3e448 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala @@ -1236,6 +1236,12 @@ class HiveQuerySuite extends HiveComparisonTest with SQLTestUtils with BeforeAnd } } } + + test("SPARK-19490 case sensitivity when filtering hive partition columns") { + sql("CREATE TABLE partition_test (key Int) partitioned by (date string)") + sql("INSERT INTO TABLE partition_test partition(date='20170101') select 1 from src limit 1") + sql("SELECT * FROM partition_test where DATE = '20170101'") + } } // for SPARK-2180 test