-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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-20289][SQL] Use StaticInvoke to box primitive types #17604
Conversation
@@ -204,37 +204,37 @@ object ScalaReflection extends ScalaReflection { | |||
case t if t <:< localTypeOf[java.lang.Integer] => | |||
val boxedType = classOf[java.lang.Integer] | |||
val objectType = ObjectType(boxedType) | |||
NewInstance(boxedType, getPath :: Nil, objectType) | |||
StaticInvoke(boxedType, objectType, "valueOf", getPath :: Nil, propagateNull = true) |
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.
propagateNull
is true by default, maybe omit it?
LGTM |
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.
+1 for using valueOf
. Maybe you already know this but didn't see it in the JIRA, but, the JVM caches instances of small numbers so this method is actually more efficient in common cases.
NewInstance(c, getPath :: Nil, ObjectType(c)) | ||
case c if c == classOf[java.lang.Boolean] => | ||
NewInstance(c, getPath :: Nil, ObjectType(c)) | ||
case c if c == classOf[java.lang.Short] || |
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.
Is this simpler as
case c: java.lang.Short | java.lang.Integer | java.lang.Long | ... =>
I believe it's the same thing but don't know if it is implemented in a meaningfully different way. Seems like it ought to be no worse at runtime but I don't know.
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.
c
is a Class[_]
...
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.
Ugh right ignore that. Not thinking straight.
Test build #75698 has finished for PR 17604 at commit
|
Merging in master. |
## What changes were proposed in this pull request? Dataset typed API currently uses NewInstance to box primitive types (i.e. calling the constructor). Instead, it'd be slightly more idiomatic in Java to use PrimitiveType.valueOf, which can be invoked using StaticInvoke expression. ## How was this patch tested? The change should be covered by existing tests for Dataset encoders. Author: Reynold Xin <[email protected]> Closes apache#17604 from rxin/SPARK-20289.
What changes were proposed in this pull request?
Dataset typed API currently uses NewInstance to box primitive types (i.e. calling the constructor). Instead, it'd be slightly more idiomatic in Java to use PrimitiveType.valueOf, which can be invoked using StaticInvoke expression.
How was this patch tested?
The change should be covered by existing tests for Dataset encoders.