You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by marmbrus <gi...@git.apache.org> on 2015/09/04 01:11:24 UTC

[GitHub] spark pull request: [SPARK-7160][SQL] Support converting DataFrame...

Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5713#discussion_r38707296
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/CatalystTypeConvertersSuite.scala ---
    @@ -59,4 +63,199 @@ class CatalystTypeConvertersSuite extends SparkFunSuite {
       test("option handling in createToCatalystConverter") {
         assert(CatalystTypeConverters.createToCatalystConverter(IntegerType)(Some(123)) === 123)
       }
    +
    +  import ScalaReflection._
    +
    +  test("createToProductConverter[T] with a case class") {
    +    val a = A(1)
    +    assert(a === rebuildWithProductConverter(a))
    +  }
    +
    +  test("createToProductConverter[T] with a case class and null value") {
    +    val a = A(null.asInstanceOf[Int])
    +    assert(a === rebuildWithProductConverter(a))
    +  }
    +
    +  test("createToProductConverter[T] with a case class dependent on another case class") {
    +    val b = B(A(1), 2.0)
    +    assert(b === rebuildWithProductConverter(b))
    +  }
    +
    +  test("createToProductConverter[T] with a case class dep. on case class dep. on case class") {
    +    val c = C(B(A(1), 2.0), "hi everybody")
    +    assert(c === rebuildWithProductConverter(c))
    +  }
    +
    +  test("createToProductConverter[T] with T having Seqs") {
    +    val d = D(B(A(1), 2.0), Seq(A(1), A(5)), Seq(3, 8), 10L)
    +    assert(d === rebuildWithProductConverter(d))
    +  }
    +
    +  test("createToProductConverter[T] with T having Maps") {
    +    val e = E(B(A(1), 2.0),
    +      Map(A(1) -> A(5), A(11) -> A(15)),
    +      Map(A(1) -> 5, A(11) -> 15),
    +      Map(1 -> A(5), 11 -> A(15)),
    +      Map(1 -> 5, 11 -> 15))
    +    assert(e === rebuildWithProductConverter(e))
    +  }
    +
    +  test("createToProductConverter[T] with T having multiple constructors") {
    +    val f = new F(1)
    +    assert(F(1, "hi everybody") === rebuildWithProductConverter(f))
    +  }
    +
    +  test("createToProductConverter[T] with T having String") {
    +    val g = new G("hi everybody!")
    +    assert(g === rebuildWithProductConverter(g))
    +  }
    +
    +  test("createToProductConverter[T] with an incompatible case class fails at conversion") {
    +    intercept[ClassCastException] {
    +      val a = A(1)
    +      val dataType = schemaFor[A].dataType
    +      val row = CatalystTypeConverters.createToCatalystConverter(dataType)(a)
    +      val converter =
    +        CatalystTypeConverters.createToProductConverter[G](dataType.asInstanceOf[StructType])
    +      converter(row.asInstanceOf[InternalRow])
    +    }
    --- End diff --
    
    This is also a kind of a nit, but could you limit the scope of the `intercept`.  I think this is right, but with the extra casts I'm worried the wrong thing might be throwing `ClassCastException`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org