Giter Club home page Giter Club logo

avronaut's People

Contributors

bobbyrauchenberg avatar bskyb-rra02 avatar r-glyde avatar

Stargazers

 avatar

Watchers

 avatar  avatar

avronaut's Issues

Rewrite schema to use AST

Schema is currently working, but i think the code could be cleaned up in the instances by moving to an AST

Magnolia would generate an AST which was then parsed to a schema, keeping the instances simple and clean and also making things like shuffling schema elements, handling annotations etc... a lot cleaner

Improve schema tests

Schema tests are currently comparing Strings, this is fragile

On the whole we should be able to convert to json and compare json objects (this may not apply to, for example Union schemas, where we want to enforce field order)

Make schema default conversion configurable

When you give a default for a field in the schema creation, the value needs to be converted to a Java structure

Currently there is a case match on possible types to use for defaults in SchemaHelper.transformDefault - it would be nice to make it possible for users to add their own default conversions - possibly in the shape of a map from DefaultType -> JavaType (which in reality would probably be sth like Map[String, Any] => Any

But this could then be passed in, or added to some config object when schema generation happened

Improve error reporting

Currently all apis return Either[Error, T]. This can translate nicely to cats Validation instances, and given Magnolia iterates over all params we can build a very descriptive error report if a typeclass generation fails

A nice to have would be to be able to also have this in json format

Make Encoder and Decoder APIs more efficient

Currently Encoder and Decoder will run thru a load of extra steps each time they're called

Encoder generates an AvroSchema, and also translates to Avro in the magnolia step. We should

  • pass in a schema
  • translate direct to AvroF in typeclass generation and jst run a catamorphism in the parser (currently anamorphism)
  • allow an encoder to be generated up front - like avro4s has ToRecord, then pass this to the parser when we have the record

will need to change this

def encode[A](a: A)(implicit encoder: Encoder[A], schema: AvroSchema[A]): Either[Error, GenericData.Record] =
    for {
      s       <- schema.schema
      encoded <- encoder.encode(a)
      genRec <- encoded match {
                 case AvroRecord(schema, values) =>
                   Parser(new GenericData.Record(s)).parse(AvroRoot(schema, values))
                 case _ => Error(s"Can only encode records, got $encoded").asLeft
               }
    } yield genRec

similar with Decoder which currently does everything on each invocation, need to split this so that the interface is sth like

trait Decoder[A] {

  def apply(operation: DecodeOperation): Result[A]

}

Cleanup decoder parser

GenericRecord returns Any when you lookup values. I didn't want to pollute the API passing Any about. However given the way the typeclass derivation works, i wasn't able to write a Decoder instance for, for example List, without passing the Any value from the GenericRecord

As a solution I have written a parser which traverses the schema passed by the reader, and pulls the relevant values from the generic record, this keeps Any out of any public facing APIs

However because this step happens before Magnolia derives typeclass instances, I don't have access to default parameter values (as Magnolia provides these) at parse time. So the parser currently can fail to parse a field because there is no value in the provided GenericRecord, but the overall process needs to still succeed, setting the field that parsed tp type ParseFail, this means that when the Magnolia based Decoder runs, ParseFails are propogated and it is possible to provide a default value for those fields (if a default exists).

This feels wrong because:

  1. ParseFail has been added as an AvroType to allow me to return Result[AvroType] from Parser
  2. It feels dirty to fail but still pass the parsing step (tho this is a necessary evil atm)

It would be nice to find a cleaner way to do this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.