Skip to content

Instantly share code, notes, and snippets.

@idarlington
Last active July 2, 2020 23:24
Show Gist options
  • Save idarlington/ad488be3588eb9c07236cc5feab47639 to your computer and use it in GitHub Desktop.
Save idarlington/ad488be3588eb9c07236cc5feab47639 to your computer and use it in GitHub Desktop.
/**
* [WIP]
*
* The goal is to recursively convert a genericRecord to have lower case field names.
*/
import org.apache.avro.{Schema, SchemaBuilder}
import scala.collection.JavaConverters._
object GenericRecordConverter {
def converter(schema: Schema): Schema = {
val builder: SchemaBuilder.FieldAssembler[Schema] = SchemaBuilder.record(schema.getNamespace).fields()
schema.getFields.asScala.foreach { field =>
if (field.schema().getType != Schema.Type.RECORD) {
builder.name(field.name().toLowerCase).`type`(field.schema())
} else {
builder.name(field.name().toLowerCase).`type`(converter(field.schema()))
}
}
builder.endRecord()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment