Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14259#discussion_r71496316
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
---
@@ -166,11 +185,11 @@ case class Invoke(
} else {
""
}
-
val code = s"""
${obj.code}
${argGen.map(_.code).mkString("\n")}
$setIsNull
+ $callFunc
--- End diff --
I'm thinking of something like
```
val returnPrimitive = method.isDefined &&
method.get.getReturnType.isPrimitive
val needTryCatch = method.isDefined && method.get.getExceptionTypes.nonEmpty
def getFuncResult(resultVal: String, funcCall: String): String = if
(needTryCatch) {
"""
try {
$resultVal = $funcCall;
} catch (Exception e) {
org.apache.spark.unsafe.Platform.throwException(e);
}
"""
} else {
s"$resultVal = $funcCall;"
}
val evaluate = if (returnPrimitive) {
getFuncResult(ev.value, s"${obj.value}.$functionName($argString)")
} else {
val funcResult = ctx.freshName("funcResult")
s"""
Object $funcResult = null;
$getFuncResult(funcResult, s"${obj.value}.$functionName($argString)")
if ($funcResult == null) {
${ev.isNull} = true;
} else {
${ev.value} = (${ctx.boxedType(javaType)}) $funcResult;
}
"""
}
val code = s"""
...
$javaType ${ev.value} = ${ctx.defaultValue(dataType)};
$evaluete
...
"""
```
---
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]