Last active
July 2, 2020 23:24
-
-
Save idarlington/ad488be3588eb9c07236cc5feab47639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* [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