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 @@ -308,4 +308,10 @@ private[hive] case class MetastoreRelation
val attributes = hiveQlTable.getCols.map(_.toAttribute)

val output = attributes ++ partitionKeys

/** An attribute map that can be used to lookup original attributes based on expression id. */
val attributeMap = AttributeMap(output.map(o => (o,o)))

/** An attribute map for determining the ordinal for non-partition columns. */
val columnOrdinals = AttributeMap(attributes.zipWithIndex)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import org.apache.spark.sql.hive._
*/
@DeveloperApi
case class HiveTableScan(
attributes: Seq[Attribute],
requestedAttributes: Seq[Attribute],
relation: MetastoreRelation,
partitionPruningPred: Option[Expression])(
@transient val context: HiveContext)
Expand All @@ -54,6 +54,9 @@ case class HiveTableScan(
require(partitionPruningPred.isEmpty || relation.hiveQlTable.isPartitioned,
"Partition pruning predicates only supported for partitioned tables.")

// Retrieve the original attributes based on expression ID so that capitalization matches.
val attributes = requestedAttributes.map(relation.attributeMap)

// Bind all partition key attribute references in the partition pruning predicate for later
// evaluation.
private[this] val boundPruningPred = partitionPruningPred.map { pred =>
Expand All @@ -79,9 +82,7 @@ case class HiveTableScan(

private def addColumnMetadataToConf(hiveConf: HiveConf) {
// Specifies needed column IDs for those non-partitioning columns.
val neededColumnIDs =
attributes.map(a =>
relation.attributes.indexWhere(_.name == a.name): Integer).filter(index => index >= 0)
val neededColumnIDs = attributes.flatMap(relation.columnOrdinals.get).map(o => o: Integer)

ColumnProjectionUtils.appendReadColumnIDs(hiveConf, neededColumnIDs)
ColumnProjectionUtils.appendReadColumnNames(hiveConf, attributes.map(_.name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.sql.hive.execution

import org.apache.spark.sql.hive.test.TestHive

class HiveTableScanSuite extends HiveComparisonTest {

createQueryTest("partition_based_table_scan_with_different_serde",
Expand All @@ -38,4 +40,11 @@ class HiveTableScanSuite extends HiveComparisonTest {
|
|SELECT * from part_scan_test;
""".stripMargin)

test("Spark-4041: lowercase issue") {
TestHive.sql("CREATE TABLE tb (KEY INT, VALUE STRING) STORED AS ORC")
TestHive.sql("insert into table tb select key, value from src")
TestHive.sql("select KEY from tb where VALUE='just_for_test' limit 5").collect()
TestHive.sql("drop table tb")
}
}