Skip to content

Commit

Permalink
[SPARK-2888] [SQL] Fix addColumnMetadataToConf in HiveTableScan
Browse files Browse the repository at this point in the history
JIRA: https://issues.apache.org/jira/browse/SPARK-2888

Author: Yin Huai <huai@cse.ohio-state.edu>

Closes apache#1817 from yhuai/fixAddColumnMetadataToConf and squashes the following commits:

fba728c [Yin Huai] Fix addColumnMetadataToConf.
  • Loading branch information
yhuai authored and conviva-zz committed Sep 4, 2014
1 parent ffcab1e commit 57d7854
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,12 @@ case class HiveTableScan(
}

private def addColumnMetadataToConf(hiveConf: HiveConf) {
// Specifies IDs and internal names of columns to be scanned.
val neededColumnIDs = attributes.map(a => relation.output.indexWhere(_.name == a.name): Integer)
val columnInternalNames = neededColumnIDs.map(HiveConf.getColumnInternalName(_)).mkString(",")

if (attributes.size == relation.output.size) {
// SQLContext#pruneFilterProject guarantees no duplicated value in `attributes`
ColumnProjectionUtils.setFullyReadColumns(hiveConf)
} else {
ColumnProjectionUtils.appendReadColumnIDs(hiveConf, neededColumnIDs)
}
// 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)

ColumnProjectionUtils.appendReadColumnIDs(hiveConf, neededColumnIDs)
ColumnProjectionUtils.appendReadColumnNames(hiveConf, attributes.map(_.name))

// Specifies types and object inspectors of columns to be scanned.
Expand All @@ -99,7 +94,7 @@ case class HiveTableScan(
.mkString(",")

hiveConf.set(serdeConstants.LIST_COLUMN_TYPES, columnTypeNames)
hiveConf.set(serdeConstants.LIST_COLUMNS, columnInternalNames)
hiveConf.set(serdeConstants.LIST_COLUMNS, relation.attributes.map(_.name).mkString(","))
}

addColumnMetadataToConf(context.hiveconf)
Expand Down

0 comments on commit 57d7854

Please sign in to comment.