spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From viirya <...@git.apache.org>
Subject [GitHub] spark pull request #17633: [SPARK-20331][SQL] Enhanced Hive partition prunin...
Date Tue, 04 Jul 2017 02:02:58 GMT
Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17633#discussion_r125376931
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveShim.scala ---
    @@ -589,18 +590,40 @@ private[client] class Shim_v0_13 extends Shim_v0_12 {
             col.getType.startsWith(serdeConstants.CHAR_TYPE_NAME))
           .map(col => col.getName).toSet
     
    -    filters.collect {
    -      case op @ BinaryComparison(a: Attribute, Literal(v, _: IntegralType)) =>
    -        s"${a.name} ${op.symbol} $v"
    -      case op @ BinaryComparison(Literal(v, _: IntegralType), a: Attribute) =>
    -        s"$v ${op.symbol} ${a.name}"
    -      case op @ BinaryComparison(a: Attribute, Literal(v, _: StringType))
    -          if !varcharKeys.contains(a.name) =>
    -        s"""${a.name} ${op.symbol} ${quoteStringLiteral(v.toString)}"""
    -      case op @ BinaryComparison(Literal(v, _: StringType), a: Attribute)
    -          if !varcharKeys.contains(a.name) =>
    -        s"""${quoteStringLiteral(v.toString)} ${op.symbol} ${a.name}"""
    -    }.mkString(" and ")
    +    def isExtractable(expr: Expression): Boolean =
    +      expr match {
    +        case Literal(_, _: IntegralType) | Literal(_, _: StringType) => true
    +        case _ => false
    +      }
    +
    +    def extractValue(expr: Expression): String =
    +      expr match {
    +        case Literal(v, _: IntegralType) => v.toString
    +        case Literal(v, _: StringType) => quoteStringLiteral(v.toString)
    +      }
    +
    +    lazy val convert: PartialFunction[Expression, String] =
    +      {
    +        case In(a: Attribute, exprs)
    +            if !varcharKeys.contains(a.name) && exprs.forall(isExtractable) =>
    +          val or =
    +            exprs
    +              .map(expr => s"${a.name} = ${extractValue(expr)}")
    +              .reduce(_ + " or " + _)
    +          "(" + or + ")"
    +        case op @ BinaryComparison(a: Attribute, expr2)
    --- End diff --
    
    +1 So we can avoid duplicate cases when adding new types.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message