A started draft of a runtime Lenses implementation for mutating or creating transformed GenericRecords
How to use
The artifact is deployed on sonatype's central repository, so all you need is to add it to your resolvers and use it like that :
resolvers += Resolver.sonatypeRepo("snapshot") libraryDependencies += "fr.psug.avro" %% "avro-lenses" % "0.1.0-SNAPSHOT"
Or to use the latest stable release
resolvers += Resolver.sonatypeRepo("releases") libraryDependencies += "fr.psug.avro" %% "avro-lenses" % "0.1.0"
// here for example we define a transformer that will transform toUpperCase the field 'name' of struct 'person' import fr.psug.avro.AvroLens._ val transformer = defineWithSideEffect[String]("a.b", _.toUpperCase) // then you can apply it 'transformer' on any generic record and it will be mutated in place // If you want additional safety you can use it providing the Schema : val transformer = defineWithSideEffectAndSchema[String]("a.b", _.toUpperCase, schema)
For more use cases, you can check out the unit tests that contains exhaustive tests of all the features.
path is quite intuitive and conforms almost to the JSONPath standard :
a.b.cwill refer to the field/array
awill refer to the array inside of field