ahshahid commented on code in PR #48252:
URL: https://github.com/apache/spark/pull/48252#discussion_r1844722897


##########
sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala:
##########
@@ -2802,6 +2821,79 @@ class DatasetSuite extends QueryTest
       }
     }
   }
+
+  test("SPARK-49789 Bean class encoding with generic type implementing 
Serializable") {
+    // just create encoder
+    val enc = Encoders.bean(classOf[MessageWrapper[_]])
+    val data = Seq("test1", "test2").map(str => {
+      val msg = new MessageWrapper[String]()
+      msg.setMessage(str)
+      msg
+    })
+    validateParamBeanDataset(classOf[MessageWrapper[String]],
+      data, mutable.Buffer(data: _*),
+      StructType(Seq(StructField("message", BinaryType, true)))
+    )
+  }
+
+  test("SPARK-49789 Bean class encoding with  generic type indirectly 
extending" +
+    " Serializable class") {
+    // just create encoder
+    Encoders.bean(classOf[BigDecimalMessageWrapper[_]])
+    val data = Seq(2d, 8d).map(doub => {
+      val bean = new BigDecimalMessageWrapper[DerivedBigDecimalExtender]()
+      bean.setMessage(new DerivedBigDecimalExtender(doub))
+      bean
+    })
+    validateParamBeanDataset(
+      classOf[BigDecimalMessageWrapper[DerivedBigDecimalExtender]],
+      data, mutable.Buffer(data: _*),
+      StructType(Seq(StructField("message", BinaryType, true))))
+  }
+
+  test("SPARK-49789. test bean class with  generictype bound of UDTType") {
+    // just create encoder
+    UDTRegistration.register(classOf[TestUDT].getName, 
classOf[TestUDTType].getName)
+    val enc = Encoders.bean(classOf[UDTBean[_]])
+    val baseData = Seq((1, "a"), (2, "b"))
+    val data = baseData.map(tup => {
+      val bean = new UDTBean[TestUDT]()
+      bean.setMessage(new TestUDTImplSub(tup._1, tup._2))
+      bean
+    })
+    val expectedData = baseData.map(tup => {
+      val bean = new UDTBean[TestUDT]()
+      bean.setMessage(new TestUDTImpl(tup._1, tup._2))
+      bean
+    })
+    validateParamBeanDataset(
+      classOf[UDTBean[TestUDT]],
+      data, mutable.Buffer(expectedData: _*),
+      StructType(Seq(StructField("message", new TestUDTType(), true))))
+  }
+
+  private def validateParamBeanDataset[T](
+                                           classToEncode: Class[T],
+                                           data: Seq[T],
+                                           expectedData: mutable.Buffer[T],
+                                           expectedSchema: StructType): Unit = 
{
+

Review Comment:
   thanks. will do that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to