Вот мое решение в scala
private val INVALID_ATTRIBUTE_CHARS = "[ ,;{}()\n\t=]"
def replaceBadAttriName(structType: StructType): StructType =
StructType(structType.fields.map(cleanStructFld))
private def cleanStructFld(fld: StructField): StructField = {
fld.dataType match {
case struct: StructType =>
StructField(fld.name, StructType(struct.map(cleanStructFld)), fld.nullable, fld.metadata)
case _ =>
val newName = fld.name.replaceAll(INVALID_ATTRIBUTE_CHARS, "_")
StructField(newName, fld.dataType, fld.nullable, fld.metadata)
}
}