Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Push down predicates when convertMetastoreParquet=true
  • Loading branch information
Cheolsoo Park committed Jun 29, 2015
commit 095672f00ca23c5d071650f3d00657dfe20f38be
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ private[hive] class HiveMetastoreCatalog(val client: ClientInterface, hive: Hive
val result = if (metastoreRelation.hiveQlTable.isPartitioned) {
val partitionSchema = StructType.fromAttributes(metastoreRelation.partitionKeys)
val partitionColumnDataTypes = partitionSchema.map(_.dataType)
// This is for non-partitioned tables, so partition pruning predicates
// cannot be pushed into Hive metastore.
val partitions = metastoreRelation.getHiveQlPartitions(None).map { p =>
val location = p.getLocation
val values = InternalRow.fromSeq(p.getValues.zip(partitionColumnDataTypes).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ private[hive] object HiveShim {
partitionKeys: List[FieldSchema],
hiveMetastoreVersion: String): Option[String] = {

// Binary comparison operators such as >, <, >=, and <= started being supported by
// getPartitionsByFilter() in 0.13. So if Hive matastore version is older than 0.13,
// no predicate is pushed down. See HIVE-4888.
// Binary comparison operators have been supported in getPartitionsByFilter() since 0.13.
// So if Hive matastore version is older than 0.13, predicates cannot be pushed down.
// See HIVE-4888.
val versionPattern = "([\\d]+\\.[\\d]+).*".r
hiveMetastoreVersion match {
case versionPattern(version) => if (version.toDouble < 0.13) return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ private[hive] trait HiveStrategies {

try {
if (relation.hiveQlTable.isPartitioned) {

val metastoreFilter =
HiveShim.toMetastoreFilter(
pruningPredicates,
relation.hiveQlTable.getPartitionKeys,
hiveContext.hiveMetastoreVersion)

val rawPredicate = pruningPredicates.reduceOption(And).getOrElse(Literal(true))
// Translate the predicate so that it automatically casts the input values to the
// correct data types during evaluation.
Expand All @@ -124,7 +131,7 @@ private[hive] trait HiveStrategies {
InterpretedPredicate.create(castedPredicate)
}

val partitions = relation.getHiveQlPartitions(None).filter { part =>
val partitions = relation.getHiveQlPartitions(metastoreFilter).filter { part =>
val partitionValues = part.getValues
var i = 0
while (i < partitionValues.size()) {
Expand Down