New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-7527][Core]Fix createNullValue to return the correct null values and REPL mode detection #6735
Conversation
Test build #34557 has finished for PR 6735 at commit
|
retest this please |
Test build #34564 has finished for PR 6735 at commit
|
@@ -109,7 +109,16 @@ private[spark] object ClosureCleaner extends Logging { | |||
|
|||
private def createNullValue(cls: Class[_]): AnyRef = { | |||
if (cls.isPrimitive) { | |||
new java.lang.Byte(0: Byte) // Should be convertible to any primitive type | |||
if (cls == java.lang.Boolean.TYPE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use match
syntax here?
I see why boolean
needs a special case, but a byte
widens to a char
in Java so I don't think that's necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following code will fail:
case class X(x: Char)
object Foo1 extends App {
val c = classOf[X]
val x = c.getConstructors()(0)
println(x)
println(x.newInstance(new java.lang.Byte(0: Byte)))
}
I don't know why char
is also a special case.
Interesting, I'd love to hear that this is the fix. The current failure is:
|
It's because
Before this fix, I'm looking for a fix for this |
The issue is that if a closure is cleaned twice, when cleaning the closure at the second time, the Because the compiler always checks the first parameter in the constructor, so Since the code for |
Heh, well it's supposed to be used when in the I don't know the history of this bit of code. I am not sure about the assumption in the comments that the constructor has no effects -- did it mean a case class? It sort of looks like an optimization, to try to call the constructor directly via reflection. Well... I think it wouldn't hurt to try removing it as you say and see what happens? |
Test build #34595 has finished for PR 6735 at commit
|
Test build #34594 has finished for PR 6735 at commit
|
case java.lang.Boolean.TYPE => new java.lang.Boolean(false) | ||
case java.lang.Character.TYPE => new java.lang.Character('\0') | ||
case java.lang.Void.TYPE => | ||
// This should not happen because `Foo(void x) {}` cannot be compiled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: cannot be compiled -> does not compile
LGTM. All of my comments are documentation related. I will fix these on merge myself. This is going into master. |
@@ -1804,15 +1804,10 @@ private[spark] object Utils extends Logging { | |||
|
|||
lazy val isInInterpreter: Boolean = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just delete this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this for now. I remember there's some discussion saying that this should be abstracted to a shared method so it can be used elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact #6734 uses it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, now I remember that. Now the logic is correct, hopefully.
…lues and REPL mode detection The root cause of SPARK-7527 is `createNullValue` returns an incompatible value `Byte(0)` for `char` and `boolean`. This PR fixes it and corrects the class name of the main class, and also adds an unit test to demonstrate it. Author: zsxwing <zsxwing@gmail.com> Closes apache#6735 from zsxwing/SPARK-7527 and squashes the following commits: bbdb271 [zsxwing] Use pattern match in createNullValue b0a0e7e [zsxwing] Remove the noisy in the test output 903e269 [zsxwing] Remove the code for Utils.isInInterpreter == false 5f92dc1 [zsxwing] Fix createNullValue to return the correct null values and REPL mode detection
…lues and REPL mode detection The root cause of SPARK-7527 is `createNullValue` returns an incompatible value `Byte(0)` for `char` and `boolean`. This PR fixes it and corrects the class name of the main class, and also adds an unit test to demonstrate it. Author: zsxwing <zsxwing@gmail.com> Closes #6735 from zsxwing/SPARK-7527 and squashes the following commits: bbdb271 [zsxwing] Use pattern match in createNullValue b0a0e7e [zsxwing] Remove the noisy in the test output 903e269 [zsxwing] Remove the code for Utils.isInInterpreter == false 5f92dc1 [zsxwing] Fix createNullValue to return the correct null values and REPL mode detection
The root cause of SPARK-7527 is
createNullValue
returns an incompatible valueByte(0)
forchar
andboolean
.This PR fixes it and corrects the class name of the main class, and also adds an unit test to demonstrate it.