Coder Social home page Coder Social logo

avrohugger's Introduction

avrohugger

Schema-to-case-class code generation for working with Avro in Scala.

  • avrohugger-core: Generate source code dynamically at runtime for evaluation at a later step
  • avrohugger-tools: Generate source code at the command line with the avrohugger-tools jar.
  • sbt-avrohugger: Generate source code at compile time with an sbt plugin.

Generates Scala case classes:

  • Vanilla case classes (for use with Scalavro, Salat-Avro, gfc-avro, etc.)

  • Case classes that implement SpecificRecordBase (for use with the Avro Specific API - Scalding, Spark, Avro, etc.).

Supports generating case classes with arbitrary fields of the following datatypes:

  • INT -> Int
  • LONG -> Long
  • FLOAT -> Float
  • DOUBLE -> Double
  • STRING -> String
  • BOOLEAN -> Boolean
  • NULL -> Null
  • MAP -> Map
  • ENUM -> generate: scala.Enumeration, generate-specific: Java Enum
  • BYTES -> //TODO
  • FIXED -> //TODO
  • ARRAY -> List
  • UNION -> Option
  • RECORD -> case class

Usage (for Scala 2.10 and 2.11)

####avrohugger-core

Get the dependency with:

"com.julianpeeters" % "avrohugger-core" %% "0.4.0"

Instantiate a Generator with Standard or SpecificRecord source formats. Then use

tToFile(input: T, outputDir: String): Unit

or

tToStrings(input: T): List[String]

where 'T' can be File, Schema, or String:

import avrohugger._
import format._

val schemaFile = new File("path/to/schema")
val generator = new Generator(SpecificRecord)
generator.fileToFile(schemaFile, "optional/path/to/output") // default output path = "target/generated-sources" 

####avrohugger-tools

Download the avrohugger-tools jar for Scala 2.10 or Scala 2.11(20MB!) and use it like the avro-tools jar Usage: [-string] (schema|protocol|datafile) input... outputdir:

  • 'generate' generates Scala case class definitions java -jar /path/to/avrohugger-tools_2.11-0.4.0-assembly.jar generate schema user.avsc .

  • 'generate-specific' generates case class definitions that extend SpecificRecordBase java -jar /path/to/avrohugger-tools_2.11-0.4.0-assembly.jar generate-specific schema user.avsc .

####sbt-avrohugger

Also available as an sbt plugin found here that adds a generate or generate-specific task to compile (an alternative to macros).

Future

  • Support more avro types: fixed, bytes.

Testing

The scripted task runs all tests.

As per Doug Cutting's recommendations in the avro compiler tests, the string-based tests in test are augmented by scripted tests that generate and compile source that is run in de/serialization tests.

Credits

Depends on Avro and Treehugger. avrohugger-tools is based on avro-tools.

Contributors:

Criticism is appreciated. Fork away, just make sure the tests pass before sending a pull request.

avrohugger's People

Contributors

galarragas avatar julianpeeters avatar mariussoutier avatar ppearcy avatar

Watchers

 avatar  avatar

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.