Giter Club home page Giter Club logo

sbt-avrohugger's Introduction

sbt-avrohugger

sbt plugin for generating Scala case classes from Apache Avro schemas, datafiles, and protocols.

Install the plugin

Add the following lines to the file myproject/project/plugins.sbt in your project directory:

addSbtPlugin("com.julianpeeters" % "sbt-avrohugger" % "0.8.0")

Import the plugin settings

To activate the plugin, import its settings by adding one of the following lines to your myproject/build.sbt file:

To get the 'generate' task for generating standard Scala Case Classes use:

sbtavrohugger.SbtAvrohugger.avroSettings

To get the generate-specific task for generating Scala Case Classes that are compatible with the Avro Specific API, use:

sbtavrohugger.SbtAvrohugger.specificAvroSettings

To get the generate-scavro task for generating Scala Case Class wrapper classes (Java generated classes supplied separately, or just use the Scavro plugin to do both) for use with Scavro, use:

sbtavrohugger.SbtAvrohugger.scavroSettings

Scope

All settings and tasks are in the avro scope. E.g., to execute the generate task directly, just run avro:generate.

Settings

Name Name in shell Default Description
sourceDirectory source-directory src/main/avro Path containing *.avsc, *.avdl, and/or *.avro files.
scalaSource scala-source $sourceManaged/main Path for the generated *.scala or *.java files.
avroScalaCustomTypes scala-custom-types Map.empty[String, Class[_]] Map for reassigning array to Array, List, or Seq.
avroScalaCustomNamespace scala-custom-namespace Map.empty[String, String] Map for reassigning namespaces.

Changing Settings

Settings can be overridden by adding lines to myproject/build.sbt:

(scalaSource in avroConfig) := new java.io.File("myscalaSource")

scala-custom-types and scala-custom-namespace require additional imports (I'm not sure why these aren't picked up with the other settings, anybody know why we have to import them separately?):

import sbtavrohugger.AvrohuggerSettings.{ avroScalaCustomTypes, avroScalaCustomNamespace }

(avroScalaCustomTypes in avroConfig) := Map("array"->classOf[Array[_]])

(avroScalaCustomNamespace in avroConfig) := Map("example"->"overridden")

Tasks

Each task is automatically executed every time the project is compiled.*

  • as of Intellij IDEA 14.1.4, and possibly for other IDEs, the task must be run manually from the integrated Terminal: avro:generate.
Name Name in shell Description
generate generate Compiles the Avro files into Scala case classes.
generateSpecific generate-specific Compiles the Avro files into Scala case classes implementing SpecificRecord.
generateScavro generate-scavro Compiles the Avro files into Scala case class Scavro wrapper classes.

Datatypes

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 -> Array[Byte]
  • FIXED -> //TODO
  • ARRAY -> List (generate-scavro: Array). To reassign, please see Settings above.
  • UNION -> Option
  • RECORD -> case class

Future

  • support for more avro datatypes
  • more codegen situations, e.g. exploding Spark Rows?

Credits

sbt-avrohugger is based on sbt-avro by Juan Manuel Caicedo, and depends on avrohugger.

Contributors

Fork away, just make sure the tests pass before you send a pull request.

Criticism is appreciated.

sbt-avrohugger's People

Contributors

julianpeeters avatar mariussoutier avatar rkoval 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.