Skip to content

Commit

Permalink
[SPARK-20289][SQL] Use StaticInvoke to box primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
rxin committed Apr 11, 2017
1 parent 379b0b0 commit 8cbc617
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,19 @@ object JavaTypeInference {
typeToken.getRawType match {
case c if !inferExternalType(c).isInstanceOf[ObjectType] => getPath

case c if c == classOf[java.lang.Short] =>
NewInstance(c, getPath :: Nil, ObjectType(c))
case c if c == classOf[java.lang.Integer] =>
NewInstance(c, getPath :: Nil, ObjectType(c))
case c if c == classOf[java.lang.Long] =>
NewInstance(c, getPath :: Nil, ObjectType(c))
case c if c == classOf[java.lang.Double] =>
NewInstance(c, getPath :: Nil, ObjectType(c))
case c if c == classOf[java.lang.Byte] =>
NewInstance(c, getPath :: Nil, ObjectType(c))
case c if c == classOf[java.lang.Float] =>
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] ||
c == classOf[java.lang.Integer] ||
c == classOf[java.lang.Long] ||
c == classOf[java.lang.Double] ||
c == classOf[java.lang.Float] ||
c == classOf[java.lang.Byte] ||
c == classOf[java.lang.Boolean] =>
StaticInvoke(
c,
ObjectType(c),
"valueOf",
getPath :: Nil,
propagateNull = true)

case c if c == classOf[java.sql.Date] =>
StaticInvoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

case t if t <:< localTypeOf[java.lang.Long] =>
val boxedType = classOf[java.lang.Long]
val objectType = ObjectType(boxedType)
NewInstance(boxedType, getPath :: Nil, objectType)
StaticInvoke(boxedType, objectType, "valueOf", getPath :: Nil, propagateNull = true)

case t if t <:< localTypeOf[java.lang.Double] =>
val boxedType = classOf[java.lang.Double]
val objectType = ObjectType(boxedType)
NewInstance(boxedType, getPath :: Nil, objectType)
StaticInvoke(boxedType, objectType, "valueOf", getPath :: Nil, propagateNull = true)

case t if t <:< localTypeOf[java.lang.Float] =>
val boxedType = classOf[java.lang.Float]
val objectType = ObjectType(boxedType)
NewInstance(boxedType, getPath :: Nil, objectType)
StaticInvoke(boxedType, objectType, "valueOf", getPath :: Nil, propagateNull = true)

case t if t <:< localTypeOf[java.lang.Short] =>
val boxedType = classOf[java.lang.Short]
val objectType = ObjectType(boxedType)
NewInstance(boxedType, getPath :: Nil, objectType)
StaticInvoke(boxedType, objectType, "valueOf", getPath :: Nil, propagateNull = true)

case t if t <:< localTypeOf[java.lang.Byte] =>
val boxedType = classOf[java.lang.Byte]
val objectType = ObjectType(boxedType)
NewInstance(boxedType, getPath :: Nil, objectType)
StaticInvoke(boxedType, objectType, "valueOf", getPath :: Nil, propagateNull = true)

case t if t <:< localTypeOf[java.lang.Boolean] =>
val boxedType = classOf[java.lang.Boolean]
val objectType = ObjectType(boxedType)
NewInstance(boxedType, getPath :: Nil, objectType)
StaticInvoke(boxedType, objectType, "valueOf", getPath :: Nil, propagateNull = true)

case t if t <:< localTypeOf[java.sql.Date] =>
StaticInvoke(
Expand Down

0 comments on commit 8cbc617

Please sign in to comment.