code: public static Path serializeAsPath(GenericRecord record, boolean includeFieldNames, boolean replacePathSeparators) {
      if (record == null) {
        return new Path("");
      }
      List<String> tokens = Lists.newArrayList();
      for (Schema.Field field : record.getSchema().getFields()) {
        String sanitizedName = HadoopUtils.sanitizePath(field.name(), "_");
        String sanitizedValue = HadoopUtils.sanitizePath(record.get(field.name()).toString(), "_");
        if (replacePathSeparators) {
          sanitizedName = sanitizedName.replaceAll(Path.SEPARATOR, "_");
          sanitizedValue = sanitizedValue.replaceAll(Path.SEPARATOR, "_");
        }
        if (includeFieldNames) {
          tokens.add(String.format("%s=%s", sanitizedName, sanitizedValue));
        } else if (!Strings.isNullOrEmpty(sanitizedValue)) {
          tokens.add(sanitizedValue);
        }
      }
      return new Path(Joiner.on(Path.SEPARATOR).join(tokens));
    }
docs: Serialize a generic record as a relative {@link Path}. Useful for converting {@link GenericRecord} type keys
  into file system locations. For example {field1=v1, field2=v2} returns field1=v1/field2=v2 if includeFieldNames
  is true, or v1/v2 if it is false. Illegal HDFS tokens such as ':' and '\\' will be replaced with '_'.
  Additionally, parameter replacePathSeparators controls whether to replace path separators ('/') with '_'.
  
  @param record {@link GenericRecord} to serialize.
  @param includeFieldNames If true, each token in the path will be of the form key=value, otherwise, only the value
  will be included.
  @param replacePathSeparators If true, path separators ('/') in each token will be replaced with '_'.
  @return A relative path where each level is a field in the input record.