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


##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/format/CastMap.java:
##########
@@ -165,21 +192,132 @@ void add(int pos, LogicalType fromType, LogicalType 
toType) {
         }
         break;
       }
+      case ARRAY: {
+        if (from == ARRAY) {
+          LogicalType fromElementType =  fromType.getChildren().get(0);
+          LogicalType toElementType = toType.getChildren().get(0);
+          return array -> doArrayConversion((ArrayData) array, 
fromElementType, toElementType);
+        }
+        break;
+      }
+      case MAP: {
+        if (from == MAP) {
+          return map -> doMapConversion((MapData) map, fromType, toType);
+        }
+        break;
+      }
+      case ROW: {
+        if (from == ROW) {
+          // Assumption: InternalSchemaManager should produce a cast that is 
of the same size
+          return row -> doRowConversion((RowData) row, fromType, toType);
+        }
+        break;
+      }
       default:
     }
-    return null;
+    throw new IllegalArgumentException(String.format("Unsupported conversion 
for %s => %s", fromType, toType));
   }
 
-  private void add(int pos, Cast cast) {
-    castMap.put(pos, cast);
+  /**
+   * Helper function to perform convert an arrayData from one LogicalType to 
another.
+   *
+   * @param array    Non-null array data to be converted; however 
array-elements are allowed to be null
+   * @param fromType The input LogicalType of the row data to be converted from
+   * @param toType   The output LogicalType of the row data to be converted to
+   * @return Converted array that has the structure/specifications of that 
defined by the output LogicalType
+   */
+  private static ArrayData doArrayConversion(@Nonnull ArrayData array, 
LogicalType fromType, LogicalType toType) {
+    // using Object type here as primitives are not allowed to be null
+    Object[] objects = new Object[array.size()];
+    for (int i = 0; i < array.size(); i++) {
+      Object fromObject = 
ArrayData.createElementGetter(fromType).getElementOrNull(array, i);
+      // need to handle nulls to prevent NullPointerException in 
#getConversion()

Review Comment:
   No need to create element getter for each step of the for-loop?



-- 
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: commits-unsubscr...@hudi.apache.org

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

Reply via email to