static Object extractField(String fieldName, Object current, boolean validateField) {
    if (current instanceof SamzaSqlRelRecord) {
      SamzaSqlRelRecord record = (SamzaSqlRelRecord) current;
      if (validateField) {
        Validate.isTrue(record.getFieldNames().contains(fieldName),
            String.format("Invalid field %s in record %s", fieldName, record));
      }
      return record.getField(fieldName).orElse(null);
    } else if (current instanceof Map) {
      Map map = (Map) current;
      if (map.containsKey(fieldName)) {
        return map.get(fieldName);
      } else if (map.containsKey(new Utf8(fieldName))) {
        return map.get(new Utf8(fieldName));
      } else {
        throw new IllegalArgumentException(String.format("Couldn't find the field %s in map %s", fieldName, map));
      }
    } else if (current instanceof List && fieldName.endsWith("]")) {
      List list = (List) current;
      int index = Integer.parseInt(fieldName.substring(fieldName.indexOf("[") + 1, fieldName.length() - 1));
      return list.get(index);
    }

    throw new IllegalArgumentException(
        String.format("Unsupported accessing operation for data type: %s with field: %s.", current.getClass(), fieldName));
  }
UDF that extracts a field value from a nested SamzaSqlRelRecord by recursively following a query path.
Note that the root object must be a SamzaSqlRelRecord.

Syntax for field specification:
<ul>
 <li> SamzaSqlRelRecord/Map: <code> field.subfield </code> </li>
 <li> Array: <code> field[index] </code> </li>
 <li> Scalar types: <code> field </code> </li>
</ul>

Example query: <code> pageViewEvent.requestHeader.properties.cookies[3].sessionKey </code>

Above query extracts the sessionKey field from below nested record:

  pageViewEvent (SamzaSqlRelRecord)
    - requestHeader (SamzaSqlRelRecord)
      - properties (Map)
        - cookies (Array)
          - sessionKey (Scalar)
samza-sql/src/main/java/org/apache/samza/sql/fn/GetSqlFieldUdf.java