Packages

object AvroType extends Serializable

Macro annotations and converter generators for Avro types.

The following table lists Avro types and their Scala counterparts.

Avro type      Scala type
BOOLEAN        Boolean
LONG           Long
INT            Int
DOUBLE         Double
FLOAT          Float
STRING, ENUM   String
BYTES          com.google.protobuf.ByteString
ARRAY          List[T]
MAP            Map[String, T]
UNION          Option[T]
RECORD         Nested case class
Source
AvroType.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AvroType
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. trait HasAvroAnnotation extends AnyRef

    Trait for case classes with generated companion objects.

  2. trait HasAvroDoc extends AnyRef

    Trait for companion objects of case classes generated with docs.

  3. trait HasAvroSchema[T] extends AnyRef

    Trait for generated companion objects of case classes.

  4. macro class fromPath extends Annotation with StaticAnnotation

    Macro annotation for a path containing Avro files.

    Macro annotation for a path containing Avro files.

    Generates case classes from a path which contains Avro files. Path needs to represent a folder, hence it always needs to end with /. Inside of the folder needs to exist at least one file matching *.avro glob.

    Note that path must be a single string literal with optional .stripMargin at the end. For example:

    @AvroType.fromPath("gs://myBucket/myFolder/")
    class MyRecord

    or

    @AvroType.fromPath(
        """
        | gs://myBucket/myFolder/
        | myLooooooooooooooooongPath/
        """.stripMargin)
    class MyRecord

    Globs are supported as a part of the path. For example:

    @AvroType.fromPath("gs://myBucket`/`*`/`*`/`*`/`")
    class MyRecord

    Also generate a companion object with convenience methods.

    Annotations
    @nowarn() @compileTimeOnly("enable macro paradise (2.12) or -Ymacro-annotations (2.13) to expand macro annotations")
  5. macro class fromSchema extends Annotation with StaticAnnotation

    Macro annotation for an Avro schema.

    Macro annotation for an Avro schema.

    Generate case classes for an Avro schema. Note that schema must be a single string literal of the JSON schema with optional .stripMargin at the end. For example:

    @AvroType.fromSchema(
        """
          |{
          |  "type": "record",
          |  "namespace": "com.spotify.namespace",
          |  "name": "RecordName",
          |  "fields": [
          |    { "name": "boolF", "type": "boolean"},
          |    { "name": "intF", "type": "int"},
          |    { "name": "longF", "type": "long"},
          |    { "name": "floatF", "type": "float"},
          |    { "name": "doubleF", "type": "double"},
          |    { "name": "stringF", "type": "string"},
          |    { "name": "byteStringF", "type": "bytes"}
          |  ]
          |}
        """.stripMargin)
    class MyRecord

    Also generate a companion object with convenience methods.

    Annotations
    @nowarn() @compileTimeOnly("enable macro paradise (2.12) or -Ymacro-annotations (2.13) to expand macro annotations")
  6. macro class fromSchemaFile extends Annotation with StaticAnnotation

    Macro annotation for a file which contains Avro schema.

    Macro annotation for a file which contains Avro schema.

    Generate case classes for an Avro schema. File can be either local or remote files. For example file can be located on Google Cloud Storage (GCS):

    @AvroType.fromSchemaFile("gs://myBucket/myFolder/schema-file.avsc")
    class MyRecord

    For local files, you need to either provide absolute path, or path relative to project root directory. For example:

    @AvroType.fromSchemaFile("sub-project/src/main/avro/schema-file.avsc")
    class MyRecord

    Also generate a companion object with convenience methods.

    Annotations
    @nowarn() @compileTimeOnly("enable macro paradise (2.12) or -Ymacro-annotations (2.13) to expand macro annotations")
  7. macro class toSchema extends Annotation with StaticAnnotation

    Macro annotation for case classes to be saved to Avro files.

    Macro annotation for case classes to be saved to Avro files.

    Note that this annotation does not generate case classes, only a companion object with convenience methods. You need to define a complete case class for as output record. For example:

    @AvroType.toSchema
    case class Result(name: Option[String] = None, score: Option[Double] = None)

    It is recommended that you define all of your fields as Option. This way you could stop populating them in the future if you notice that you don't need them.

    This macro doesn't help you with schema evolution. It's up to you to follow the best practices on how to do evolution of your Avro schemas. Rule of thumb is to only add new fields, without removing the old ones.

    Annotations
    @compileTimeOnly("enable macro paradise (2.12) or -Ymacro-annotations (2.13) to expand macro annotations")

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply[T](implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): AvroType[T]

    Create a new AvroType instance.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. macro def fromGenericRecord[T]: (GenericRecord) => T

    Generate a converter function from GenericRecord to the given case class T.

  11. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. def schemaOf[T](implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): Schema

    Generate Schema for a case class.

  18. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  19. macro def toGenericRecord[T]: (T) => GenericRecord

    Generate a converter function from the given case class T to GenericRecord.

  20. def toString(): String
    Definition Classes
    AnyRef → Any
  21. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Type annotations

Converters

Traits for annotated types

Other Members