Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

rxin
Copy link
Contributor

@rxin rxin commented Apr 11, 2017

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.

@@ -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)
Copy link
Contributor

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?

@cloud-fan
Copy link
Contributor

LGTM

Copy link
Member

@srowen srowen left a 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] ||
Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c is a Class[_]...

Copy link
Member

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.

@SparkQA
Copy link

SparkQA commented Apr 11, 2017

Test build #75698 has finished for PR 17604 at commit 8cbc617.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rxin
Copy link
Contributor Author

rxin commented Apr 11, 2017

Merging in master.

@asfgit asfgit closed this in 123b4fb Apr 11, 2017
peter-toth pushed a commit to peter-toth/spark that referenced this pull request Oct 6, 2018
## 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 <rxin@databricks.com>

Closes apache#17604 from rxin/SPARK-20289.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants