panbingkun commented on code in PR #48509:
URL: https://github.com/apache/spark/pull/48509#discussion_r1804043853
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala:
##########
@@ -322,21 +322,22 @@ case class StaticInvoke(
val evaluate = if (returnNullable && !method.getReturnType.isPrimitive) {
if (CodeGenerator.defaultValue(dataType) == "null") {
s"""
- ${ev.value} = $callFunc;
+ ${ev.value} = ($javaType) $callFunc;
Review Comment:
- Because some methods called by `StaticInvoke` may return a `Any`(or
`Object`) value, eg:
https://github.com/apache/spark/blob/070f2bdfb968c8080de1c6614c1def978df823d4/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/json/JsonExpressionEvalUtils.scala#L103-L112
- Based on the `dataType`, obtain the `Java type` and then `cast`.
- I think this pattern can greatly simplify the methods called by
`StaticInvoke` (without writing `multiple` methods)
- Otherwise, the compilation will fail, as follows:
<img width="1234" alt="image"
src="https://github.com/user-attachments/assets/8d42a3ca-b9f4-46a0-954a-d87957806d54">
```java
/* 049 */ boolean project_isNull_0 = project_resultIsNull_0;
/* 050 */ InternalRow project_value_0 = null;
/* 051 */ if (!project_resultIsNull_0) {
/* 052 */ project_value_0 =
org.apache.spark.sql.catalyst.expressions.json.JsonExpressionEvalUtils.fromJson(project_mutableStateArray_0[0],
project_mutableStateArray_1[0]);
/* 053 */ project_isNull_0 = project_value_0 == null;
/* 054 */
/* 055 */ }
```
```shell
11:15:52.920 ERROR
org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator: Failed to
compile the generated Java code.
org.codehaus.commons.compiler.CompileException: File 'generated.java', Line
52, Column 1: Assignment conversion not possible from type "java.lang.Object"
to type "org.apache.spark.sql.catalyst.InternalRow"
at
org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:13014)
at
org.codehaus.janino.UnitCompiler.assignmentConversion(UnitCompiler.java:11263)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:4099)
at org.codehaus.janino.UnitCompiler.access$6300(UnitCompiler.java:236)
at
org.codehaus.janino.UnitCompiler$13.visitAssignment(UnitCompiler.java:4057)
at
org.codehaus.janino.UnitCompiler$13.visitAssignment(UnitCompiler.java:4040)
at org.codehaus.janino.Java$Assignment.accept(Java.java:4864)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]