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

    https://github.com/apache/spark/pull/5713#discussion_r40514499
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/CatalystTypeConvertersSuite.scala
 ---
    @@ -61,4 +65,202 @@ 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") {
    +    val a = A(1)
    +    val dataType = schemaFor[A].dataType
    +    val row = CatalystTypeConverters.createToCatalystConverter(dataType)(a)
    +    val converter =
    +      
CatalystTypeConverters.createToProductConverter[G](dataType.asInstanceOf[StructType])
    +    intercept[ClassCastException] { 
converter(row.asInstanceOf[InternalRow]) }
    +  }
    +
    +  test("createToProductConverter[T] with T having Some[U]") {
    +    val h = H(Some(1))
    +    assert(h === rebuildWithProductConverter(h))
    +  }
    +
    +  test("createToProductConverter[T] with T having None") {
    +    val h = H(None)
    +    assert(h === rebuildWithProductConverter(h))
    +  }
    +
    +  test("createToProductConverter[T] with T having Option[Option[U]]") {
    +    val i = I(Some(H(Some(1))))
    +    assert(i === rebuildWithProductConverter(i))
    +  }
    +
    +  test("createToProductConverter[T] with T having Option[Seq[U]]") {
    +    val j = J(Some(Seq(A(1), A(2))))
    +    assert(j === rebuildWithProductConverter(j))
    +  }
    +
    +  test("createToProductConverter[T] with T having BigDecimal") {
    +    val k = K(BigDecimal("123.0"))
    +    assert(k === rebuildWithProductConverter(k))
    +  }
    +
    +  test("createToProductConverter[T] with T having java.math.BigDecimal") {
    +    // NOTE: As currently implemented, Decimal.apply(java.math.BigDecimal) 
triggers the implicit
    +    // BigDecimal.javaBigDecimal2bigDecimal, creating a Scala BigDecimal 
with
    +    // BigDecimal.defaultMathContext. So a given java.math.BigDecimal ends 
up taking maximum
    +    // precision, and the scale is truncated to Decimal.MAX_LONG_DIGITS 
when converting back. This
    +    // unit test accounts for that current behavior.
    +    val l = L(new java.math.BigDecimal(new java.math.BigInteger("123"), 
Decimal.MAX_LONG_DIGITS))
    +    assert(l === rebuildWithProductConverter(l))
    +  }
    +
    +  test("createToProductConverter[T] with T having java.sql.Date") {
    +    val m = M(DateTimeUtils.toJavaDate(daysSinceEpoch = 16000))
    +    assert(m === rebuildWithProductConverter(m))
    +  }
    +
    +  test("createToProductConverter[T] with T having java.sql.Timestamp") {
    +    val n = N(DateTimeUtils.toJavaTimestamp(System.currentTimeMillis * 
1000L))
    +    assert(n === rebuildWithProductConverter(n))
    +  }
    --- End diff --
    
    I didn't have a test for timestamps in the previous versions of this PR, so 
this is new.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to