Skip to content

Commit

Permalink
Support "date", "time_ms" and "timestamp_ms" logical types
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Feb 27, 2020
1 parent d16b0ce commit 847d57f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion language-avro.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: language-avro
version: 0.1.1.0
version: 0.1.2.0
synopsis: Language definition and parser for AVRO files.
description: Parser for the AVRO language specification, see README.md for more details.
homepage: https://github.com/kutyel/avro-parser-haskell#readme
Expand Down
3 changes: 3 additions & 0 deletions src/Language/Avro/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ parseSchema =
Null <$ (reserved "null" <|> reserved "void")
<|> Boolean <$ reserved "boolean"
<|> Int' <$ reserved "int"
<|> Int (Just Date) <$ reserved "date"
<|> Int (Just TimeMillis) <$ reserved "time_ms"
<|> Long' <$ reserved "long"
<|> Long . Just . DecimalL <$> parseDecimal
<|> Long (Just TimestampMillis) <$ reserved "timestamp_ms"
<|> Float <$ reserved "float"
<|> Double <$ reserved "double"
<|> Bytes' <$ reserved "bytes"
Expand Down
10 changes: 9 additions & 1 deletion test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ simpleRecord =
"record Person {",
"string name;",
"int age;",
"date birthday;",
"}"
]

Expand Down Expand Up @@ -111,6 +112,12 @@ main = hspec $ do
it "should parse decimal" $ do
parse parseDecimal "" "decimal(4)" `shouldParse` Decimal 4 0
parse parseDecimal "" "decimal(15,2)" `shouldParse` Decimal 15 2
it "should parse date" $
parse parseSchema "" "date" `shouldParse` Int (Just Date)
it "should parse time" $
parse parseSchema "" "time_ms" `shouldParse` Int (Just TimeMillis)
it "should parse timestamp" $
parse parseSchema "" "timestamp_ms" `shouldParse` Long (Just TimestampMillis)
it "should parse bytes" $
parse parseSchema "" "bytes" `shouldParse` Bytes'
it "should parse string" $
Expand Down Expand Up @@ -154,7 +161,8 @@ main = hspec $ do
Nothing -- docs are ignored for now...
Nothing -- order is ignored for now...
[ Field "name" [] Nothing Nothing String' Nothing,
Field "age" [] Nothing Nothing Int' Nothing
Field "age" [] Nothing Nothing Int' Nothing,
Field "birthday" [] Nothing Nothing (Int (Just Date)) Nothing
]
it "should parse complex records" $
parse parseSchema "" complexRecord
Expand Down

0 comments on commit 847d57f

Please sign in to comment.