Skip to content

Commit

Permalink
WIP: Add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineGagne committed Nov 8, 2023
1 parent 650d470 commit e7158c2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/parthenon_schema_lexer.xrl
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ word_type("struct") ->
reserved;
word_type("array") ->
reserved;
word_type("tinyint") ->
encoding;
word_type("smallint") ->
encoding;
word_type("int") ->
encoding;
word_type("string") ->
word_type("integer") ->
encoding;
word_type("bigint") ->
encoding;
word_type("float") ->
encoding;
word_type("double") ->
encoding;
word_type("boolean") ->
encoding;
word_type("string") ->
encoding;
word_type(_) ->
unreserved.

Expand Down
9 changes: 8 additions & 1 deletion src/parthenon_schema_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ with_lightweight_trim(F) ->
fun(Binary, Options) ->
F(parthenon_utils:lightweight_trim(Binary), Options)
end.

to_encoder(tinyint) ->
fun(Value, _Options) -> binary_to_integer(Value) end;
to_encoder(smallint) ->
fun(Value, _Options) -> binary_to_integer(Value) end;
to_encoder(int) ->
fun(Value, _Options) -> binary_to_integer(Value) end;
to_encoder(integer) ->
fun(Value, _Options) -> binary_to_integer(Value) end;
to_encoder(bigint) ->
fun(Value, _Options) -> binary_to_integer(Value) end;
to_encoder(float) ->
fun(Value, _Options) -> binary_to_float(Value) end;
to_encoder(double) ->
fun(Value, _Options) -> binary_to_float(Value) end;
to_encoder(boolean) ->
Expand Down
12 changes: 10 additions & 2 deletions test/parthenon_schema_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,29 @@ contain_correct_encoder(_Config) ->
{ok, Schema} = parthenon_schema:create(
<<
"struct<boolean_: boolean, integer: int, double_: double, big_integer: bigint, string_: string,"
"integer_list: array<int>, boolean_list: array<boolean>, double_list: array<double>, big_integer_list: array<bigint>,"
"string_list: array<string>>"
"tiny_integer: tinyint, small_integer: smallint, integer_: integer, float_: float"
"integer_list: array<int>, boolean_list: array<boolean>, double_list: array<double>,"
"big_integer_list: array<bigint>,string_list: array<string>, tiny_integer_list: array<tinyint>,"
"small_integer_list: array<smallint>, float_list: array<float>>"
>>
),

?assertEqual(1, apply_encoder(<<"integer">>, <<"1">>, Schema)),
?assertEqual(1, apply_encoder(<<"tiny_integer">>, <<"1">>, Schema)),
?assertEqual(1, apply_encoder(<<"small_integer">>, <<"1">>, Schema)),
?assertEqual(true, apply_encoder(<<"boolean_">>, <<"true">>, Schema)),
?assertEqual(1.0, apply_encoder(<<"double_">>, <<"1.0">>, Schema)),
?assertEqual(1.0, apply_encoder(<<"float">>, <<"1.0">>, Schema)),
?assertEqual(100, apply_encoder(<<"big_integer">>, <<"100">>, Schema)),
?assertEqual(<<"test">>, apply_encoder(<<"string_">>, <<"test">>, Schema)),
?assertEqual([2], apply_list_encoder(<<"integer_list">>, [<<"2">>], Schema)),
?assertEqual([2], apply_list_encoder(<<"tiny_integer_list">>, [<<"2">>], Schema)),
?assertEqual([2], apply_list_encoder(<<"small_integer_list">>, [<<"2">>], Schema)),
?assertEqual(
[true, false], apply_list_encoder(<<"boolean_list">>, [<<"true">>, <<"false">>], Schema)
),
?assertEqual([2.0], apply_list_encoder(<<"double_list">>, [<<"2.0">>], Schema)),
?assertEqual([2.0], apply_list_encoder(<<"float_list">>, [<<"2.0">>], Schema)),
?assertEqual([101], apply_list_encoder(<<"big_integer_list">>, [<<"101">>], Schema)),
?assertEqual([<<"test_2">>], apply_list_encoder(<<"string_list">>, [<<"test_2">>], Schema)).

Expand Down

0 comments on commit e7158c2

Please sign in to comment.