Object/Class

com.spotify.scio.avro.types

AvroType

Related Docs: class AvroType | package types

Permalink

object AvroType

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
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AvroType
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait HasAvroAnnotation extends AnyRef

    Permalink

    Trait for case classes with generated companion objects.

  2. trait HasAvroDoc extends AnyRef

    Permalink

    Trait for companion objects of case classes generated with docs.

  3. trait HasAvroSchema[T] extends AnyRef

    Permalink

    Trait for generated companion objects of case classes.

  4. macro class fromPath extends Annotation with StaticAnnotation

    Permalink

    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
    @compileTimeOnly( ... )
  5. macro class fromSchema extends Annotation with StaticAnnotation

    Permalink

    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
    @compileTimeOnly( ... )
  6. macro class fromSchemaFile extends Annotation with StaticAnnotation

    Permalink

    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
    @compileTimeOnly( ... )
  7. macro class toSchema extends Annotation with StaticAnnotation

    Permalink

    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( ... )

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def apply[T](implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): AvroType[T]

    Permalink

    Create a new AvroType instance.

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. macro def fromGenericRecord[T]: (GenericRecord) ⇒ T

    Permalink

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

  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. def schemaOf[T](implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): Schema

    Permalink

    Generate Schema for a case class.

  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  19. macro def toGenericRecord[T]: (T) ⇒ GenericRecord

    Permalink

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

  20. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  21. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Type annotations

Converters

Traits for annotated types

Other Members