package avro4s
- Alphabetic
- Public
- All
Type Members
- case class Anno(className: String, args: Map[String, String]) extends Product with Serializable
- class AnnotationExtractors extends AnyRef
- class Avro4sConfigurationException extends Avro4sException
- class Avro4sDecodingException extends Avro4sException
- class Avro4sEncodingException extends Avro4sException
- class Avro4sException extends Exception
- case class AvroAlias(alias: String) extends Annotation with AvroAliasable with Product with Serializable
- trait AvroAliasable extends Annotation with AvroFieldReflection
-
class
AvroBinaryInputStream[T] extends AvroInputStream[T]
An implementation of AvroInputStream that reads values of type T written as binary data.
An implementation of AvroInputStream that reads values of type T written as binary data. See https://avro.apache.org/docs/current/spec.html#binary_encoding
In order to convert the underlying binary data into types of T, this input stream requires an instance of Decoder.
- class AvroDataInputStream[T] extends AvroInputStream[T]
-
case class
AvroDataOutputStream[T](os: OutputStream, codec: CodecFactory)(implicit encoder: Encoder[T]) extends AvroOutputStream[T] with Product with Serializable
An AvroOutputStream that writes the schema along with the messages.
An AvroOutputStream that writes the schema along with the messages. This is usually the format required when writing multiple messages to a single file. Some frameworks, such as a Kafka, store the Schema separately to messages, in which case the AvroBinaryInputStream is what you would need.
- os
the underlying stream that data will be written to.
- codec
compression codec
- encoder
the avro4s Encoder that will convert each value to a GenericRecord.
- case class AvroDoc(doc: String) extends Annotation with AvroDocumentable with Product with Serializable
- trait AvroDocumentable extends Annotation with AvroFieldReflection
- case class AvroEnumDefault(default: Any) extends Annotation with StaticAnnotation with Product with Serializable
-
case class
AvroErasedName() extends Annotation with AvroFieldReflection with Product with Serializable
This annotation is used to disable generics in the encoding of a record's name.
This annotation is used to disable generics in the encoding of a record's name.
Normally, the record name for a generic type is the name of the raw type, plus the actual type parameters. For example, a class Foo with type parameters Int and Boolean, would have a generated name of
FooInt_Boolean
When this annotation is present on a type, the name used in the schema will simply be the raw type, eg
Foo
. - sealed trait AvroFieldReflection extends Annotation with StaticAnnotation
- trait AvroFixable extends Annotation with AvroFieldReflection
-
case class
AvroFixed(size: Int) extends Annotation with AvroFixable with Product with Serializable
AvroFixed overrides the schema type for a field or a value class so that the schema is set to org.apache.avro.Schema.Type.FIXED rather than whatever the default would be.
AvroFixed overrides the schema type for a field or a value class so that the schema is set to org.apache.avro.Schema.Type.FIXED rather than whatever the default would be.
This annotation can be used in the following ways:
- On a field, eg case class
Foo(@AvroField(10) name: String)
which results in the fieldname
having schema type FIXED with a size of 10.- On a value type, eg
@AvroField(7) case class Foo(name: String) extends AnyVal
which results in all usages of the value type having schema FIXED with a size of 7 rather than the default. - sealed trait AvroFormat extends AnyRef
- trait AvroInputStream[T] extends AutoCloseable
- class AvroInputStreamBuilder[T] extends AnyRef
- class AvroInputStreamBuilderWithSource[T] extends AnyRef
- class AvroJavaEnumDefault extends Annotation with Annotation with ClassfileAnnotation
- class AvroJavaName extends Annotation with Annotation with ClassfileAnnotation
- class AvroJavaNamespace extends Annotation with Annotation with ClassfileAnnotation
- class AvroJavaProp extends Annotation with Annotation with ClassfileAnnotation
- final case class AvroJsonInputStream[T](in: InputStream, writerSchema: Schema)(implicit decoder: Decoder[T]) extends AvroInputStream[T] with Product with Serializable
-
case class
AvroName(name: String) extends Annotation with AvroNameable with Product with Serializable
AvroName allows the name used by Avro to be different from what is defined in code.
AvroName allows the name used by Avro to be different from what is defined in code.
For example, if a case class defines a field z, such as
case class Foo(z: String)
then normally this will be serialized as an entry 'z' in the Avro Record.However, if the field is annotated such as
case class Foo(@AvroName("x") z: String)
then the entry in the Avro Record will be for 'x'.Similarly for deserialization, if a field is annotated then the name that is looked up in the avro record will be the annotated name and not the field name in Scala.
The second example is with classes. If a class is annotated with @AvroName then the name used in the record schema will not be the classname but the annotated value.
This will also have an effect on serialization. For example, when decoding records into an Either, the decoder must decide if the value is a Left or a Right. It usually does this by comparing the name in the record to the classnames of the either types, but when annotated, it will compare the name in the record to the annotated value.
- trait AvroNameable extends Annotation with AvroFieldReflection
- case class AvroNamespace(namespace: String) extends Annotation with AvroNamespaceable with Product with Serializable
- trait AvroNamespaceable extends Annotation with AvroFieldReflection
- case class AvroNoDefault() extends Annotation with StaticAnnotation with Product with Serializable
-
trait
AvroOutputStream[T] extends AutoCloseable
An AvroOutputStream will write instances of T to an underlying representation.
An AvroOutputStream will write instances of T to an underlying representation.
There are three implementations of this stream
- a Data stream,
- a Binary stream
- a Json stream
See the methods on the companion object to create instances of each of these types of stream.
- class AvroOutputStreamBuilder[T] extends AnyRef
- class AvroOutputStreamBuilderWithSource[T] extends AnyRef
- case class AvroProp(key: String, value: String) extends Annotation with AvroProperty with Product with Serializable
- trait AvroProperty extends Annotation with AvroFieldReflection
- case class AvroSortPriority(priority: Float) extends Annotation with AvroFieldReflection with Product with Serializable
- case class AvroTransient() extends Annotation with StaticAnnotation with Product with Serializable
- case class AvroUnionPosition(position: Int) extends Annotation with StaticAnnotation with Product with Serializable
- trait BaseDecoders extends AnyRef
- trait BaseEncoders extends AnyRef
- trait BaseSchemaFors extends AnyRef
- trait BigDecimalDecoders extends AnyRef
- trait BigDecimalEncoders extends AnyRef
- trait ByteIterableDecoders extends AnyRef
- trait ByteIterableEncoders extends AnyRef
- trait ByteIterableSchemaFors extends AnyRef
- sealed trait CaseClassShape extends AnyRef
-
trait
Codec[T] extends Encoder[T] with Decoder[T] with SchemaAware[Codec, T]
Convenience trait that allows to define both custom Encoder and custom Decoder in one go, if both are needed.
Convenience trait that allows to define both custom Encoder and custom Decoder in one go, if both are needed. This way, they don't have to be declared in two separate classes or objects.
A codec can both encode a Scala value of type T into a compatible Avro value based on the given schema as well as decode an Avro value, such as a GenericRecord, SpecificRecord, GenericFixed, EnumSymbol, or a basic JVM type, into a target Scala type.
For advanced users: note that there is no ResolvableCodec type. If you need to define both Encoder and Decoder for a type that is within a chain of recursive types, you need to define them in two separate classes or objects.
- trait CollectionAndContainerDecoders extends AnyRef
- trait CollectionAndContainerEncoders extends AnyRef
- trait CollectionAndContainerSchemaFors extends AnyRef
- sealed trait CustomDefault extends AnyRef
- case class CustomEnumDefault(value: String) extends CustomDefault with Product with Serializable
- case class CustomUnionDefault(className: String, values: Map[String, Any]) extends CustomDefault with Product with Serializable
- case class CustomUnionWithEnumDefault(parentName: String, default: String, value: String) extends CustomDefault with Product with Serializable
-
trait
Decoder[T] extends SchemaAware[Decoder, T] with Serializable
A Decoder is used to convert an Avro value, such as a GenericRecord, SpecificRecord, GenericFixed, EnumSymbol, or a basic JVM type, into a target Scala type.
A Decoder is used to convert an Avro value, such as a GenericRecord, SpecificRecord, GenericFixed, EnumSymbol, or a basic JVM type, into a target Scala type.
For example, a Decoder[String] would convert an input of type Utf8 - which is one of the ways Avro can encode strings - into a plain Java String.
Another example, a decoder for Option[String] would handle inputs of null by emitting a None, and a non-null input by emitting the decoded value wrapped in a Some.
A final example is converting a GenericData.Array or a Java collection type into a Scala collection type.
- class DefaultAvroOutputStream[T] extends AvroOutputStream[T]
- class DefaultAwareDatumReader[T] extends GenericDatumReader[T]
- class DefaultAwareGenericData extends GenericData
-
class
DefinitionEnvironment[Typeclass[_]] extends AnyRef
Helps with encoders/decoders/schemas for recursive types.
Helps with encoders/decoders/schemas for recursive types. Provides a map of already defined bindings for types. For an Encoder e.g., captures which encoders are already defined when building the (cyclic) encoder graph for a recursive type.
Initially, one would expect that handling recursive types can be delegated to Magnolia. Magnolia uses definitions and lazy evaluation to defer the evaluation of recursive types, so that the recursive definition of the type class gets unrolled as needed during data processing. There are two reason why this approach doesn't work in avro4s: one reason for SchemaFor, and one reason for both encoders adn decoders.
a) For SchemaFor, the avro library requires to build a cyclic graph of records for recursive types. Lazily unfolding doesn't work here. To give an example, consider the type
sealed trait Tree case class Leaf(value: Int) extends Tree case class Branch(left: Tree, right: Tree) extends Tree
The Avro schema for this needs to be constructed by first creating the records, then the union, and then setting the fields of the branch record with the schema of the tree union:
val leaf = Schema.createRecord(...) val branch = Schema.createRecord(...) val tree = Schema.createUnion(branch, leaf) branch.setFields(...) // using the tree schema just created before
b) For encoder / decoder, leveraging Magnolias mechanism would work. However, the construction of encoders and decoders is expensive as computing name mappings involves type reflection that would be re-computed on every unfold. Additionally, annotations on one type may trickle down to other types, e.g., a namespace annotation on a trait will be applied to all case classes below it. This push-down of modifications will have to be done on every unfolding as well, meaning additional object allocations.
So instead of using the Magnolia mechanism for encoder / decoder, we reuse our own recursive type handling machinery that we need for SchemaFor, and by this 1) stay consistent within this code base, and 2) achieve much better runtime performance on encoding and decoding (i.e. increase the throughput by roughly 10x).
- Typeclass
Encoder, Decoder or SchemaFor
-
trait
Encoder[T] extends SchemaAware[Encoder, T] with Serializable
An Encoder encodes a Scala value of type T into a compatible Avro value based on the given schema.
An Encoder encodes a Scala value of type T into a compatible Avro value based on the given schema.
For example, given a string, and a schema of type Schema.Type.STRING then the string would be encoded as an instance of Utf8, whereas the same string and a Schema.Type.FIXED would be encoded as an instance of GenericFixed.
Another example is given a Scala enumeration value, and a schema of type Schema.Type.ENUM, the value would be encoded as an instance of GenericData.EnumSymbol.
- trait EnumSchemaFor extends AnyRef
-
trait
FieldMapper extends AnyRef
We may have a schema with a field in snake case like say { "first_name": "sam" } and that schema needs to be used for a case class field
firstName
.We may have a schema with a field in snake case like say { "first_name": "sam" } and that schema needs to be used for a case class field
firstName
.The FieldMapper is used to map fields in a schema to fields in a class by transforming the class field name to the wire name format.
-
trait
FromRecord[T] extends Serializable
Converts from an Avro GenericRecord into instances of T.
- case class ImmutableRecord(schema: Schema, values: Seq[AnyRef]) extends Record with Product with Serializable
- trait MagnoliaDerivedDecoders extends AnyRef
- trait MagnoliaDerivedEncoders extends AnyRef
- trait MagnoliaDerivedSchemaFors extends AnyRef
-
case class
NameExtractor(typeInfo: TypeInfo) extends Product with Serializable
Extracts name and namespace from a TypeName.
Extracts name and namespace from a TypeName. Takes into consideration provided annotations.
-
trait
Record extends GenericRecord with SpecificRecord
An implementation of org.apache.avro.generic.GenericContainer that is both a GenericRecord and a SpecificRecord.
- class RecordDecoder[T] extends Decoder[T]
- class RecordEncoder[T] extends Encoder[T]
-
trait
RecordFormat[T] extends ToRecord[T] with FromRecord[T] with Serializable
Brings together ToRecord and FromRecord in a single interface.
-
trait
ResolvableDecoder[T] extends Decoder[T]
A Decoder that needs to be resolved before it is usable.
A Decoder that needs to be resolved before it is usable. Resolution is needed to properly setup Decoder instances for recursive types.
If this instance is used without resolution, it falls back to use an adhoc-resolved instance and delegates all operations to it. This involves a performance penalty of lazy val access that can be avoided by calling Encoder.resolveEncoder and using that.
For examples on how to define custom ResolvableDecoder instances, see the Readme and RecursiveDecoderTest.
- T
type this encoder is for (primitive type, case class, sealed trait, or enum e.g.).
-
trait
ResolvableEncoder[T] extends Encoder[T]
An Encoder that needs to be resolved before it is usable.
An Encoder that needs to be resolved before it is usable. Resolution is needed to properly setup Encoder instances for recursive types.
If this instance is used without resolution, it falls back to use an adhoc-resolved instance and delegates all operations to it. This involves a performance penalty of lazy val access that can be avoided by calling Encoder.resolveEncoder and using that.
For examples on how to define custom ResolvableEncoder instances, see the Readme and RecursiveEncoderTest.
- T
type this encoder is for (primitive type, case class, sealed trait, or enum e.g.).
-
trait
ResolvableSchemaFor[T] extends SchemaFor[T]
A SchemaFor that needs to be resolved before it is usable.
A SchemaFor that needs to be resolved before it is usable. Resolution is needed to properly setup SchemaFor instances for recursive types.
If this instance is used without resolution, it falls back to use an adhoc-resolved instance and delegates all operations to it. This involves a performance penalty of lazy val access that can be avoided by calling SchemaFor.resolveSchemaFor and using that.
For examples on how to define custom ResolvableSchemaFor instances, see the Readme and RecursiveSchemaTest.
- T
type this schema is for (primitive type, case class, sealed trait, or enum e.g.).
- case class ScalePrecision(scale: Int, precision: Int) extends Product with Serializable
-
trait
SchemaAware[+Typeclass[_], T] extends AnyRef
Indicates that this typeclass (Codec, Encoder, Decoder) has a schema and is modifiable through schema changes
Indicates that this typeclass (Codec, Encoder, Decoder) has a schema and is modifiable through schema changes
- Typeclass
type extending SchemaAware (Codec, Encoder, Decoder)
- T
data type this codec/encoder/decoder transforms from/to
-
trait
SchemaFor[T] extends Serializable
A SchemaFor generates an Avro Schema for a Scala or Java type.
A SchemaFor generates an Avro Schema for a Scala or Java type.
For example, a String SchemaFor could return an instance of Schema.Type.STRING or Schema.Type.FIXED depending on the type required for Strings.
- sealed trait SchemaUpdate extends AnyRef
- sealed trait SealedTraitShape extends AnyRef
- trait ShapelessCoproductDecoders extends AnyRef
- trait ShapelessCoproductEncoders extends AnyRef
- trait ShapelessCoproductSchemaFors extends AnyRef
- trait TemporalDecoders extends AnyRef
- trait TemporalEncoders extends AnyRef
-
trait
ToRecord[T] extends Serializable
Converts from instances of T into Record's.
Converts from instances of T into Record's.
Note: This interface requires that T is marshalled to an Avro GenericRecord / SpecificRecord, and therefore is limited to use by case classes or traits. This interface is essentially just a convenience wrapper around an Encoder so you do not have to cast the result.
If you wish to convert an avro type other than record use an Encoder directly.
- trait TupleDecoders extends AnyRef
- trait TupleEncoders extends AnyRef
- trait TupleSchemaFors extends AnyRef
- trait TypeGuardedDecoding[T] extends Serializable
- case class TypeInfo(owner: String, short: String, typeArguments: Seq[TypeInfo], nameAnnotation: Option[String], namespaceAnnotation: Option[String], erased: Boolean) extends Product with Serializable
- class TypeUnionDecoder[T] extends Decoder[T]
- class TypeUnionEncoder[T] extends Encoder[T]
- class ValueTypeDecoder[T] extends Decoder[T]
- class ValueTypeEncoder[T] extends Encoder[T]
Value Members
- object AvroInputStream
- object AvroOutputStream
- object AvroSchema
- object AvroSchemaMerge
- object BigDecimals
- object BinaryFormat extends AvroFormat
- object CaseClassShape
- object Codec extends Serializable
- object CollectionsAndContainers
- object CustomDefaults
- object DataFormat extends AvroFormat
- object DatatypeShape
- object Decoder extends MagnoliaDerivedDecoders with ShapelessCoproductDecoders with CollectionAndContainerDecoders with TupleDecoders with ByteIterableDecoders with BigDecimalDecoders with TemporalDecoders with BaseDecoders with Serializable
- object DecoderHelpers
- object DefaultAwareDatumReader
- object DefaultFieldMapper extends FieldMapper with Product with Serializable
-
object
DefaultResolver
When we set a default on an avro field, the type must match the schema definition.
When we set a default on an avro field, the type must match the schema definition. For example, if our field has a schema of type UUID, then the default must be a String, or for a schema of Long, then the type must be a java Long and not a Scala long.
This class will accept a scala value and convert it into a type suitable for Avro and the provided schema.
- object DefinitionEnvironment
- object Encoder extends MagnoliaDerivedEncoders with ShapelessCoproductEncoders with CollectionAndContainerEncoders with ByteIterableEncoders with BigDecimalEncoders with TupleEncoders with TemporalEncoders with BaseEncoders with Serializable
- object EncoderHelpers
- object FromRecord extends Serializable
- object JavaEnumSchemaFor extends EnumSchemaFor
- object JsonFormat extends AvroFormat
- object LispCase extends FieldMapper with Product with Serializable
- object NameExtractor extends Serializable
- object PascalCase extends FieldMapper with Product with Serializable
- object RecordFields
-
object
RecordFormat extends Serializable
Returns a RecordFormat that will convert to/from instances of T and avro Record's.
- object Records
- object ScalaEnumSchemaFor extends EnumSchemaFor
- object ScalaEnums
- object ScalePrecision extends Serializable
- object SchemaFor extends MagnoliaDerivedSchemaFors with ShapelessCoproductSchemaFors with CollectionAndContainerSchemaFors with TupleSchemaFors with ByteIterableSchemaFors with BaseSchemaFors with Serializable
- object SchemaHelper
-
object
SchemaUpdate
This ADT is used to capture Avro schema updates that need to be passed from one type to another.
This ADT is used to capture Avro schema updates that need to be passed from one type to another. There are two kinds of schema updates:
a) a full schema replacement that is triggered by e.g.
.withSchema
on Encoder and Decoder, or by AvroFixed annotations on a field or a value class. This is represented by com.sksamuel.avro4s.SchemaUpdate.FullSchemaUpdateb) a namespace change given via AvroNamespace annotation on a sealed trait to its implementing case classes, or given on a field that is passed to the referenced type.
- object SealedTraitShape
- object ShapelessCoproducts
- object SnakeCase extends FieldMapper with Product with Serializable
- object SparkSchemas
- object Temporals
- object ToRecord extends Serializable
- object Tuples
- object TypeGuardedDecoding extends Serializable
- object TypeInfo extends Serializable
- object TypeUnions
- object ValueTypes