avro 0.6.1.1 → 0.6.1.2
raw patch · 5 files changed
+32/−12 lines, 5 filesdep ~HasBigDecimalPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: HasBigDecimal
API changes (from Hackage documentation)
- Data.Avro.Internal.Zag: type family Zagged a;
- Data.Avro.Internal.Zig: type family Zigged a;
- Data.Avro.Schema.Decimal: Decimal :: BigDecimal -> Decimal (p :: Nat) (s :: Nat)
- Data.Avro.Schema.Decimal: [unDecimal] :: Decimal (p :: Nat) (s :: Nat) -> BigDecimal
- Data.Avro.Schema.Decimal: newtype Decimal (p :: Nat) (s :: Nat)
+ Data.Avro.Internal.Zag: type Zagged a;
+ Data.Avro.Internal.Zig: type Zigged a;
+ Data.Avro.Schema.Decimal: data Decimal (p :: Nat) (s :: Nat)
+ Data.Avro.Schema.Schema: typeAliases :: Schema -> [TypeName]
Files
- README.md +1/−1
- avro.cabal +2/−2
- src/Data/Avro/Schema/Decimal.hs +14/−7
- src/Data/Avro/Schema/Deconflict.hs +5/−2
- src/Data/Avro/Schema/Schema.hs +10/−0
README.md view
@@ -29,7 +29,7 @@ { "name": "fullName", "type": "string" }, { "name": "age", "type": "int" }, { "name": "gender",- "type": { "type": "enum", "symbols": ["Male", "Female"] }+ "type": { "name": "Gender", "type": "enum", "symbols": ["Male", "Female"] } }, { "name": "ssn", "type": ["null", "string"] } ]
avro.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4 name: avro-version: 0.6.1.1+version: 0.6.1.2 synopsis: Avro serialization support for Haskell description: Avro serialization and deserialization support for Haskell category: Data@@ -50,7 +50,7 @@ common array { build-depends: array } common base16-bytestring { build-depends: base16-bytestring } common bifunctors { build-depends: bifunctors }-common big-decimal { build-depends: HasBigDecimal }+common big-decimal { build-depends: HasBigDecimal >= 0.2 && < 0.3 } common binary { build-depends: binary } common bytestring { build-depends: bytestring } common containers { build-depends: containers }
src/Data/Avro/Schema/Decimal.hs view
@@ -3,7 +3,11 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-}-module Data.Avro.Schema.Decimal where+module Data.Avro.Schema.Decimal+( Decimal+, fromUnderlyingValue+, underlyingValue )+where import qualified Data.BigDecimal as D import Data.Proxy@@ -13,11 +17,14 @@ = Decimal { unDecimal :: D.BigDecimal } deriving (Eq, Ord, Show, Read, Num, Fractional, Real) +intScale :: D.BigDecimal -> Integer+intScale = toInteger . D.scale+ fromUnderlyingValue :: forall p s. KnownNat s => Integer -> Decimal p s fromUnderlyingValue n- = Decimal $ D.BigDecimal n (natVal (Proxy :: Proxy s))+ = Decimal $ D.BigDecimal n (fromIntegral $ natVal (Proxy :: Proxy s)) underlyingValue :: forall s p. (KnownNat p, KnownNat s)@@ -25,9 +32,9 @@ underlyingValue (Decimal d) = let ss = natVal (Proxy :: Proxy s) pp = natVal (Proxy :: Proxy p)- new = if ss > D.getScale d- then D.BigDecimal (D.getValue d * 10 ^ (ss - D.getScale d)) ss- else D.roundBD d (D.halfUp ss)- in if D.precision new > pp+ new = if ss > intScale d+ then D.BigDecimal (D.value d * 10 ^ (ss - intScale d)) (fromIntegral ss)+ else D.roundBD d (D.halfUp (fromIntegral ss))+ in if D.precision new > fromIntegral pp then Nothing- else Just $ fromInteger $ D.getValue new+ else Just $ fromInteger $ D.value new
src/Data/Avro/Schema/Deconflict.hs view
@@ -76,7 +76,7 @@ } deconflict w@S.Record {} r@S.Record {}- | name w == name r = do+ | name w == name r || name w `elem` aliases r = do fields' <- deconflictFields (fields w) (fields r) pure Read.Record { Read.name = name r@@ -138,4 +138,7 @@ findTypeV :: Schema -> Vector Schema -> Maybe (Int, Schema) findTypeV schema schemas = let tn = typeName schema- in ((,) <$> id <*> V.unsafeIndex schemas) <$> V.findIndex ((tn ==) . typeName) schemas+ allNames typ =+ typeName typ : map renderFullname (typeAliases typ)+ in ((,) <$> id <*> V.unsafeIndex schemas) <$>+ V.findIndex ((tn `elem`) . allNames) schemas
src/Data/Avro/Schema/Schema.hs view
@@ -37,6 +37,7 @@ , validateSchema -- * Lower level utilities , typeName+ , typeAliases , buildTypeEnvironment , extractBindings @@ -495,6 +496,15 @@ _ -> renderFullname $ name bt where decimalName (Decimal prec sc) = "decimal(" <> T.pack (show prec) <> "," <> T.pack (show sc) <> ")"++-- |Get the aliases of the type.+typeAliases :: Schema -> [TypeName]+typeAliases bt =+ case bt of+ Record { aliases } -> aliases+ Enum { aliases} -> aliases+ Fixed { aliases } -> aliases+ _ -> [] instance FromJSON Schema where parseJSON = parseSchemaJSON Nothing