You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2020/10/16 10:51:31 UTC

[GitHub] [hudi] lw309637554 commented on a change in pull request #2177: [HUDI-307] add test to check data type write and read consistent

lw309637554 commented on a change in pull request #2177:
URL: https://github.com/apache/hudi/pull/2177#discussion_r506287585



##########
File path: hudi-spark/src/test/scala/org/apache/hudi/functional/TestCOWDataSource.scala
##########
@@ -194,4 +199,31 @@ class TestCOWDataSource extends HoodieClientTestBase {
       .load(basePath)
     assertEquals(hoodieIncViewDF2.count(), insert2NewKeyCnt)
   }
+
+  @Test def testComplexDataTypeWriteAndReadConsistency(): Unit = {
+    val records = Seq(ComplexDataTypeRecord("11", "Andy", Timestamp.valueOf("1970-01-01 13:31:24"), Date.valueOf("1991-11-07"), BigDecimal.valueOf(1.0), 11, 1),
+      ComplexDataTypeRecord("22", "lisi", Timestamp.valueOf("1970-01-02 13:31:24"), Date.valueOf("1991-11-08"), BigDecimal.valueOf(2.0), 11, 1),
+      ComplexDataTypeRecord("33", "zhangsan", Timestamp.valueOf("1970-01-03 13:31:24"), Date.valueOf("1991-11-09"), BigDecimal.valueOf(3.0), 11, 1))
+
+    val rdd = jsc.parallelize(records)
+    val  recordsDF = spark.createDataFrame(rdd)
+    recordsDF.write.format("org.apache.hudi")
+      .options(commonOpts)
+      .mode(SaveMode.Append)
+      .save(basePath)
+
+    val recordsReadDF = spark.read.format("org.apache.hudi")
+      .load(basePath + "/*/*")
+    recordsReadDF.schema.foreach(f => {
+      f.name match {
+        case "timeStampValue" =>
+          assertEquals(f.dataType, org.apache.spark.sql.types.TimestampType)
+        case "dateValue" =>
+          assertEquals(f.dataType, org.apache.spark.sql.types.DateType)
+        case "bigDecimalValue" =>
+          assertEquals(f.dataType, org.apache.spark.sql.types.DecimalType(38, 18))

Review comment:
       yes,  spark will transform java  bigdecimal to SYSTEM_DEFAULT  decimal(38,18)




----------------------------------------------------------------
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.

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