Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/10974#discussion_r51295244
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala
---
@@ -325,36 +325,62 @@ case class Murmur3Hash(children: Seq[Expression],
seed: Int) extends Expression
override def genCode(ctx: CodegenContext, ev: ExprCode): String = {
ev.isNull = "false"
- val childrenHash = children.zipWithIndex.map {
- case (child, dt) =>
- val childGen = child.gen(ctx)
- val childHash = computeHash(childGen.value, child.dataType,
ev.value, ctx)
- s"""
- ${childGen.code}
- if (!${childGen.isNull}) {
- ${childHash.code}
- ${ev.value} = ${childHash.value};
- }
- """
+ val childrenHash = children.map { child =>
+ val childGen = child.gen(ctx)
+ childGen.code + generateNullCheck(child.nullable, childGen.isNull) {
+ computeHash(childGen.value, child.dataType, ev.value, ctx)
+ }
}.mkString("\n")
+
s"""
int ${ev.value} = $seed;
$childrenHash
"""
}
+ private def generateNullCheck(nullable: Boolean, isNull:
String)(execution: String): String = {
--- End diff --
I think so, we can promote it to `CodeGenContext` and use it in other
places in a follow-up PR.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]