Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19878#discussion_r154845901
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/hash.scala
 ---
    @@ -730,23 +776,29 @@ case class HiveHash(children: Seq[Expression]) 
extends HashExpression[Int] {
           input: String,
           result: String,
           fields: Array[StructField]): String = {
    -    val localResult = ctx.freshName("localResult")
         val childResult = ctx.freshName("childResult")
    -    fields.zipWithIndex.map { case (field, index) =>
    +    val fieldsHash = fields.zipWithIndex.map { case (field, index) =>
    +      val computeFieldHash = nullSafeElementHash(
    +        input, index.toString, field.nullable, field.dataType, 
childResult, ctx)
           s"""
    -         $childResult = 0;
    -         ${nullSafeElementHash(input, index.toString, field.nullable, 
field.dataType,
    -           childResult, ctx)}
    -         $localResult = (31 * $localResult) + $childResult;
    -       """
    -    }.mkString(
    -      s"""
    -         int $localResult = 0;
    -         int $childResult = 0;
    -       """,
    -      "",
    -      s"$result = (31 * $result) + $localResult;"
    -    )
    +         |$childResult = 0;
    +         |$computeFieldHash
    +         |$result = (31 * $result) + $childResult;
    +       """.stripMargin
    +    }
    +
    +    s"${ctx.JAVA_INT} $childResult = 0;\n" + ctx.splitExpressions(
    --- End diff --
    
    Yea, the input here is a row that may be produced by `row.getStruct` 
instead of `ctx.INPUT_ROW`, so we don't need this check as the input won't be 
`ctx.currentVars`.


---

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

Reply via email to