vinlee19 commented on code in PR #267:
URL: 
https://github.com/apache/doris-flink-connector/pull/267#discussion_r1432586296


##########
flink-doris-connector/src/main/java/org/apache/doris/flink/deserialization/converter/DorisRowConverter.java:
##########
@@ -360,39 +360,52 @@ private static List<Object> convertArrayData(ArrayData 
array, LogicalType type)
 
     private static Object convertMapData(MapData map, LogicalType type) {
         Map<Object, Object> result = new HashMap<>();
+        LogicalType valueType = ((MapType) type).getValueType();
+        LogicalType keyType = ((MapType) type).getKeyType();
         if (map instanceof GenericMapData) {
             GenericMapData gMap = (GenericMapData) map;
             for (Object key : ((GenericArrayData) 
gMap.keyArray()).toObjectArray()) {
-                result.put(key, gMap.get(key));
+
+                Object convertedKey = convertMapEntry(key, keyType);
+                Object convertedValue = convertMapEntry(gMap.get(key), 
valueType);
+                result.put(convertedKey, convertedValue);
             }
             return result;
-        }
-        if (map instanceof BinaryMapData) {
+        } else if (map instanceof BinaryMapData) {
             BinaryMapData bMap = (BinaryMapData) map;
-            LogicalType valueType = ((MapType) type).getValueType();
             Map<?, ?> javaMap = bMap.toJavaMap(((MapType) type).getKeyType(), 
valueType);
             for (Map.Entry<?, ?> entry : javaMap.entrySet()) {
-                String key = entry.getKey().toString();
-                if (LogicalTypeRoot.MAP.equals(valueType.getTypeRoot())) {
-                    result.put(key, convertMapData((MapData) entry.getValue(), 
valueType));
-                } else if 
(LogicalTypeRoot.DATE.equals(valueType.getTypeRoot())) {
-                    result.put(
-                            key,
-                            Date.valueOf(LocalDate.ofEpochDay((Integer) 
entry.getValue()))
-                                    .toString());
-                } else if 
(LogicalTypeRoot.ARRAY.equals(valueType.getTypeRoot())) {
-                    result.put(key, convertArrayData((ArrayData) 
entry.getValue(), valueType));
-                } else if (entry.getValue() instanceof TimestampData) {
-                    result.put(key, ((TimestampData) 
entry.getValue()).toTimestamp().toString());
-                } else {
-                    result.put(key, entry.getValue().toString());
-                }
+                Object convertedKey = convertMapEntry(entry.getKey(), keyType);
+                Object convertedValue = convertMapEntry(entry.getValue(), 
valueType);
+                result.put(convertedKey, convertedValue);
             }
             return result;
         }
         throw new UnsupportedOperationException("Unsupported map data: " + 
map.getClass());
     }
 
+    /**
+     * Converts the key-value pair of MAP to the actual type.
+     *
+     * @param originValue the original value of key-value pair
+     * @param logicalType key or value logical type
+     */
+    private static Object convertMapEntry(Object originValue, LogicalType 
logicalType) {
+        if (LogicalTypeRoot.MAP.equals(logicalType.getTypeRoot())) {
+            return convertMapData((MapData) originValue, logicalType);
+        } else if (LogicalTypeRoot.DATE.equals(logicalType.getTypeRoot())) {
+            return Date.valueOf(LocalDate.ofEpochDay((Integer) 
originValue)).toString();
+        } else if (LogicalTypeRoot.ARRAY.equals(logicalType.getTypeRoot())) {
+            return convertArrayData((ArrayData) originValue, logicalType);
+        } else if 
(LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE.equals(logicalType.getTypeRoot())) 
{
+            return (((TimestampData) originValue).toTimestamp()).toString();
+        } else if (originValue instanceof TimestampData) {
+            return ((TimestampData) originValue).toString();

Review Comment:
   After considering it for a while, the previous version was correct。



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


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

Reply via email to