def METHOD_NAME(field, parent_name="", include_nested=True):
    cols = []
    if parent_name != "":
        parent_name = f"{parent_name}."
    if pyspark.types and isinstance(field, pyspark.types.StructType):
        for child in field.fields:
            cols += METHOD_NAME(
                child, parent_name=parent_name, include_nested=include_nested
            )
    elif pyspark.types and isinstance(field, pyspark.types.StructField):
        if include_nested and "." in field.name:
            # Only add backticks to escape dotted fields if they don't already exist
            if field.name.startswith("`") and field.name.endswith("`"):
                name = f"{parent_name}{field.name}"
            else:
                name = f"{parent_name}`{field.name}`"
        else:
            name = parent_name + field.name
        field_metadata = {"name": name, "type": field.dataType}
        cols.append(field_metadata)
        if (
            include_nested
            and pyspark.types
            and isinstance(field.dataType, pyspark.types.StructType)
        ):
            for child in field.dataType.fields:
                cols += METHOD_NAME(
                    child,
                    parent_name=parent_name + field.name,
                    include_nested=include_nested,
                )
    else:
        raise ValueError("unrecognized field type")
    return cols