Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Avro
Description
Avro encoding and decoding routines.
This library provides a high level interface for encoding and decoding Haskell values in Apache's Avro serialization format.
Synopsis
- data Schema where
- Null
- Boolean
- Int { }
- Long { }
- Float
- Double
- Bytes { }
- String { }
- Array { }
- Map { }
- NamedType TypeName
- Record { }
- Enum { }
- Union { }
- Fixed {
- name :: TypeName
- aliases :: [TypeName]
- size :: Int
- logicalTypeF :: Maybe LogicalTypeFixed
- pattern Bytes' :: Schema
- pattern Int' :: Schema
- pattern Long' :: Schema
- pattern String' :: Schema
- data Field = Field {
- fldName :: Text
- fldAliases :: [Text]
- fldDoc :: Maybe Text
- fldOrder :: Maybe Order
- fldType :: Schema
- fldDefault :: Maybe DefaultValue
- data Order
- data TypeName = TN {}
- data Decimal = Decimal {}
- newtype LogicalTypeBytes = DecimalB Decimal
- data LogicalTypeFixed
- data LogicalTypeInt
- data LogicalTypeLong
- data LogicalTypeString = UUID
- data ReadSchema
- deconflict :: Schema -> Schema -> Either String ReadSchema
- readSchemaFromSchema :: Schema -> ReadSchema
- encodeValue :: (HasAvroSchema a, ToAvro a) => a -> ByteString
- encodeValueWithSchema :: ToAvro a => Schema -> a -> ByteString
- decodeValue :: (HasAvroSchema a, FromAvro a) => ByteString -> Either String a
- decodeValueWithSchema :: FromAvro a => ReadSchema -> ByteString -> Either String a
- decodeContainer :: (HasAvroSchema a, FromAvro a) => ByteString -> [Either String a]
- decodeContainerWithEmbeddedSchema :: FromAvro a => ByteString -> [Either String a]
- decodeContainerWithReaderSchema :: FromAvro a => Schema -> ByteString -> [Either String a]
- encodeContainer :: (HasAvroSchema a, ToAvro a) => Codec -> [[a]] -> IO ByteString
- encodeContainerWithSchema :: ToAvro a => Codec -> Schema -> [[a]] -> IO ByteString
- encodeContainerWithSync :: ToAvro a => Codec -> Schema -> ByteString -> [[a]] -> ByteString
- newSyncBytes :: IO ByteString
- extractContainerValuesBytes :: ByteString -> Either String (Schema, [Either String ByteString])
- decodeContainerValuesBytes :: FromAvro a => Schema -> ByteString -> Either String (Schema, [Either String (a, ByteString)])
- class ToAvro a
- class FromAvro a
- data Codec
- nullCodec :: Codec
- deflateCodec :: Codec
- class HasAvroSchema a where
- schemaOf :: HasAvroSchema a => a -> Schema
Schema
N.B. It is possible to create a Haskell value (of Schema
type) that is
not a valid Avro schema by violating one of the above or one of the
conditions called out in validateSchema
.
Constructors
Null | |
Boolean | |
Int | |
Fields | |
Long | |
Fields | |
Float | |
Double | |
Bytes | |
Fields | |
String | |
Fields | |
Array | |
Map | |
NamedType TypeName | |
Record | |
Enum | |
Union | |
Fixed | |
Fields
|
Bundled Patterns
pattern Bytes' :: Schema | |
pattern Int' :: Schema | |
pattern Long' :: Schema | |
pattern String' :: Schema |
Instances
Constructors
Field | |
Fields
|
Instances
NFData Field Source # | |||||
Defined in Data.Avro.Schema.Schema | |||||
Generic Field Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
| |||||
Show Field Source # | |||||
Eq Field Source # | |||||
Ord Field Source # | |||||
Lift Field Source # | |||||
type Rep Field Source # | |||||
Defined in Data.Avro.Schema.Schema type Rep Field = D1 ('MetaData "Field" "Data.Avro.Schema.Schema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'False) (C1 ('MetaCons "Field" 'PrefixI 'True) ((S1 ('MetaSel ('Just "fldName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text) :*: (S1 ('MetaSel ('Just "fldAliases") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [Text]) :*: S1 ('MetaSel ('Just "fldDoc") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Text)))) :*: (S1 ('MetaSel ('Just "fldOrder") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Order)) :*: (S1 ('MetaSel ('Just "fldType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Schema) :*: S1 ('MetaSel ('Just "fldDefault") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe DefaultValue)))))) |
Constructors
Ascending | |
Descending | |
Ignore |
Instances
FromJSON Order Source # | |||||
Defined in Data.Avro.Schema.Schema | |||||
ToJSON Order Source # | |||||
NFData Order Source # | |||||
Defined in Data.Avro.Schema.Schema | |||||
Generic Order Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
| |||||
Show Order Source # | |||||
Eq Order Source # | |||||
Ord Order Source # | |||||
Lift Order Source # | |||||
type Rep Order Source # | |||||
Defined in Data.Avro.Schema.Schema type Rep Order = D1 ('MetaData "Order" "Data.Avro.Schema.Schema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'False) (C1 ('MetaCons "Ascending" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Descending" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Ignore" 'PrefixI 'False) (U1 :: Type -> Type))) |
A named type in Avro has a name and, optionally, a namespace.
A name is a string that starts with an ASCII letter or underscore followed by letters, underscores and digits:
name ::= [A-Za-z_][A-Za-z0-9_]*
Examples include "_foo7"
, Bar_
and "x"
.
A namespace is a sequence of names with the same lexical
structure. When written as a string, the components of a namespace
are separated with dots ("com.example"
).
TypeName
represents a fullname—a name combined with a
namespace. These are written and parsed as dot-separated
strings. The TypeName
TN Foo ["com", "example"]
is rendered
as "com.example.Foo"
.
Fullnames have to be globally unique inside an Avro schema.
A namespace of []
or [""]
is the "null namespace". In avro
an explicitly null-namespaced identifier is written as ".Foo"
Instances
NFData TypeName Source # | |||||
Defined in Data.Avro.Schema.Schema | |||||
IsString TypeName Source # | This lets us write | ||||
Defined in Data.Avro.Schema.Schema Methods fromString :: String -> TypeName # | |||||
Generic TypeName Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
| |||||
Show TypeName Source # | Show the | ||||
Eq TypeName Source # | |||||
Ord TypeName Source # | |||||
Defined in Data.Avro.Schema.Schema | |||||
Hashable TypeName Source # | |||||
Defined in Data.Avro.Schema.Schema | |||||
Lift TypeName Source # | |||||
type Rep TypeName Source # | |||||
Defined in Data.Avro.Schema.Schema type Rep TypeName = D1 ('MetaData "TypeName" "Data.Avro.Schema.Schema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'False) (C1 ('MetaCons "TN" 'PrefixI 'True) (S1 ('MetaSel ('Just "baseName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "namespace") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [Text]))) |
The decimal
logical type represents arbitrary-precision decimal
numbers. Numbers are represented as unscaled * (10 ** -scale)
where scale
is part of the logical type and unscaled
is an
integer represented by the underlying primitive type.
Instances of the decimal
logical type need to specify a scale
and precision
.
decimal
can be encoded as one of several different primitive
types:
bytes
fixed
long
int
For long
and int
, unscaled
is the underlying number.
For bytes
and fixed
, unscaled
is represented as a
two's-complement signed integer in big-endian byte order.
Note: int
and long
representations for decimal
are not part
of the current Avro
specification,
but they are supported by some language implementations including
the official Java library. Implementations that do not support this
should ignore the logical type and use the underlying primitive
type instead.
Constructors
Decimal | |
Instances
NFData Decimal Source # | |||||
Defined in Data.Avro.Schema.Schema | |||||
Generic Decimal Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
| |||||
Show Decimal Source # | |||||
Eq Decimal Source # | |||||
Ord Decimal Source # | |||||
Defined in Data.Avro.Schema.Schema | |||||
Lift Decimal Source # | |||||
type Rep Decimal Source # | |||||
Defined in Data.Avro.Schema.Schema type Rep Decimal = D1 ('MetaData "Decimal" "Data.Avro.Schema.Schema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'False) (C1 ('MetaCons "Decimal" 'PrefixI 'True) (S1 ('MetaSel ('Just "precision") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Integer) :*: S1 ('MetaSel ('Just "scale") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Integer))) |
newtype LogicalTypeBytes Source #
Instances
NFData LogicalTypeBytes Source # | |||||
Defined in Data.Avro.Schema.Schema Methods rnf :: LogicalTypeBytes -> () # | |||||
Generic LogicalTypeBytes Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
Methods from :: LogicalTypeBytes -> Rep LogicalTypeBytes x # to :: Rep LogicalTypeBytes x -> LogicalTypeBytes # | |||||
Show LogicalTypeBytes Source # | |||||
Defined in Data.Avro.Schema.Schema Methods showsPrec :: Int -> LogicalTypeBytes -> ShowS # show :: LogicalTypeBytes -> String # showList :: [LogicalTypeBytes] -> ShowS # | |||||
Eq LogicalTypeBytes Source # | |||||
Defined in Data.Avro.Schema.Schema Methods (==) :: LogicalTypeBytes -> LogicalTypeBytes -> Bool # (/=) :: LogicalTypeBytes -> LogicalTypeBytes -> Bool # | |||||
Ord LogicalTypeBytes Source # | |||||
Defined in Data.Avro.Schema.Schema Methods compare :: LogicalTypeBytes -> LogicalTypeBytes -> Ordering # (<) :: LogicalTypeBytes -> LogicalTypeBytes -> Bool # (<=) :: LogicalTypeBytes -> LogicalTypeBytes -> Bool # (>) :: LogicalTypeBytes -> LogicalTypeBytes -> Bool # (>=) :: LogicalTypeBytes -> LogicalTypeBytes -> Bool # max :: LogicalTypeBytes -> LogicalTypeBytes -> LogicalTypeBytes # min :: LogicalTypeBytes -> LogicalTypeBytes -> LogicalTypeBytes # | |||||
Lift LogicalTypeBytes Source # | |||||
Defined in Data.Avro.Deriving.Lift Methods lift :: Quote m => LogicalTypeBytes -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => LogicalTypeBytes -> Code m LogicalTypeBytes # | |||||
type Rep LogicalTypeBytes Source # | |||||
Defined in Data.Avro.Schema.Schema type Rep LogicalTypeBytes = D1 ('MetaData "LogicalTypeBytes" "Data.Avro.Schema.Schema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'True) (C1 ('MetaCons "DecimalB" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Decimal))) |
data LogicalTypeFixed Source #
Constructors
DecimalF Decimal | An arbitrary-precision signed decimal number. See |
Duration | An interval of time, represented as some number of months, days and milliseconds. Encoded as three little-endian unsigned integers for months, days and milliseconds respectively. |
Instances
NFData LogicalTypeFixed Source # | |||||
Defined in Data.Avro.Schema.Schema Methods rnf :: LogicalTypeFixed -> () # | |||||
Generic LogicalTypeFixed Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
Methods from :: LogicalTypeFixed -> Rep LogicalTypeFixed x # to :: Rep LogicalTypeFixed x -> LogicalTypeFixed # | |||||
Show LogicalTypeFixed Source # | |||||
Defined in Data.Avro.Schema.Schema Methods showsPrec :: Int -> LogicalTypeFixed -> ShowS # show :: LogicalTypeFixed -> String # showList :: [LogicalTypeFixed] -> ShowS # | |||||
Eq LogicalTypeFixed Source # | |||||
Defined in Data.Avro.Schema.Schema Methods (==) :: LogicalTypeFixed -> LogicalTypeFixed -> Bool # (/=) :: LogicalTypeFixed -> LogicalTypeFixed -> Bool # | |||||
Ord LogicalTypeFixed Source # | |||||
Defined in Data.Avro.Schema.Schema Methods compare :: LogicalTypeFixed -> LogicalTypeFixed -> Ordering # (<) :: LogicalTypeFixed -> LogicalTypeFixed -> Bool # (<=) :: LogicalTypeFixed -> LogicalTypeFixed -> Bool # (>) :: LogicalTypeFixed -> LogicalTypeFixed -> Bool # (>=) :: LogicalTypeFixed -> LogicalTypeFixed -> Bool # max :: LogicalTypeFixed -> LogicalTypeFixed -> LogicalTypeFixed # min :: LogicalTypeFixed -> LogicalTypeFixed -> LogicalTypeFixed # | |||||
Lift LogicalTypeFixed Source # | |||||
Defined in Data.Avro.Deriving.Lift Methods lift :: Quote m => LogicalTypeFixed -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => LogicalTypeFixed -> Code m LogicalTypeFixed # | |||||
type Rep LogicalTypeFixed Source # | |||||
Defined in Data.Avro.Schema.Schema type Rep LogicalTypeFixed = D1 ('MetaData "LogicalTypeFixed" "Data.Avro.Schema.Schema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'False) (C1 ('MetaCons "DecimalF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Decimal)) :+: C1 ('MetaCons "Duration" 'PrefixI 'False) (U1 :: Type -> Type)) |
data LogicalTypeInt Source #
Constructors
DecimalI Decimal | An arbitrary-precision signed decimal number. See |
Date | A date (eg Encoded as the number of days before/after the Unix epoch (1970-01-01). |
TimeMillis | A time of day with millisecond precision. Encoded as the number of milliseconds after midnight. |
Instances
NFData LogicalTypeInt Source # | |||||
Defined in Data.Avro.Schema.Schema Methods rnf :: LogicalTypeInt -> () # | |||||
Generic LogicalTypeInt Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
Methods from :: LogicalTypeInt -> Rep LogicalTypeInt x # to :: Rep LogicalTypeInt x -> LogicalTypeInt # | |||||
Show LogicalTypeInt Source # | |||||
Defined in Data.Avro.Schema.Schema Methods showsPrec :: Int -> LogicalTypeInt -> ShowS # show :: LogicalTypeInt -> String # showList :: [LogicalTypeInt] -> ShowS # | |||||
Eq LogicalTypeInt Source # | |||||
Defined in Data.Avro.Schema.Schema Methods (==) :: LogicalTypeInt -> LogicalTypeInt -> Bool # (/=) :: LogicalTypeInt -> LogicalTypeInt -> Bool # | |||||
Ord LogicalTypeInt Source # | |||||
Defined in Data.Avro.Schema.Schema Methods compare :: LogicalTypeInt -> LogicalTypeInt -> Ordering # (<) :: LogicalTypeInt -> LogicalTypeInt -> Bool # (<=) :: LogicalTypeInt -> LogicalTypeInt -> Bool # (>) :: LogicalTypeInt -> LogicalTypeInt -> Bool # (>=) :: LogicalTypeInt -> LogicalTypeInt -> Bool # max :: LogicalTypeInt -> LogicalTypeInt -> LogicalTypeInt # min :: LogicalTypeInt -> LogicalTypeInt -> LogicalTypeInt # | |||||
Lift LogicalTypeInt Source # | |||||
Defined in Data.Avro.Deriving.Lift Methods lift :: Quote m => LogicalTypeInt -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => LogicalTypeInt -> Code m LogicalTypeInt # | |||||
type Rep LogicalTypeInt Source # | |||||
Defined in Data.Avro.Schema.Schema type Rep LogicalTypeInt = D1 ('MetaData "LogicalTypeInt" "Data.Avro.Schema.Schema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'False) (C1 ('MetaCons "DecimalI" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Decimal)) :+: (C1 ('MetaCons "Date" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TimeMillis" 'PrefixI 'False) (U1 :: Type -> Type))) |
data LogicalTypeLong Source #
Constructors
DecimalL Decimal | An arbitrary-precision signed decimal number. See |
TimeMicros | A time of day with microsecond precision. Encoded as the number of microseconds after midnight. |
TimestampMillis | A UTC timestamp with millisecond precision. Encoded as the number of milliseconds before/after the Unix epoch (1970-01-01 00:00:00.000). |
TimestampMicros | A UTC timestamp with microsecond precision. Encoded as the number of microseconds before/after the Unix epoch (1970-01-01 00:00:00.000000). |
LocalTimestampMillis | A timestamp in the local timezone, whatever that happens to be, with millisecond precision. Encoded as the number of milliseconds before/after the Unix epoch (1970-01-01 00:00:00.000). |
LocalTimestampMicros | A timestamp in the local timezone, whatever that happens to be, with microsecond precision. Encoded as the number of microseconds before/after the Unix epoch (1970-01-01 00:00:00.000000). |
Instances
NFData LogicalTypeLong Source # | |||||
Defined in Data.Avro.Schema.Schema Methods rnf :: LogicalTypeLong -> () # | |||||
Generic LogicalTypeLong Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
Methods from :: LogicalTypeLong -> Rep LogicalTypeLong x # to :: Rep LogicalTypeLong x -> LogicalTypeLong # | |||||
Show LogicalTypeLong Source # | |||||
Defined in Data.Avro.Schema.Schema Methods showsPrec :: Int -> LogicalTypeLong -> ShowS # show :: LogicalTypeLong -> String # showList :: [LogicalTypeLong] -> ShowS # | |||||
Eq LogicalTypeLong Source # | |||||
Defined in Data.Avro.Schema.Schema Methods (==) :: LogicalTypeLong -> LogicalTypeLong -> Bool # (/=) :: LogicalTypeLong -> LogicalTypeLong -> Bool # | |||||
Ord LogicalTypeLong Source # | |||||
Defined in Data.Avro.Schema.Schema Methods compare :: LogicalTypeLong -> LogicalTypeLong -> Ordering # (<) :: LogicalTypeLong -> LogicalTypeLong -> Bool # (<=) :: LogicalTypeLong -> LogicalTypeLong -> Bool # (>) :: LogicalTypeLong -> LogicalTypeLong -> Bool # (>=) :: LogicalTypeLong -> LogicalTypeLong -> Bool # max :: LogicalTypeLong -> LogicalTypeLong -> LogicalTypeLong # min :: LogicalTypeLong -> LogicalTypeLong -> LogicalTypeLong # | |||||
Lift LogicalTypeLong Source # | |||||
Defined in Data.Avro.Deriving.Lift Methods lift :: Quote m => LogicalTypeLong -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => LogicalTypeLong -> Code m LogicalTypeLong # | |||||
type Rep LogicalTypeLong Source # | |||||
Defined in Data.Avro.Schema.Schema type Rep LogicalTypeLong = D1 ('MetaData "LogicalTypeLong" "Data.Avro.Schema.Schema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'False) ((C1 ('MetaCons "DecimalL" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Decimal)) :+: (C1 ('MetaCons "TimeMicros" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TimestampMillis" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "TimestampMicros" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "LocalTimestampMillis" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "LocalTimestampMicros" 'PrefixI 'False) (U1 :: Type -> Type)))) |
data LogicalTypeString Source #
Constructors
UUID | A Universally Unique Identifier (UUID). Encoded as a string that is valid according to RFC 4122. |
Instances
NFData LogicalTypeString Source # | |||||
Defined in Data.Avro.Schema.Schema Methods rnf :: LogicalTypeString -> () # | |||||
Generic LogicalTypeString Source # | |||||
Defined in Data.Avro.Schema.Schema Associated Types
Methods from :: LogicalTypeString -> Rep LogicalTypeString x # to :: Rep LogicalTypeString x -> LogicalTypeString # | |||||
Show LogicalTypeString Source # | |||||
Defined in Data.Avro.Schema.Schema Methods showsPrec :: Int -> LogicalTypeString -> ShowS # show :: LogicalTypeString -> String # showList :: [LogicalTypeString] -> ShowS # | |||||
Eq LogicalTypeString Source # | |||||
Defined in Data.Avro.Schema.Schema Methods (==) :: LogicalTypeString -> LogicalTypeString -> Bool # (/=) :: LogicalTypeString -> LogicalTypeString -> Bool # | |||||
Ord LogicalTypeString Source # | |||||
Defined in Data.Avro.Schema.Schema Methods compare :: LogicalTypeString -> LogicalTypeString -> Ordering # (<) :: LogicalTypeString -> LogicalTypeString -> Bool # (<=) :: LogicalTypeString -> LogicalTypeString -> Bool # (>) :: LogicalTypeString -> LogicalTypeString -> Bool # (>=) :: LogicalTypeString -> LogicalTypeString -> Bool # max :: LogicalTypeString -> LogicalTypeString -> LogicalTypeString # min :: LogicalTypeString -> LogicalTypeString -> LogicalTypeString # | |||||
Lift LogicalTypeString Source # | |||||
Defined in Data.Avro.Deriving.Lift Methods lift :: Quote m => LogicalTypeString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => LogicalTypeString -> Code m LogicalTypeString # | |||||
type Rep LogicalTypeString Source # | |||||
Deconflicting schemas
data ReadSchema Source #
This type represents a deconflicted version of a Schema
.
Schema resolution is described in Avro specification: https://avro.apache.org/docs/current/spec.html#Schema+Resolution
This library represents "normal" schema and "deconflicted" schema as different types to avoid confusion between these two usecases (we shouldn't serialise values with such schema) and to be able to accomodate some extra information that links between how data is supposed transformed between what reader wants and what writer has.
Instances
NFData ReadSchema Source # | |||||
Defined in Data.Avro.Schema.ReadSchema Methods rnf :: ReadSchema -> () # | |||||
Generic ReadSchema Source # | |||||
Defined in Data.Avro.Schema.ReadSchema Associated Types
| |||||
Show ReadSchema Source # | |||||
Defined in Data.Avro.Schema.ReadSchema Methods showsPrec :: Int -> ReadSchema -> ShowS # show :: ReadSchema -> String # showList :: [ReadSchema] -> ShowS # | |||||
Eq ReadSchema Source # | |||||
Defined in Data.Avro.Schema.ReadSchema | |||||
type Rep ReadSchema Source # | |||||
Defined in Data.Avro.Schema.ReadSchema type Rep ReadSchema = D1 ('MetaData "ReadSchema" "Data.Avro.Schema.ReadSchema" "avro-0.6.2.1-34TenvYazigIdabKYuTk4O" 'False) ((((C1 ('MetaCons "Null" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Boolean" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Int" 'PrefixI 'True) (S1 ('MetaSel ('Just "logicalTypeI") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe LogicalTypeInt))) :+: C1 ('MetaCons "Long" 'PrefixI 'True) (S1 ('MetaSel ('Just "longReadFrom") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReadLong) :*: S1 ('MetaSel ('Just "logicalTypeL") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe LogicalTypeLong))))) :+: ((C1 ('MetaCons "Float" 'PrefixI 'True) (S1 ('MetaSel ('Just "floatReadFrom") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReadFloat)) :+: C1 ('MetaCons "Double" 'PrefixI 'True) (S1 ('MetaSel ('Just "doubleReadFrom") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReadDouble))) :+: (C1 ('MetaCons "Bytes" 'PrefixI 'True) (S1 ('MetaSel ('Just "logicalTypeB") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe LogicalTypeBytes))) :+: C1 ('MetaCons "String" 'PrefixI 'True) (S1 ('MetaSel ('Just "logicalTypeS") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe LogicalTypeString)))))) :+: (((C1 ('MetaCons "Array" 'PrefixI 'True) (S1 ('MetaSel ('Just "item") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReadSchema)) :+: C1 ('MetaCons "Map" 'PrefixI 'True) (S1 ('MetaSel ('Just "values") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReadSchema))) :+: (C1 ('MetaCons "NamedType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TypeName)) :+: C1 ('MetaCons "Record" 'PrefixI 'True) ((S1 ('MetaSel ('Just "name") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TypeName) :*: S1 ('MetaSel ('Just "aliases") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeName])) :*: (S1 ('MetaSel ('Just "doc") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "fields") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ReadField]))))) :+: ((C1 ('MetaCons "Enum" 'PrefixI 'True) ((S1 ('MetaSel ('Just "name") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TypeName) :*: S1 ('MetaSel ('Just "aliases") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeName])) :*: (S1 ('MetaSel ('Just "doc") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "symbols") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Vector Text)))) :+: C1 ('MetaCons "Union" 'PrefixI 'True) (S1 ('MetaSel ('Just "options") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Vector (Int, ReadSchema))))) :+: (C1 ('MetaCons "Fixed" 'PrefixI 'True) ((S1 ('MetaSel ('Just "name") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TypeName) :*: S1 ('MetaSel ('Just "aliases") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeName])) :*: (S1 ('MetaSel ('Just "size") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "logicalTypeF") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe LogicalTypeFixed)))) :+: C1 ('MetaCons "FreeUnion" 'PrefixI 'True) (S1 ('MetaSel ('Just "pos") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "ty") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReadSchema)))))) |
deconflict :: Schema -> Schema -> Either String ReadSchema Source #
deconflict writer reader
will produce a schema that can decode
with the writer's schema into the form specified by the reader's schema.
Schema resolution rules are described by the specification: https://avro.apache.org/docs/current/spec.html#Schema+Resolution
readSchemaFromSchema :: Schema -> ReadSchema Source #
Converts Schema
into ReadSchema
. This function may be useful when it is known
that the writer and the reader schemas are the same.
Individual values
encodeValue :: (HasAvroSchema a, ToAvro a) => a -> ByteString Source #
Serialises an individual value into Avro using the schema
from its coresponding HasAvroSchema
instance.
encodeValueWithSchema :: ToAvro a => Schema -> a -> ByteString Source #
Serialises an individual value into Avro with the schema provided.
decodeValue :: (HasAvroSchema a, FromAvro a) => ByteString -> Either String a Source #
Deserialises an individual value from Avro using the schema from its coresponding HasAvroSchema
.
NOTE: This function is only to be used when reader and writes schemas are known to be the same. Because only one schema is known at this point, and it is the reader schema, no decondlicting can be performed.
decodeValueWithSchema :: FromAvro a => ReadSchema -> ByteString -> Either String a Source #
Deserialises an individual value from Avro.
Working with containers
Decoding containers
decodeContainer :: (HasAvroSchema a, FromAvro a) => ByteString -> [Either String a] Source #
Decodes the container using a schema from HasAvroSchema
as a reader schema.
Errors are reported as a part of the list and the list will stop at first error. This means that the consumer will get all the "good" content from the container until the error is detected, then this error and then the list is finished.
decodeContainerWithEmbeddedSchema :: FromAvro a => ByteString -> [Either String a] Source #
Decodes the container as a list of values of the requested type.
Errors are reported as a part of the list and the list will stop at first error. This means that the consumer will get all the "good" content from the container until the error is detected, then this error and then the list is finished.
decodeContainerWithReaderSchema :: FromAvro a => Schema -> ByteString -> [Either String a] Source #
Decodes the container as a list of values of the requested type.
The provided reader schema will be de-conflicted with the schema embedded with the container.
Errors are reported as a part of the list and the list will stop at first error. This means that the consumer will get all the "good" content from the container until the error is detected, then this error and then the list is finished.
encodeContainer :: (HasAvroSchema a, ToAvro a) => Codec -> [[a]] -> IO ByteString Source #
Encode chunks of values into a container, using 16 random bytes for
the synchronization markers and a corresponding HasAvroSchema
schema.
Blocks are compressed (or not) according to the given Codec
(nullCodec
or deflateCodec
).
encodeContainerWithSchema :: ToAvro a => Codec -> Schema -> [[a]] -> IO ByteString Source #
Encode chunks of values into a container, using 16 random bytes for
the synchronization markers. Blocks are compressed (or not) according
to the given Codec
(nullCodec
or deflateCodec
).
encodeContainerWithSync :: ToAvro a => Codec -> Schema -> ByteString -> [[a]] -> ByteString Source #
Encode chunks of objects into a container, using the provided ByteString as the synchronization markers.
newSyncBytes :: IO ByteString Source #
Generates a new synchronization marker for encoding Avro containers
Extracting containers' data
extractContainerValuesBytes :: ByteString -> Either String (Schema, [Either String ByteString]) Source #
Splits container into a list of individual avro-encoded values.
This is particularly useful when slicing up containers into one or more smaller files. By extracting the original bytestring it is possible to avoid re-encoding data.
decodeContainerValuesBytes :: FromAvro a => Schema -> ByteString -> Either String (Schema, [Either String (a, ByteString)]) Source #
Splits container into a list of individual avro-encoded values. This version provides both encoded and decoded values.
This is particularly useful when slicing up containers into one or more smaller files. By extracting the original bytestring it is possible to avoid re-encoding data.
Classes
Describes how to encode Haskell data types into Avro bytes
Minimal complete definition
Instances
ToAvro ByteString Source # | |
Defined in Data.Avro.Encoding.ToAvro | |
ToAvro ByteString Source # | |
Defined in Data.Avro.Encoding.ToAvro | |
ToAvro Int32 Source # | |
ToAvro Int64 Source # | |
ToAvro Word16 Source # | |
ToAvro Word32 Source # | |
ToAvro Word64 Source # | |
ToAvro Word8 Source # | |
ToAvro Text Source # | |
ToAvro Text Source # | |
ToAvro Day Source # | |
ToAvro DiffTime Source # | |
ToAvro UTCTime Source # | |
ToAvro LocalTime Source # | |
ToAvro UUID Source # | |
ToAvro () Source # | |
ToAvro Bool Source # | |
ToAvro Double Source # | |
ToAvro Float Source # | |
ToAvro Int Source # | |
ToAvro a => ToAvro (Identity a) Source # | |
ToAvro a => ToAvro (Vector a) Source # | |
(Unbox a, ToAvro a) => ToAvro (Vector a) Source # | |
ToAvro a => ToAvro (Maybe a) Source # | |
ToAvro a => ToAvro [a] Source # | |
(KnownNat p, KnownNat s) => ToAvro (Decimal p s) Source # | |
ToAvro a => ToAvro (Map Text a) Source # | |
(Ix i, ToAvro a) => ToAvro (Array i a) Source # | |
(ToAvro a, ToAvro b) => ToAvro (Either a b) Source # | |
ToAvro a => ToAvro (HashMap Text a) Source # | |
(ToAvro a, ToAvro b, ToAvro c) => ToAvro (Either3 a b c) Source # | |
(ToAvro a, ToAvro b, ToAvro c, ToAvro d) => ToAvro (Either4 a b c d) Source # | |
(ToAvro a, ToAvro b, ToAvro c, ToAvro d, ToAvro e) => ToAvro (Either5 a b c d e) Source # | |
(ToAvro a, ToAvro b, ToAvro c, ToAvro d, ToAvro e, ToAvro f) => ToAvro (Either6 a b c d e f) Source # | |
(ToAvro a, ToAvro b, ToAvro c, ToAvro d, ToAvro e, ToAvro f, ToAvro g) => ToAvro (Either7 a b c d e f g) Source # | |
(ToAvro a, ToAvro b, ToAvro c, ToAvro d, ToAvro e, ToAvro f, ToAvro g, ToAvro h) => ToAvro (Either8 a b c d e f g h) Source # | |
(ToAvro a, ToAvro b, ToAvro c, ToAvro d, ToAvro e, ToAvro f, ToAvro g, ToAvro h, ToAvro i) => ToAvro (Either9 a b c d e f g h i) Source # | |
(ToAvro a, ToAvro b, ToAvro c, ToAvro d, ToAvro e, ToAvro f, ToAvro g, ToAvro h, ToAvro i, ToAvro j) => ToAvro (Either10 a b c d e f g h i j) Source # | |
Descrives how to convert a given intermediate Value
into a Haskell data type.
Minimal complete definition
Instances
FromAvro ByteString Source # | |
Defined in Data.Avro.Encoding.FromAvro | |
FromAvro ByteString Source # | |
Defined in Data.Avro.Encoding.FromAvro | |
FromAvro Int32 Source # | |
FromAvro Int64 Source # | |
FromAvro Text Source # | |
FromAvro Day Source # | |
FromAvro DiffTime Source # | |
FromAvro UTCTime Source # | |
FromAvro LocalTime Source # | |
FromAvro UUID Source # | |
FromAvro () Source # | |
FromAvro Bool Source # | |
FromAvro Double Source # | |
FromAvro Float Source # | |
FromAvro Int Source # | |
FromAvro a => FromAvro (Identity a) Source # | |
FromAvro a => FromAvro (Vector a) Source # | |
(Unbox a, FromAvro a) => FromAvro (Vector a) Source # | |
FromAvro a => FromAvro (Maybe a) Source # | |
FromAvro a => FromAvro [a] Source # | |
(KnownNat p, KnownNat s) => FromAvro (Decimal p s) Source # | |
FromAvro a => FromAvro (Map Text a) Source # | |
(FromAvro a, FromAvro b) => FromAvro (Either a b) Source # | |
FromAvro a => FromAvro (HashMap Text a) Source # | |
(FromAvro a, FromAvro b, FromAvro c) => FromAvro (Either3 a b c) Source # | |
(FromAvro a, FromAvro b, FromAvro c, FromAvro d) => FromAvro (Either4 a b c d) Source # | |
(FromAvro a, FromAvro b, FromAvro c, FromAvro d, FromAvro e) => FromAvro (Either5 a b c d e) Source # | |
(FromAvro a, FromAvro b, FromAvro c, FromAvro d, FromAvro e, FromAvro f) => FromAvro (Either6 a b c d e f) Source # | |
(FromAvro a, FromAvro b, FromAvro c, FromAvro d, FromAvro e, FromAvro f, FromAvro g) => FromAvro (Either7 a b c d e f g) Source # | |
(FromAvro a, FromAvro b, FromAvro c, FromAvro d, FromAvro e, FromAvro f, FromAvro g, FromAvro h) => FromAvro (Either8 a b c d e f g h) Source # | |
(FromAvro a, FromAvro b, FromAvro c, FromAvro d, FromAvro e, FromAvro f, FromAvro g, FromAvro h, FromAvro i) => FromAvro (Either9 a b c d e f g h i) Source # | |
(FromAvro a, FromAvro b, FromAvro c, FromAvro d, FromAvro e, FromAvro f, FromAvro g, FromAvro h, FromAvro i, FromAvro j) => FromAvro (Either10 a b c d e f g h i j) Source # | |
Compression
A Codec
allows for compression/decompression of a block in an
Avro container according to the Avro spec.
nullCodec
specifies null
required by Avro spec.
(see https://avro.apache.org/docs/1.8.1/spec.html#null)
deflateCodec :: Codec Source #
deflateCodec
specifies deflate
codec required by Avro spec.
(see https://avro.apache.org/docs/1.8.1/spec.html#deflate)
class HasAvroSchema a where Source #
Instances
HasAvroSchema ByteString Source # | |
Defined in Data.Avro.HasAvroSchema | |
HasAvroSchema ByteString Source # | |
Defined in Data.Avro.HasAvroSchema | |
HasAvroSchema Int16 Source # | |
HasAvroSchema Int32 Source # | |
HasAvroSchema Int64 Source # | |
HasAvroSchema Int8 Source # | |
HasAvroSchema Word16 Source # | |
HasAvroSchema Word32 Source # | |
HasAvroSchema Word64 Source # | |
HasAvroSchema Word8 Source # | |
HasAvroSchema Text Source # | |
HasAvroSchema Text Source # | |
HasAvroSchema Day Source # | |
HasAvroSchema DiffTime Source # | |
HasAvroSchema UTCTime Source # | |
HasAvroSchema LocalTime Source # | |
HasAvroSchema UUID Source # | |
HasAvroSchema () Source # | |
HasAvroSchema Bool Source # | |
HasAvroSchema Double Source # | |
HasAvroSchema Float Source # | |
HasAvroSchema Int Source # | |
HasAvroSchema a => HasAvroSchema (Set a) Source # | |
HasAvroSchema a => HasAvroSchema (Identity a) Source # | |
HasAvroSchema a => HasAvroSchema (Vector a) Source # | |
HasAvroSchema a => HasAvroSchema (Vector a) Source # | |
HasAvroSchema a => HasAvroSchema (Maybe a) Source # | |
HasAvroSchema a => HasAvroSchema [a] Source # | |
(KnownNat p, KnownNat s) => HasAvroSchema (Decimal p s) Source # | |
HasAvroSchema a => HasAvroSchema (Map Text a) Source # | |
HasAvroSchema a => HasAvroSchema (Map Text a) Source # | |
HasAvroSchema a => HasAvroSchema (Map String a) Source # | |
(HasAvroSchema a, Ix i) => HasAvroSchema (Array i a) Source # | |
(HasAvroSchema a, HasAvroSchema b) => HasAvroSchema (Either a b) Source # | |
HasAvroSchema a => HasAvroSchema (HashMap Text a) Source # | |
HasAvroSchema a => HasAvroSchema (HashMap Text a) Source # | |
HasAvroSchema a => HasAvroSchema (HashMap String a) Source # | |
(HasAvroSchema a, HasAvroSchema b, HasAvroSchema c) => HasAvroSchema (Either3 a b c) Source # | |
(HasAvroSchema a, HasAvroSchema b, HasAvroSchema c, HasAvroSchema d) => HasAvroSchema (Either4 a b c d) Source # | |
(HasAvroSchema a, HasAvroSchema b, HasAvroSchema c, HasAvroSchema d, HasAvroSchema e) => HasAvroSchema (Either5 a b c d e) Source # | |
(HasAvroSchema a, HasAvroSchema b, HasAvroSchema c, HasAvroSchema d, HasAvroSchema e, HasAvroSchema f) => HasAvroSchema (Either6 a b c d e f) Source # | |
(HasAvroSchema a, HasAvroSchema b, HasAvroSchema c, HasAvroSchema d, HasAvroSchema e, HasAvroSchema f, HasAvroSchema g) => HasAvroSchema (Either7 a b c d e f g) Source # | |
(HasAvroSchema a, HasAvroSchema b, HasAvroSchema c, HasAvroSchema d, HasAvroSchema e, HasAvroSchema f, HasAvroSchema g, HasAvroSchema h) => HasAvroSchema (Either8 a b c d e f g h) Source # | |
(HasAvroSchema a, HasAvroSchema b, HasAvroSchema c, HasAvroSchema d, HasAvroSchema e, HasAvroSchema f, HasAvroSchema g, HasAvroSchema h, HasAvroSchema i) => HasAvroSchema (Either9 a b c d e f g h i) Source # | |
(HasAvroSchema a, HasAvroSchema b, HasAvroSchema c, HasAvroSchema d, HasAvroSchema e, HasAvroSchema f, HasAvroSchema g, HasAvroSchema h, HasAvroSchema i, HasAvroSchema j) => HasAvroSchema (Either10 a b c d e f g h i j) Source # | |
schemaOf :: HasAvroSchema a => a -> Schema Source #