{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
module Data.Avro.Schema.ReadSchema
( ReadSchema(..), ReadField(..)
, ReadLong(..), ReadFloat(..), ReadDouble(..)
, fromSchema, fromField
, extractBindings
, S.Decimal(..)
, S.LogicalTypeBytes(..), S.LogicalTypeFixed(..)
, S.LogicalTypeInt(..), S.LogicalTypeLong(..)
, S.LogicalTypeString(..)
, FieldStatus(..)
)
where
import Control.DeepSeq (NFData)
import Data.Avro.Schema.Schema (LogicalTypeBytes, LogicalTypeFixed, LogicalTypeInt, LogicalTypeLong, LogicalTypeString, Order, TypeName)
import qualified Data.Avro.Schema.Schema as S
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Vector as V
import GHC.Generics (Generic)
data ReadLong
= LongFromInt
| ReadLong
deriving (Int -> ReadLong -> ShowS
[ReadLong] -> ShowS
ReadLong -> String
(Int -> ReadLong -> ShowS)
-> (ReadLong -> String) -> ([ReadLong] -> ShowS) -> Show ReadLong
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReadLong] -> ShowS
$cshowList :: [ReadLong] -> ShowS
show :: ReadLong -> String
$cshow :: ReadLong -> String
showsPrec :: Int -> ReadLong -> ShowS
$cshowsPrec :: Int -> ReadLong -> ShowS
Show, ReadLong -> ReadLong -> Bool
(ReadLong -> ReadLong -> Bool)
-> (ReadLong -> ReadLong -> Bool) -> Eq ReadLong
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReadLong -> ReadLong -> Bool
$c/= :: ReadLong -> ReadLong -> Bool
== :: ReadLong -> ReadLong -> Bool
$c== :: ReadLong -> ReadLong -> Bool
Eq, Eq ReadLong
Eq ReadLong
-> (ReadLong -> ReadLong -> Ordering)
-> (ReadLong -> ReadLong -> Bool)
-> (ReadLong -> ReadLong -> Bool)
-> (ReadLong -> ReadLong -> Bool)
-> (ReadLong -> ReadLong -> Bool)
-> (ReadLong -> ReadLong -> ReadLong)
-> (ReadLong -> ReadLong -> ReadLong)
-> Ord ReadLong
ReadLong -> ReadLong -> Bool
ReadLong -> ReadLong -> Ordering
ReadLong -> ReadLong -> ReadLong
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ReadLong -> ReadLong -> ReadLong
$cmin :: ReadLong -> ReadLong -> ReadLong
max :: ReadLong -> ReadLong -> ReadLong
$cmax :: ReadLong -> ReadLong -> ReadLong
>= :: ReadLong -> ReadLong -> Bool
$c>= :: ReadLong -> ReadLong -> Bool
> :: ReadLong -> ReadLong -> Bool
$c> :: ReadLong -> ReadLong -> Bool
<= :: ReadLong -> ReadLong -> Bool
$c<= :: ReadLong -> ReadLong -> Bool
< :: ReadLong -> ReadLong -> Bool
$c< :: ReadLong -> ReadLong -> Bool
compare :: ReadLong -> ReadLong -> Ordering
$ccompare :: ReadLong -> ReadLong -> Ordering
$cp1Ord :: Eq ReadLong
Ord, (forall x. ReadLong -> Rep ReadLong x)
-> (forall x. Rep ReadLong x -> ReadLong) -> Generic ReadLong
forall x. Rep ReadLong x -> ReadLong
forall x. ReadLong -> Rep ReadLong x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReadLong x -> ReadLong
$cfrom :: forall x. ReadLong -> Rep ReadLong x
Generic, ReadLong -> ()
(ReadLong -> ()) -> NFData ReadLong
forall a. (a -> ()) -> NFData a
rnf :: ReadLong -> ()
$crnf :: ReadLong -> ()
NFData)
data ReadFloat
= FloatFromInt
| FloatFromLong
| ReadFloat
deriving (Int -> ReadFloat -> ShowS
[ReadFloat] -> ShowS
ReadFloat -> String
(Int -> ReadFloat -> ShowS)
-> (ReadFloat -> String)
-> ([ReadFloat] -> ShowS)
-> Show ReadFloat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReadFloat] -> ShowS
$cshowList :: [ReadFloat] -> ShowS
show :: ReadFloat -> String
$cshow :: ReadFloat -> String
showsPrec :: Int -> ReadFloat -> ShowS
$cshowsPrec :: Int -> ReadFloat -> ShowS
Show, ReadFloat -> ReadFloat -> Bool
(ReadFloat -> ReadFloat -> Bool)
-> (ReadFloat -> ReadFloat -> Bool) -> Eq ReadFloat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReadFloat -> ReadFloat -> Bool
$c/= :: ReadFloat -> ReadFloat -> Bool
== :: ReadFloat -> ReadFloat -> Bool
$c== :: ReadFloat -> ReadFloat -> Bool
Eq, Eq ReadFloat
Eq ReadFloat
-> (ReadFloat -> ReadFloat -> Ordering)
-> (ReadFloat -> ReadFloat -> Bool)
-> (ReadFloat -> ReadFloat -> Bool)
-> (ReadFloat -> ReadFloat -> Bool)
-> (ReadFloat -> ReadFloat -> Bool)
-> (ReadFloat -> ReadFloat -> ReadFloat)
-> (ReadFloat -> ReadFloat -> ReadFloat)
-> Ord ReadFloat
ReadFloat -> ReadFloat -> Bool
ReadFloat -> ReadFloat -> Ordering
ReadFloat -> ReadFloat -> ReadFloat
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ReadFloat -> ReadFloat -> ReadFloat
$cmin :: ReadFloat -> ReadFloat -> ReadFloat
max :: ReadFloat -> ReadFloat -> ReadFloat
$cmax :: ReadFloat -> ReadFloat -> ReadFloat
>= :: ReadFloat -> ReadFloat -> Bool
$c>= :: ReadFloat -> ReadFloat -> Bool
> :: ReadFloat -> ReadFloat -> Bool
$c> :: ReadFloat -> ReadFloat -> Bool
<= :: ReadFloat -> ReadFloat -> Bool
$c<= :: ReadFloat -> ReadFloat -> Bool
< :: ReadFloat -> ReadFloat -> Bool
$c< :: ReadFloat -> ReadFloat -> Bool
compare :: ReadFloat -> ReadFloat -> Ordering
$ccompare :: ReadFloat -> ReadFloat -> Ordering
$cp1Ord :: Eq ReadFloat
Ord, (forall x. ReadFloat -> Rep ReadFloat x)
-> (forall x. Rep ReadFloat x -> ReadFloat) -> Generic ReadFloat
forall x. Rep ReadFloat x -> ReadFloat
forall x. ReadFloat -> Rep ReadFloat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReadFloat x -> ReadFloat
$cfrom :: forall x. ReadFloat -> Rep ReadFloat x
Generic, ReadFloat -> ()
(ReadFloat -> ()) -> NFData ReadFloat
forall a. (a -> ()) -> NFData a
rnf :: ReadFloat -> ()
$crnf :: ReadFloat -> ()
NFData)
data ReadDouble
= DoubleFromInt
| DoubleFromFloat
| DoubleFromLong
| ReadDouble
deriving (Int -> ReadDouble -> ShowS
[ReadDouble] -> ShowS
ReadDouble -> String
(Int -> ReadDouble -> ShowS)
-> (ReadDouble -> String)
-> ([ReadDouble] -> ShowS)
-> Show ReadDouble
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReadDouble] -> ShowS
$cshowList :: [ReadDouble] -> ShowS
show :: ReadDouble -> String
$cshow :: ReadDouble -> String
showsPrec :: Int -> ReadDouble -> ShowS
$cshowsPrec :: Int -> ReadDouble -> ShowS
Show, ReadDouble -> ReadDouble -> Bool
(ReadDouble -> ReadDouble -> Bool)
-> (ReadDouble -> ReadDouble -> Bool) -> Eq ReadDouble
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReadDouble -> ReadDouble -> Bool
$c/= :: ReadDouble -> ReadDouble -> Bool
== :: ReadDouble -> ReadDouble -> Bool
$c== :: ReadDouble -> ReadDouble -> Bool
Eq, Eq ReadDouble
Eq ReadDouble
-> (ReadDouble -> ReadDouble -> Ordering)
-> (ReadDouble -> ReadDouble -> Bool)
-> (ReadDouble -> ReadDouble -> Bool)
-> (ReadDouble -> ReadDouble -> Bool)
-> (ReadDouble -> ReadDouble -> Bool)
-> (ReadDouble -> ReadDouble -> ReadDouble)
-> (ReadDouble -> ReadDouble -> ReadDouble)
-> Ord ReadDouble
ReadDouble -> ReadDouble -> Bool
ReadDouble -> ReadDouble -> Ordering
ReadDouble -> ReadDouble -> ReadDouble
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ReadDouble -> ReadDouble -> ReadDouble
$cmin :: ReadDouble -> ReadDouble -> ReadDouble
max :: ReadDouble -> ReadDouble -> ReadDouble
$cmax :: ReadDouble -> ReadDouble -> ReadDouble
>= :: ReadDouble -> ReadDouble -> Bool
$c>= :: ReadDouble -> ReadDouble -> Bool
> :: ReadDouble -> ReadDouble -> Bool
$c> :: ReadDouble -> ReadDouble -> Bool
<= :: ReadDouble -> ReadDouble -> Bool
$c<= :: ReadDouble -> ReadDouble -> Bool
< :: ReadDouble -> ReadDouble -> Bool
$c< :: ReadDouble -> ReadDouble -> Bool
compare :: ReadDouble -> ReadDouble -> Ordering
$ccompare :: ReadDouble -> ReadDouble -> Ordering
$cp1Ord :: Eq ReadDouble
Ord, (forall x. ReadDouble -> Rep ReadDouble x)
-> (forall x. Rep ReadDouble x -> ReadDouble) -> Generic ReadDouble
forall x. Rep ReadDouble x -> ReadDouble
forall x. ReadDouble -> Rep ReadDouble x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReadDouble x -> ReadDouble
$cfrom :: forall x. ReadDouble -> Rep ReadDouble x
Generic, ReadDouble -> ()
(ReadDouble -> ()) -> NFData ReadDouble
forall a. (a -> ()) -> NFData a
rnf :: ReadDouble -> ()
$crnf :: ReadDouble -> ()
NFData)
data ReadSchema
=
Null
| Boolean
| Int { ReadSchema -> Maybe LogicalTypeInt
logicalTypeI :: Maybe LogicalTypeInt }
| Long { ReadSchema -> ReadLong
longReadFrom :: ReadLong, ReadSchema -> Maybe LogicalTypeLong
logicalTypeL :: Maybe LogicalTypeLong }
| Float { ReadSchema -> ReadFloat
floatReadFrom :: ReadFloat }
| Double { ReadSchema -> ReadDouble
doubleReadFrom :: ReadDouble }
| Bytes { ReadSchema -> Maybe LogicalTypeBytes
logicalTypeB :: Maybe LogicalTypeBytes }
| String { ReadSchema -> Maybe LogicalTypeString
logicalTypeS :: Maybe LogicalTypeString }
| Array { ReadSchema -> ReadSchema
item :: ReadSchema }
| Map { ReadSchema -> ReadSchema
values :: ReadSchema }
| NamedType TypeName
| Record { ReadSchema -> TypeName
name :: TypeName
, ReadSchema -> [TypeName]
aliases :: [TypeName]
, ReadSchema -> Maybe Text
doc :: Maybe Text
, ReadSchema -> [ReadField]
fields :: [ReadField]
}
| Enum { name :: TypeName
, aliases :: [TypeName]
, doc :: Maybe Text
, ReadSchema -> Vector Text
symbols :: V.Vector Text
}
| Union { ReadSchema -> Vector (Int, ReadSchema)
options :: V.Vector (Int, ReadSchema)
}
| Fixed { name :: TypeName
, aliases :: [TypeName]
, ReadSchema -> Int
size :: Int
, ReadSchema -> Maybe LogicalTypeFixed
logicalTypeF :: Maybe LogicalTypeFixed
}
| FreeUnion { ReadSchema -> Int
pos :: Int, ReadSchema -> ReadSchema
ty :: ReadSchema }
deriving (ReadSchema -> ReadSchema -> Bool
(ReadSchema -> ReadSchema -> Bool)
-> (ReadSchema -> ReadSchema -> Bool) -> Eq ReadSchema
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReadSchema -> ReadSchema -> Bool
$c/= :: ReadSchema -> ReadSchema -> Bool
== :: ReadSchema -> ReadSchema -> Bool
$c== :: ReadSchema -> ReadSchema -> Bool
Eq, Int -> ReadSchema -> ShowS
[ReadSchema] -> ShowS
ReadSchema -> String
(Int -> ReadSchema -> ShowS)
-> (ReadSchema -> String)
-> ([ReadSchema] -> ShowS)
-> Show ReadSchema
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReadSchema] -> ShowS
$cshowList :: [ReadSchema] -> ShowS
show :: ReadSchema -> String
$cshow :: ReadSchema -> String
showsPrec :: Int -> ReadSchema -> ShowS
$cshowsPrec :: Int -> ReadSchema -> ShowS
Show, (forall x. ReadSchema -> Rep ReadSchema x)
-> (forall x. Rep ReadSchema x -> ReadSchema) -> Generic ReadSchema
forall x. Rep ReadSchema x -> ReadSchema
forall x. ReadSchema -> Rep ReadSchema x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReadSchema x -> ReadSchema
$cfrom :: forall x. ReadSchema -> Rep ReadSchema x
Generic, ReadSchema -> ()
(ReadSchema -> ()) -> NFData ReadSchema
forall a. (a -> ()) -> NFData a
rnf :: ReadSchema -> ()
$crnf :: ReadSchema -> ()
NFData)
data FieldStatus
= AsIs Int
| Ignored
| Defaulted Int S.DefaultValue
deriving (Int -> FieldStatus -> ShowS
[FieldStatus] -> ShowS
FieldStatus -> String
(Int -> FieldStatus -> ShowS)
-> (FieldStatus -> String)
-> ([FieldStatus] -> ShowS)
-> Show FieldStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldStatus] -> ShowS
$cshowList :: [FieldStatus] -> ShowS
show :: FieldStatus -> String
$cshow :: FieldStatus -> String
showsPrec :: Int -> FieldStatus -> ShowS
$cshowsPrec :: Int -> FieldStatus -> ShowS
Show, FieldStatus -> FieldStatus -> Bool
(FieldStatus -> FieldStatus -> Bool)
-> (FieldStatus -> FieldStatus -> Bool) -> Eq FieldStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldStatus -> FieldStatus -> Bool
$c/= :: FieldStatus -> FieldStatus -> Bool
== :: FieldStatus -> FieldStatus -> Bool
$c== :: FieldStatus -> FieldStatus -> Bool
Eq, Eq FieldStatus
Eq FieldStatus
-> (FieldStatus -> FieldStatus -> Ordering)
-> (FieldStatus -> FieldStatus -> Bool)
-> (FieldStatus -> FieldStatus -> Bool)
-> (FieldStatus -> FieldStatus -> Bool)
-> (FieldStatus -> FieldStatus -> Bool)
-> (FieldStatus -> FieldStatus -> FieldStatus)
-> (FieldStatus -> FieldStatus -> FieldStatus)
-> Ord FieldStatus
FieldStatus -> FieldStatus -> Bool
FieldStatus -> FieldStatus -> Ordering
FieldStatus -> FieldStatus -> FieldStatus
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FieldStatus -> FieldStatus -> FieldStatus
$cmin :: FieldStatus -> FieldStatus -> FieldStatus
max :: FieldStatus -> FieldStatus -> FieldStatus
$cmax :: FieldStatus -> FieldStatus -> FieldStatus
>= :: FieldStatus -> FieldStatus -> Bool
$c>= :: FieldStatus -> FieldStatus -> Bool
> :: FieldStatus -> FieldStatus -> Bool
$c> :: FieldStatus -> FieldStatus -> Bool
<= :: FieldStatus -> FieldStatus -> Bool
$c<= :: FieldStatus -> FieldStatus -> Bool
< :: FieldStatus -> FieldStatus -> Bool
$c< :: FieldStatus -> FieldStatus -> Bool
compare :: FieldStatus -> FieldStatus -> Ordering
$ccompare :: FieldStatus -> FieldStatus -> Ordering
$cp1Ord :: Eq FieldStatus
Ord, (forall x. FieldStatus -> Rep FieldStatus x)
-> (forall x. Rep FieldStatus x -> FieldStatus)
-> Generic FieldStatus
forall x. Rep FieldStatus x -> FieldStatus
forall x. FieldStatus -> Rep FieldStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FieldStatus x -> FieldStatus
$cfrom :: forall x. FieldStatus -> Rep FieldStatus x
Generic, FieldStatus -> ()
(FieldStatus -> ()) -> NFData FieldStatus
forall a. (a -> ()) -> NFData a
rnf :: FieldStatus -> ()
$crnf :: FieldStatus -> ()
NFData)
data ReadField = ReadField
{ ReadField -> Text
fldName :: Text
, ReadField -> [Text]
fldAliases :: [Text]
, ReadField -> Maybe Text
fldDoc :: Maybe Text
, ReadField -> Maybe Order
fldOrder :: Maybe Order
, ReadField -> FieldStatus
fldStatus :: FieldStatus
, ReadField -> ReadSchema
fldType :: ReadSchema
, ReadField -> Maybe DefaultValue
fldDefault :: Maybe S.DefaultValue
}
deriving (ReadField -> ReadField -> Bool
(ReadField -> ReadField -> Bool)
-> (ReadField -> ReadField -> Bool) -> Eq ReadField
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReadField -> ReadField -> Bool
$c/= :: ReadField -> ReadField -> Bool
== :: ReadField -> ReadField -> Bool
$c== :: ReadField -> ReadField -> Bool
Eq, Int -> ReadField -> ShowS
[ReadField] -> ShowS
ReadField -> String
(Int -> ReadField -> ShowS)
-> (ReadField -> String)
-> ([ReadField] -> ShowS)
-> Show ReadField
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReadField] -> ShowS
$cshowList :: [ReadField] -> ShowS
show :: ReadField -> String
$cshow :: ReadField -> String
showsPrec :: Int -> ReadField -> ShowS
$cshowsPrec :: Int -> ReadField -> ShowS
Show, (forall x. ReadField -> Rep ReadField x)
-> (forall x. Rep ReadField x -> ReadField) -> Generic ReadField
forall x. Rep ReadField x -> ReadField
forall x. ReadField -> Rep ReadField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReadField x -> ReadField
$cfrom :: forall x. ReadField -> Rep ReadField x
Generic, ReadField -> ()
(ReadField -> ()) -> NFData ReadField
forall a. (a -> ()) -> NFData a
rnf :: ReadField -> ()
$crnf :: ReadField -> ()
NFData)
fromSchema :: S.Schema -> ReadSchema
fromSchema :: Schema -> ReadSchema
fromSchema = \case
Schema
S.Null -> ReadSchema
Null
Schema
S.Boolean -> ReadSchema
Boolean
S.Int Maybe LogicalTypeInt
l -> Maybe LogicalTypeInt -> ReadSchema
Int Maybe LogicalTypeInt
l
S.Long Maybe LogicalTypeLong
l -> ReadLong -> Maybe LogicalTypeLong -> ReadSchema
Long ReadLong
ReadLong Maybe LogicalTypeLong
l
Schema
S.Float -> ReadFloat -> ReadSchema
Float ReadFloat
ReadFloat
Schema
S.Double -> ReadDouble -> ReadSchema
Double ReadDouble
ReadDouble
S.Bytes Maybe LogicalTypeBytes
l -> Maybe LogicalTypeBytes -> ReadSchema
Bytes Maybe LogicalTypeBytes
l
S.String Maybe LogicalTypeString
l -> Maybe LogicalTypeString -> ReadSchema
String Maybe LogicalTypeString
l
S.Array Schema
vs -> ReadSchema -> ReadSchema
Array (ReadSchema -> ReadSchema) -> ReadSchema -> ReadSchema
forall a b. (a -> b) -> a -> b
$ Schema -> ReadSchema
fromSchema Schema
vs
S.Map Schema
vs -> ReadSchema -> ReadSchema
Map (ReadSchema -> ReadSchema) -> ReadSchema -> ReadSchema
forall a b. (a -> b) -> a -> b
$ Schema -> ReadSchema
fromSchema Schema
vs
S.NamedType TypeName
v -> TypeName -> ReadSchema
NamedType TypeName
v
v :: Schema
v@S.Record{} -> Record :: TypeName -> [TypeName] -> Maybe Text -> [ReadField] -> ReadSchema
Record
{ name :: TypeName
name = Schema -> TypeName
S.name Schema
v
, aliases :: [TypeName]
aliases = Schema -> [TypeName]
S.aliases Schema
v
, doc :: Maybe Text
doc = Schema -> Maybe Text
S.doc Schema
v
, fields :: [ReadField]
fields = (\(Int
i, Field
x) -> FieldStatus -> Field -> ReadField
fromField (Int -> FieldStatus
AsIs Int
i) Field
x) ((Int, Field) -> ReadField) -> [(Int, Field)] -> [ReadField]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int] -> [Field] -> [(Int, Field)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] (Schema -> [Field]
S.fields Schema
v)
}
v :: Schema
v@S.Enum{} -> Enum :: TypeName -> [TypeName] -> Maybe Text -> Vector Text -> ReadSchema
Enum
{ name :: TypeName
name = Schema -> TypeName
S.name Schema
v
, aliases :: [TypeName]
aliases = Schema -> [TypeName]
S.aliases Schema
v
, doc :: Maybe Text
doc = Schema -> Maybe Text
S.doc Schema
v
, symbols :: Vector Text
symbols = Schema -> Vector Text
S.symbols Schema
v
}
S.Union Vector Schema
vs -> Vector (Int, ReadSchema) -> ReadSchema
Union (Vector (Int, ReadSchema) -> ReadSchema)
-> (Vector ReadSchema -> Vector (Int, ReadSchema))
-> Vector ReadSchema
-> ReadSchema
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector ReadSchema -> Vector (Int, ReadSchema)
forall a. Vector a -> Vector (Int, a)
V.indexed (Vector ReadSchema -> ReadSchema)
-> Vector ReadSchema -> ReadSchema
forall a b. (a -> b) -> a -> b
$ Schema -> ReadSchema
fromSchema (Schema -> ReadSchema) -> Vector Schema -> Vector ReadSchema
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector Schema
vs
v :: Schema
v@S.Fixed{} -> Fixed :: TypeName
-> [TypeName] -> Int -> Maybe LogicalTypeFixed -> ReadSchema
Fixed
{ name :: TypeName
name = Schema -> TypeName
S.name Schema
v
, aliases :: [TypeName]
aliases = Schema -> [TypeName]
S.aliases Schema
v
, size :: Int
size = Schema -> Int
S.size Schema
v
, logicalTypeF :: Maybe LogicalTypeFixed
logicalTypeF = Schema -> Maybe LogicalTypeFixed
S.logicalTypeF Schema
v
}
fromField :: FieldStatus -> S.Field -> ReadField
fromField :: FieldStatus -> Field -> ReadField
fromField FieldStatus
s Field
v = ReadField :: Text
-> [Text]
-> Maybe Text
-> Maybe Order
-> FieldStatus
-> ReadSchema
-> Maybe DefaultValue
-> ReadField
ReadField
{ fldName :: Text
fldName = Field -> Text
S.fldName Field
v
, fldAliases :: [Text]
fldAliases = Field -> [Text]
S.fldAliases Field
v
, fldDoc :: Maybe Text
fldDoc = Field -> Maybe Text
S.fldDoc Field
v
, fldOrder :: Maybe Order
fldOrder = Field -> Maybe Order
S.fldOrder Field
v
, fldStatus :: FieldStatus
fldStatus = FieldStatus
s
, fldType :: ReadSchema
fldType = Schema -> ReadSchema
fromSchema (Field -> Schema
S.fldType Field
v)
, fldDefault :: Maybe DefaultValue
fldDefault = Field -> Maybe DefaultValue
S.fldDefault Field
v
}
extractBindings :: ReadSchema -> HashMap.HashMap TypeName ReadSchema
= \case
t :: ReadSchema
t@Record{[TypeName]
[ReadField]
Maybe Text
TypeName
fields :: [ReadField]
doc :: Maybe Text
aliases :: [TypeName]
name :: TypeName
fields :: ReadSchema -> [ReadField]
doc :: ReadSchema -> Maybe Text
aliases :: ReadSchema -> [TypeName]
name :: ReadSchema -> TypeName
..} ->
let withRecord :: HashMap TypeName ReadSchema
withRecord = [(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema)
-> [(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema
forall a b. (a -> b) -> a -> b
$ (TypeName
name TypeName -> [TypeName] -> [TypeName]
forall a. a -> [a] -> [a]
: [TypeName]
aliases) [TypeName] -> [ReadSchema] -> [(TypeName, ReadSchema)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` ReadSchema -> [ReadSchema]
forall a. a -> [a]
repeat ReadSchema
t
in [HashMap TypeName ReadSchema] -> HashMap TypeName ReadSchema
forall k v. (Eq k, Hashable k) => [HashMap k v] -> HashMap k v
HashMap.unions ([HashMap TypeName ReadSchema] -> HashMap TypeName ReadSchema)
-> [HashMap TypeName ReadSchema] -> HashMap TypeName ReadSchema
forall a b. (a -> b) -> a -> b
$ HashMap TypeName ReadSchema
withRecord HashMap TypeName ReadSchema
-> [HashMap TypeName ReadSchema] -> [HashMap TypeName ReadSchema]
forall a. a -> [a] -> [a]
: (ReadSchema -> HashMap TypeName ReadSchema
extractBindings (ReadSchema -> HashMap TypeName ReadSchema)
-> (ReadField -> ReadSchema)
-> ReadField
-> HashMap TypeName ReadSchema
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReadField -> ReadSchema
fldType (ReadField -> HashMap TypeName ReadSchema)
-> [ReadField] -> [HashMap TypeName ReadSchema]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ReadField]
fields)
e :: ReadSchema
e@Enum{[TypeName]
Maybe Text
Vector Text
TypeName
symbols :: Vector Text
doc :: Maybe Text
aliases :: [TypeName]
name :: TypeName
symbols :: ReadSchema -> Vector Text
doc :: ReadSchema -> Maybe Text
aliases :: ReadSchema -> [TypeName]
name :: ReadSchema -> TypeName
..} -> [(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema)
-> [(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema
forall a b. (a -> b) -> a -> b
$ (TypeName
name TypeName -> [TypeName] -> [TypeName]
forall a. a -> [a] -> [a]
: [TypeName]
aliases) [TypeName] -> [ReadSchema] -> [(TypeName, ReadSchema)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` ReadSchema -> [ReadSchema]
forall a. a -> [a]
repeat ReadSchema
e
Union{Vector (Int, ReadSchema)
options :: Vector (Int, ReadSchema)
options :: ReadSchema -> Vector (Int, ReadSchema)
..} -> [HashMap TypeName ReadSchema] -> HashMap TypeName ReadSchema
forall k v. (Eq k, Hashable k) => [HashMap k v] -> HashMap k v
HashMap.unions ([HashMap TypeName ReadSchema] -> HashMap TypeName ReadSchema)
-> [HashMap TypeName ReadSchema] -> HashMap TypeName ReadSchema
forall a b. (a -> b) -> a -> b
$ Vector (HashMap TypeName ReadSchema)
-> [HashMap TypeName ReadSchema]
forall a. Vector a -> [a]
V.toList (Vector (HashMap TypeName ReadSchema)
-> [HashMap TypeName ReadSchema])
-> Vector (HashMap TypeName ReadSchema)
-> [HashMap TypeName ReadSchema]
forall a b. (a -> b) -> a -> b
$ ReadSchema -> HashMap TypeName ReadSchema
extractBindings (ReadSchema -> HashMap TypeName ReadSchema)
-> ((Int, ReadSchema) -> ReadSchema)
-> (Int, ReadSchema)
-> HashMap TypeName ReadSchema
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, ReadSchema) -> ReadSchema
forall a b. (a, b) -> b
snd ((Int, ReadSchema) -> HashMap TypeName ReadSchema)
-> Vector (Int, ReadSchema) -> Vector (HashMap TypeName ReadSchema)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector (Int, ReadSchema)
options
f :: ReadSchema
f@Fixed{Int
[TypeName]
Maybe LogicalTypeFixed
TypeName
logicalTypeF :: Maybe LogicalTypeFixed
size :: Int
aliases :: [TypeName]
name :: TypeName
logicalTypeF :: ReadSchema -> Maybe LogicalTypeFixed
size :: ReadSchema -> Int
aliases :: ReadSchema -> [TypeName]
name :: ReadSchema -> TypeName
..} -> [(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema)
-> [(TypeName, ReadSchema)] -> HashMap TypeName ReadSchema
forall a b. (a -> b) -> a -> b
$ (TypeName
name TypeName -> [TypeName] -> [TypeName]
forall a. a -> [a] -> [a]
: [TypeName]
aliases) [TypeName] -> [ReadSchema] -> [(TypeName, ReadSchema)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` ReadSchema -> [ReadSchema]
forall a. a -> [a]
repeat ReadSchema
f
Array{ReadSchema
item :: ReadSchema
item :: ReadSchema -> ReadSchema
..} -> ReadSchema -> HashMap TypeName ReadSchema
extractBindings ReadSchema
item
Map{ReadSchema
values :: ReadSchema
values :: ReadSchema -> ReadSchema
..} -> ReadSchema -> HashMap TypeName ReadSchema
extractBindings ReadSchema
values
ReadSchema
_ -> HashMap TypeName ReadSchema
forall k v. HashMap k v
HashMap.empty