spark git commit: [SPARK-5675][SQL] XyzType companion object should subclass XyzType

2015-02-09 Thread rxin
Repository: spark
Updated Branches:
  refs/heads/master 0765af9b2 - f48199eb3


[SPARK-5675][SQL] XyzType companion object should subclass XyzType

Otherwise, the following will always return false in Java.

```scala
dataType instanceof StringType
```

Author: Reynold Xin r...@databricks.com

Closes #4463 from rxin/type-companion-object and squashes the following commits:

04d5d8d [Reynold Xin] Comment.
976e11e [Reynold Xin] [SPARK-5675][SQL]StringType case object should be 
subclass of StringType class


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/f48199eb
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/f48199eb
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/f48199eb

Branch: refs/heads/master
Commit: f48199eb354d6ec8675c2c1f96c3005064058d66
Parents: 0765af9
Author: Reynold Xin r...@databricks.com
Authored: Mon Feb 9 14:51:46 2015 -0800
Committer: Reynold Xin r...@databricks.com
Committed: Mon Feb 9 14:51:46 2015 -0800

--
 .../org/apache/spark/sql/types/dataTypes.scala  | 85 +---
 1 file changed, 73 insertions(+), 12 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/spark/blob/f48199eb/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala
--
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala
index 91efe32..2abb1ca 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala
@@ -240,10 +240,16 @@ abstract class DataType {
  * @group dataType
  */
 @DeveloperApi
-case object NullType extends DataType {
+class NullType private() extends DataType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type NullType$ 
in byte code.
+  // Defined with a private constructor so the companion object is the only 
possible instantiation.
   override def defaultSize: Int = 1
 }
 
+case object NullType extends NullType
+
+
 protected[sql] object NativeType {
   val all = Seq(
 IntegerType, BooleanType, LongType, DoubleType, FloatType, ShortType, 
ByteType, StringType)
@@ -292,7 +298,10 @@ protected[sql] abstract class NativeType extends DataType {
  * @group dataType
  */
 @DeveloperApi
-case object StringType extends NativeType with PrimitiveType {
+class StringType private() extends NativeType with PrimitiveType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type StringType$ 
in byte code.
+  // Defined with a private constructor so the companion object is the only 
possible instantiation.
   private[sql] type JvmType = String
   @transient private[sql] lazy val tag = ScalaReflectionLock.synchronized { 
typeTag[JvmType] }
   private[sql] val ordering = implicitly[Ordering[JvmType]]
@@ -303,6 +312,8 @@ case object StringType extends NativeType with 
PrimitiveType {
   override def defaultSize: Int = 4096
 }
 
+case object StringType extends StringType
+
 
 /**
  * :: DeveloperApi ::
@@ -313,7 +324,10 @@ case object StringType extends NativeType with 
PrimitiveType {
  * @group dataType
  */
 @DeveloperApi
-case object BinaryType extends NativeType with PrimitiveType {
+class BinaryType private() extends NativeType with PrimitiveType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type BinaryType$ 
in byte code.
+  // Defined with a private constructor so the companion object is the only 
possible instantiation.
   private[sql] type JvmType = Array[Byte]
   @transient private[sql] lazy val tag = ScalaReflectionLock.synchronized { 
typeTag[JvmType] }
   private[sql] val ordering = new Ordering[JvmType] {
@@ -332,6 +346,8 @@ case object BinaryType extends NativeType with 
PrimitiveType {
   override def defaultSize: Int = 4096
 }
 
+case object BinaryType extends BinaryType
+
 
 /**
  * :: DeveloperApi ::
@@ -341,7 +357,10 @@ case object BinaryType extends NativeType with 
PrimitiveType {
  *@group dataType
  */
 @DeveloperApi
-case object BooleanType extends NativeType with PrimitiveType {
+class BooleanType private() extends NativeType with PrimitiveType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type 
BooleanType$ in byte code.
+  // Defined with a private constructor so the companion object is the only 
possible instantiation.
   private[sql] 

spark git commit: [SPARK-5675][SQL] XyzType companion object should subclass XyzType

2015-02-09 Thread rxin
Repository: spark
Updated Branches:
  refs/heads/branch-1.3 18c5a999b - 1e2fab22b


[SPARK-5675][SQL] XyzType companion object should subclass XyzType

Otherwise, the following will always return false in Java.

```scala
dataType instanceof StringType
```

Author: Reynold Xin r...@databricks.com

Closes #4463 from rxin/type-companion-object and squashes the following commits:

04d5d8d [Reynold Xin] Comment.
976e11e [Reynold Xin] [SPARK-5675][SQL]StringType case object should be 
subclass of StringType class

(cherry picked from commit f48199eb354d6ec8675c2c1f96c3005064058d66)
Signed-off-by: Reynold Xin r...@databricks.com


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/1e2fab22
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/1e2fab22
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/1e2fab22

Branch: refs/heads/branch-1.3
Commit: 1e2fab22b81021c6fd84c13207ceeb5137b1b317
Parents: 18c5a99
Author: Reynold Xin r...@databricks.com
Authored: Mon Feb 9 14:51:46 2015 -0800
Committer: Reynold Xin r...@databricks.com
Committed: Mon Feb 9 14:52:00 2015 -0800

--
 .../org/apache/spark/sql/types/dataTypes.scala  | 85 +---
 1 file changed, 73 insertions(+), 12 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/spark/blob/1e2fab22/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala
--
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala
index 91efe32..2abb1ca 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/dataTypes.scala
@@ -240,10 +240,16 @@ abstract class DataType {
  * @group dataType
  */
 @DeveloperApi
-case object NullType extends DataType {
+class NullType private() extends DataType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type NullType$ 
in byte code.
+  // Defined with a private constructor so the companion object is the only 
possible instantiation.
   override def defaultSize: Int = 1
 }
 
+case object NullType extends NullType
+
+
 protected[sql] object NativeType {
   val all = Seq(
 IntegerType, BooleanType, LongType, DoubleType, FloatType, ShortType, 
ByteType, StringType)
@@ -292,7 +298,10 @@ protected[sql] abstract class NativeType extends DataType {
  * @group dataType
  */
 @DeveloperApi
-case object StringType extends NativeType with PrimitiveType {
+class StringType private() extends NativeType with PrimitiveType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type StringType$ 
in byte code.
+  // Defined with a private constructor so the companion object is the only 
possible instantiation.
   private[sql] type JvmType = String
   @transient private[sql] lazy val tag = ScalaReflectionLock.synchronized { 
typeTag[JvmType] }
   private[sql] val ordering = implicitly[Ordering[JvmType]]
@@ -303,6 +312,8 @@ case object StringType extends NativeType with 
PrimitiveType {
   override def defaultSize: Int = 4096
 }
 
+case object StringType extends StringType
+
 
 /**
  * :: DeveloperApi ::
@@ -313,7 +324,10 @@ case object StringType extends NativeType with 
PrimitiveType {
  * @group dataType
  */
 @DeveloperApi
-case object BinaryType extends NativeType with PrimitiveType {
+class BinaryType private() extends NativeType with PrimitiveType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type BinaryType$ 
in byte code.
+  // Defined with a private constructor so the companion object is the only 
possible instantiation.
   private[sql] type JvmType = Array[Byte]
   @transient private[sql] lazy val tag = ScalaReflectionLock.synchronized { 
typeTag[JvmType] }
   private[sql] val ordering = new Ordering[JvmType] {
@@ -332,6 +346,8 @@ case object BinaryType extends NativeType with 
PrimitiveType {
   override def defaultSize: Int = 4096
 }
 
+case object BinaryType extends BinaryType
+
 
 /**
  * :: DeveloperApi ::
@@ -341,7 +357,10 @@ case object BinaryType extends NativeType with 
PrimitiveType {
  *@group dataType
  */
 @DeveloperApi
-case object BooleanType extends NativeType with PrimitiveType {
+class BooleanType private() extends NativeType with PrimitiveType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type 
BooleanType$ in byte