zentol closed pull request #7120: fix up RowSerializer.copy occur 
ClassCastException
URL: https://github.com/apache/flink/pull/7120
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java
 
b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java
index e29f6813254..5d3a9e50667 100644
--- 
a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java
+++ 
b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java
@@ -33,6 +33,8 @@
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.List;
 
@@ -92,7 +94,12 @@ public Row copy(Row from) {
                Row result = new Row(len);
                for (int i = 0; i < len; i++) {
                        Object fromField = from.getField(i);
-                       if (fromField != null) {
+
+                       String fromTypeName = 
fromField.getClass().getTypeName();
+                       Type fieldSerializerType = ((ParameterizedType) 
fieldSerializers[i].getClass().getGenericSuperclass()).getActualTypeArguments()[0];
+                       String fieldSerializerTypeName = 
fieldSerializerType.getTypeName();
+
+                       if (fromField != null && 
fieldSerializerTypeName.equals(fromTypeName)) {
                                Object copy = 
fieldSerializers[i].copy(fromField);
                                result.setField(i, copy);
                        } else {
@@ -120,12 +127,20 @@ public Row copy(Row from, Row reuse) {
                        Object fromField = from.getField(i);
                        if (fromField != null) {
                                Object reuseField = reuse.getField(i);
-                               if (reuseField != null) {
+
+                               String fromTypeName = 
fromField.getClass().getTypeName();
+                               String reuseTypeName = 
reuseField.getClass().getTypeName();
+                               Type fieldSerializerType = ((ParameterizedType) 
fieldSerializers[i].getClass().getGenericSuperclass()).getActualTypeArguments()[0];
+                               String fieldSerializerTypeName = 
fieldSerializerType.getTypeName();
+
+                               if (reuseField != null && 
fieldSerializerTypeName.equals(fromTypeName) && 
fromTypeName.equals(reuseTypeName)) {
                                        Object copy = 
fieldSerializers[i].copy(fromField, reuseField);
                                        reuse.setField(i, copy);
-                               } else {
+                               } else if 
(fieldSerializerTypeName.equals(fromTypeName)){
                                        Object copy = 
fieldSerializers[i].copy(fromField);
                                        reuse.setField(i, copy);
+                               } else {
+                                       reuse.setField(i, null);
                                }
                        } else {
                                reuse.setField(i, null);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to