Skip to content

Commit 57d7854

Browse files
yhuaiconviva-zz
authored andcommitted
[SPARK-2888] [SQL] Fix addColumnMetadataToConf in HiveTableScan
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.
1 parent ffcab1e commit 57d7854

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveTableScan.scala

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,12 @@ case class HiveTableScan(
7272
}
7373

7474
private def addColumnMetadataToConf(hiveConf: HiveConf) {
75-
// Specifies IDs and internal names of columns to be scanned.
76-
val neededColumnIDs = attributes.map(a => relation.output.indexWhere(_.name == a.name): Integer)
77-
val columnInternalNames = neededColumnIDs.map(HiveConf.getColumnInternalName(_)).mkString(",")
78-
79-
if (attributes.size == relation.output.size) {
80-
// SQLContext#pruneFilterProject guarantees no duplicated value in `attributes`
81-
ColumnProjectionUtils.setFullyReadColumns(hiveConf)
82-
} else {
83-
ColumnProjectionUtils.appendReadColumnIDs(hiveConf, neededColumnIDs)
84-
}
75+
// Specifies needed column IDs for those non-partitioning columns.
76+
val neededColumnIDs =
77+
attributes.map(a =>
78+
relation.attributes.indexWhere(_.name == a.name): Integer).filter(index => index >= 0)
8579

80+
ColumnProjectionUtils.appendReadColumnIDs(hiveConf, neededColumnIDs)
8681
ColumnProjectionUtils.appendReadColumnNames(hiveConf, attributes.map(_.name))
8782

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

10196
hiveConf.set(serdeConstants.LIST_COLUMN_TYPES, columnTypeNames)
102-
hiveConf.set(serdeConstants.LIST_COLUMNS, columnInternalNames)
97+
hiveConf.set(serdeConstants.LIST_COLUMNS, relation.attributes.map(_.name).mkString(","))
10398
}
10499

105100
addColumnMetadataToConf(context.hiveconf)

0 commit comments

Comments
 (0)