Zouxxyy commented on code in PR #4848:
URL: https://github.com/apache/paimon/pull/4848#discussion_r1904824201


##########
paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java:
##########
@@ -681,6 +690,65 @@ public void testTimeToTimestamp() {
                 DateTimeUtils.parseTimestampData("1970-01-01 " + time, 3));
     }
 
+    @Test
+    public void testArrayToString() {
+        ArrayType arrayType = new ArrayType(DataTypes.INT());
+        GenericArray genericArray = new GenericArray(new Integer[] {1, null, 
2});
+        compareCastResult(
+                CastExecutors.resolve(arrayType, DataTypes.STRING()),
+                genericArray,
+                BinaryString.fromString("[1, null, 2]"));
+    }
+
+    @Test
+    public void testMapToString() {
+        MapType mapType = new MapType(DataTypes.INT(), DataTypes.STRING());
+        Map<Object, Object> javaMap = new HashMap<>();
+        javaMap.put(1, BinaryString.fromString("i"));
+        javaMap.put(2, BinaryString.fromString("miss"));
+        javaMap.put(3, BinaryString.fromString("you"));
+        javaMap.put(4, null);
+        GenericMap genericMap = new GenericMap(javaMap);
+        compareCastResult(
+                CastExecutors.resolve(mapType, DataTypes.STRING()),
+                genericMap,
+                BinaryString.fromString("{1 -> i, 2 -> miss, 3 -> you, 4 -> 
null}"));

Review Comment:
   This is the behavior of Spark SQL's cast.
   
   ```
   select cast (struct(1, 'a') as string), cast (map(1, 'a') as string), cast 
(array(1,2,3) as string)
   
+----------------------------+-------------------------+------------------------------+
   |CAST(struct(1, a) AS STRING)|CAST(map(1, a) AS STRING)|CAST(array(1, 2, 3) 
AS STRING)|
   
+----------------------------+-------------------------+------------------------------+
   |                      {1, a}|                 {1 -> a}|                     
[1, 2, 3]|
   
+----------------------------+-------------------------+------------------------------+
   ```



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