danny0405 commented on code in PR #14351:
URL: https://github.com/apache/hudi/pull/14351#discussion_r2563693181


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/cdc/InternalRowToJsonStringConverter.scala:
##########
@@ -36,15 +37,63 @@ class InternalRowToJsonStringConverter(schema: StructType) {
   }
 
   def convert(record: InternalRow): UTF8String = {
-    val map = scala.collection.mutable.Map.empty[String, Any]
+    // Use LinkedHashMap to preserve field order
+    val map = scala.collection.mutable.LinkedHashMap.empty[String, Any]
     schema.zipWithIndex.foreach {
       case (field, idx) =>
-        if (field.dataType.isInstanceOf[StringType]) {
-          map(field.name) = 
Option(record.getUTF8String(idx)).map(_.toString).orNull
-        } else {
-          map(field.name) = record.get(idx, field.dataType)
-        }
+        map(field.name) = convertField(record.get(idx, field.dataType), 
field.dataType)
     }
     UTF8String.fromString(mapper.writeValueAsString(map))
   }
+
+  private def convertField(value: Any, dataType: DataType): Any = {
+    if (value == null) {
+      null
+    } else {
+      dataType match {
+        case StringType => value.toString

Review Comment:
   do we already have a test to cover the cdc generation of string fields?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to