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
- Alphabetic
- By Inheritance
- AvroType
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- trait HasAvroAnnotation extends AnyRef
Trait for case classes with generated companion objects.
- trait HasAvroDoc extends AnyRef
Trait for companion objects of case classes generated with docs.
- trait HasAvroSchema[T] extends AnyRef
Trait for generated companion objects of case classes.
- 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")
- 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")
- 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")
- 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
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def apply[T](implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): AvroType[T]
Create a new AvroType instance.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- macro def fromGenericRecord[T]: (GenericRecord) => T
Generate a converter function from GenericRecord to the given case class
T
. - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def schemaOf[T](implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): Schema
Generate Schema for a case class.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- macro def toGenericRecord[T]: (T) => GenericRecord
Generate a converter function from the given case class
T
to GenericRecord. - def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()