Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,18 @@ case object StringType extends NativeType with PrimitiveType {
def simpleString: String = "string"
}

case object BinaryType extends DataType with PrimitiveType {
case object BinaryType extends NativeType with PrimitiveType {
private[sql] type JvmType = Array[Byte]
@transient private[sql] lazy val tag = ScalaReflectionLock.synchronized { typeTag[JvmType] }
private[sql] val ordering = new Ordering[JvmType] {
def compare(x: Array[Byte], y: Array[Byte]): Int = {
for (i <- 0 until x.length; if i < y.length) {
val res = x(i).compareTo(y(i))
if (res != 0) return res
}
return x.length - y.length
}
}
def simpleString: String = "binary"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
sql("SELECT * FROM testData2 ORDER BY a DESC, b ASC"),
Seq((3,1), (3,2), (2,1), (2,2), (1,1), (1,2)))

checkAnswer(
sql("SELECT b FROM binaryData ORDER BY a ASC"),
(1 to 5).map(Row(_)).toSeq)

checkAnswer(
sql("SELECT b FROM binaryData ORDER BY a DESC"),
(1 to 5).map(Row(_)).toSeq.reverse)

checkAnswer(
sql("SELECT * FROM arrayData ORDER BY data[0] ASC"),
arrayData.collect().sortBy(_.data(0)).toSeq)
Expand Down
10 changes: 10 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ object TestData {
TestData2(3, 2) :: Nil)
testData2.registerTempTable("testData2")

case class BinaryData(a: Array[Byte], b: Int)
val binaryData: SchemaRDD =
TestSQLContext.sparkContext.parallelize(
BinaryData("12".getBytes(), 1) ::
BinaryData("22".getBytes(), 5) ::
BinaryData("122".getBytes(), 3) ::
BinaryData("121".getBytes(), 2) ::
BinaryData("123".getBytes(), 4) :: Nil)
binaryData.registerTempTable("binaryData")

// TODO: There is no way to express null primitives as case classes currently...
val testData3 =
logical.LocalRelation('a.int, 'b.int).loadData(
Expand Down