From 8def8b70361ce4db1c4b1993af70b61c869b955a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Lindman=20H=C3=B6rnlund?= Date: Wed, 23 Sep 2015 11:31:08 +0200 Subject: [PATCH] SPARKC-275: Make OptionConverter handle Nones as well as nulls --- CHANGES.txt | 1 + .../datastax/spark/connector/types/TypeConverter.scala | 3 ++- .../spark/connector/rdd/reader/CassandraRowTest.scala | 8 ++++++++ .../spark/connector/types/TypeConverterTest.scala | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index f26186bd0..7832faef2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,7 @@ * Fix merge strategy for netty.io.properties (SPARKC-249) * Upgrade integration tests to use Cassandra 2.1.9 and upgrade Java Driver to 2.1.7.1, Spark to 1.4.1 (SPARKC-248) + * Make OptionConverter handle Nones as well as nulls (SPARKC-275) 1.4.0 * Fixed broken integration tests (SPARKC-247): diff --git a/spark-cassandra-connector/src/main/scala/com/datastax/spark/connector/types/TypeConverter.scala b/spark-cassandra-connector/src/main/scala/com/datastax/spark/connector/types/TypeConverter.scala index 98b1b2cc7..01705307d 100644 --- a/spark-cassandra-connector/src/main/scala/com/datastax/spark/connector/types/TypeConverter.scala +++ b/spark-cassandra-connector/src/main/scala/com/datastax/spark/connector/types/TypeConverter.scala @@ -492,6 +492,7 @@ object TypeConverter { def convertPF = { case null => None + case None => None case other => Some(c.convert(other)) } } @@ -854,4 +855,4 @@ object TypeConverter { converters = c +: converters } } -} \ No newline at end of file +} diff --git a/spark-cassandra-connector/src/test/scala/com/datastax/spark/connector/rdd/reader/CassandraRowTest.scala b/spark-cassandra-connector/src/test/scala/com/datastax/spark/connector/rdd/reader/CassandraRowTest.scala index 3d5d10515..c951a8714 100644 --- a/spark-cassandra-connector/src/test/scala/com/datastax/spark/connector/rdd/reader/CassandraRowTest.scala +++ b/spark-cassandra-connector/src/test/scala/com/datastax/spark/connector/rdd/reader/CassandraRowTest.scala @@ -25,6 +25,14 @@ class CassandraRowTest extends FunSuite with ShouldMatchers { assertEquals(1, row.size) } + test("NoneAccessTest") { + val row = new CassandraRow(Array("value"), Array(None)) + assertEquals(None, row.getStringOption(0)) + assertEquals(None, row.getStringOption("value")) + assertEquals(1, row.size) + } + + test("nullToStringTest") { val row = new CassandraRow(Array("value"), Array(null)) assertEquals("CassandraRow{value: null}", row.toString()) diff --git a/spark-cassandra-connector/src/test/scala/com/datastax/spark/connector/types/TypeConverterTest.scala b/spark-cassandra-connector/src/test/scala/com/datastax/spark/connector/types/TypeConverterTest.scala index 13775f62e..a2f1baa63 100644 --- a/spark-cassandra-connector/src/test/scala/com/datastax/spark/connector/types/TypeConverterTest.scala +++ b/spark-cassandra-connector/src/test/scala/com/datastax/spark/connector/types/TypeConverterTest.scala @@ -192,6 +192,7 @@ class TypeConverterTest { def testOption() { val c = TypeConverter.forType[Option[String]] assertEquals(None, c.convert(null)) + assertEquals(None, c.convert(None)) assertEquals(Some("not-null"), c.convert("not-null")) }