vinishjail97 commented on code in PR #17694:
URL: https://github.com/apache/hudi/pull/17694#discussion_r2666228242


##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaUtils.java:
##########
@@ -416,21 +453,138 @@ private static Option<Pair<String, HoodieSchemaField>> 
getNestedFieldInternal(Ho
           .map(field -> Pair.of(prefix + fieldName, field));
     } else {
       // Recursive case: nested field
-      if (nonNullableSchema.getType() != HoodieSchemaType.RECORD) {
-        return Option.empty();
-      }
-
       int dotIndex = fieldName.indexOf(".");
       String rootFieldName = fieldName.substring(0, dotIndex);
       String remainingPath = fieldName.substring(dotIndex + 1);
 
-      return nonNullableSchema.getField(rootFieldName)
-          .flatMap(rootField -> getNestedFieldInternal(
-              rootField.schema(),
-              remainingPath,
-              prefix + rootFieldName + "."
-          ));
+      // Handle RECORD types - standard field navigation
+      if (nonNullableSchema.getType() == HoodieSchemaType.RECORD) {
+        return nonNullableSchema.getField(rootFieldName)
+            .flatMap(rootField -> getNestedFieldInternal(
+                rootField.schema(),
+                remainingPath,
+                prefix + rootFieldName + "."
+            ));
+      }
+
+      // Handle ARRAY types - expect ".list.element" pattern
+      if (nonNullableSchema.getType() == HoodieSchemaType.ARRAY && 
ARRAY_LIST.equals(rootFieldName)) {
+        return handleArrayNavigation(nonNullableSchema, remainingPath, prefix);
+      }
+
+      // Handle MAP types - expect ".key_value.key" or ".key_value.value" 
pattern
+      if (nonNullableSchema.getType() == HoodieSchemaType.MAP && 
MAP_KEY_VALUE.equals(rootFieldName)) {
+        return handleMapNavigation(nonNullableSchema, remainingPath, prefix);
+      }
+      // For all other types (primitives, etc.), cannot navigate
+      return Option.empty();
+    }
+  }
+
+  /**
+   * Extracts the remaining path after a component name, validating the format.
+   * Supports both "component" (end of path) and "component.rest" (continued 
navigation).
+   *
+   * @param remainingPath the remaining path to parse
+   * @param component     the component name to extract after (e.g., 
"element", "key", "value")
+   * @return Option containing the path after the component (empty string if 
at end), or Option.empty() if invalid format
+   */
+  private static Option<String> extractPathAfterComponent(String 
remainingPath, String component) {
+    if (remainingPath.equals(component)) {
+      return Option.of("");
+    } else if (remainingPath.startsWith(component + ".")) {
+      return Option.of(remainingPath.substring((component + ".").length()));
+    }
+    return Option.empty();  // Invalid format (e.g., "elementXYZ")
+  }
+
+  /**
+   * Handles navigation into ARRAY types using the Parquet-style 
".list.element" pattern.
+   *
+   * @param arraySchema   the ARRAY schema to navigate into
+   * @param remainingPath the remaining path after "list" (should start with 
"element")
+   * @param prefix        the accumulated field path prefix
+   * @return Option containing the nested field, or Option.empty() if invalid 
path
+   */
+  private static Option<Pair<String, HoodieSchemaField>> handleArrayNavigation(
+      HoodieSchema arraySchema, String remainingPath, String prefix) {
+    return extractPathAfterComponent(remainingPath, "element")
+        .flatMap(pathAfterElement -> {
+          HoodieSchema elementSchema = arraySchema.getElementType();
+          if (pathAfterElement.isEmpty()) {
+            // We've reached the end - return nested component field for 
element
+            HoodieSchemaField nestedComponentField = HoodieSchemaField.of(
+                "element",
+                elementSchema,
+                null,  // doc
+                null   // defaultVal
+            );
+            return Option.of(Pair.of(prefix + ARRAY_LIST_ELEMENT, 
nestedComponentField));
+          } else {
+            // Continue navigating into element schema
+            return getNestedFieldInternal(
+                elementSchema,
+                pathAfterElement,
+                prefix + ARRAY_LIST_ELEMENT + "."
+            );

Review Comment:
   I have added the offset implementation.



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