This is an automated email from the ASF dual-hosted git repository.
yumwang pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 6dc7457 [SPARK-32624][SQL] Use getCanonicalName to fix byte[] compile
issue
6dc7457 is described below
commit 6dc7457620130a7aa03b14303d1475a64348e399
Author: Yuming Wang <[email protected]>
AuthorDate: Wed Aug 19 05:20:26 2020 -0700
[SPARK-32624][SQL] Use getCanonicalName to fix byte[] compile issue
### What changes were proposed in this pull request?
```scala
scala> Array[Byte](1, 2).getClass.getName
res13: String = [B
scala> Array[Byte](1, 2).getClass.getCanonicalName
res14: String = byte[]
```
This pr replace `getClass.getName` with `getClass.getCanonicalName` in
`CodegenContext.addReferenceObj` to fix `byte[]` compile issue:
```
...
/* 030 */ value_1 =
org.apache.spark.sql.catalyst.util.TypeUtils.compareBinary(value_2, (([B)
references[0] /* min */)) >= 0 &&
org.apache.spark.sql.catalyst.util.TypeUtils.compareBinary(value_2, (([B)
references[1] /* max */)) <= 0;
/* 031 */ }
/* 032 */ return !isNull_1 && value_1;
/* 033 */ }
/* 034 */
/* 035 */
/* 036 */ }
20:49:54.886 WARN org.apache.spark.sql.catalyst.expressions.Predicate: Expr
codegen error and falling back to interpreter mode
java.util.concurrent.ExecutionException:
org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 30,
Column 81: failed to compile: org.codehaus.commons.compiler.CompileException:
File 'generated.java', Line 30, Column 81: Unexpected token "[" in primary
...
```
### Why are the changes needed?
Fix compile issue when compiling generated code.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Unit test.
Closes #29439 from wangyum/SPARK-32624.
Authored-by: Yuming Wang <[email protected]>
Signed-off-by: Yuming Wang <[email protected]>
(cherry picked from commit 409fea30cc40ce24a17325ec63d2f847ce49f5a6)
Signed-off-by: Yuming Wang <[email protected]>
---
.../spark/sql/catalyst/expressions/codegen/CodeGenerator.scala | 2 +-
.../spark/sql/catalyst/expressions/CodeGenerationSuite.scala | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
index 58c95c9..c8aa83e 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
@@ -133,7 +133,7 @@ class CodegenContext extends Logging {
def addReferenceObj(objName: String, obj: Any, className: String = null):
String = {
val idx = references.length
references += obj
- val clsName = Option(className).getOrElse(obj.getClass.getName)
+ val clsName = Option(className).getOrElse(obj.getClass.getCanonicalName)
s"(($clsName) references[$idx] /* $objName */)"
}
diff --git
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
index db52229..09cc01d 100644
---
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
+++
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
@@ -536,6 +536,13 @@ class CodeGenerationSuite extends SparkFunSuite with
ExpressionEvalHelper {
GenerateUnsafeProjection.generate(exprs, true)
GenerateMutableProjection.generate(exprs, true)
}
+
+ test("SPARK-32624: Use getCanonicalName to fix byte[] compile issue") {
+ val ctx = new CodegenContext
+ val bytes = new Array[Byte](3)
+ val byteObj = ctx.addReferenceObj("bytes", bytes)
+ assert(byteObj == "((byte[]) references[0] /* bytes */)")
+ }
}
case class HugeCodeIntExpression(value: Int) extends Expression {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]