29
29
-include_lib (" riak_pb/include/riak_ts_ttb.hrl" ).
30
30
31
31
-export ([serialize /2 ,
32
- deserialize /1 ]).
32
+ deserialize /1 , deserialize / 2 ]).
33
33
34
34
serialize (QueryText , Interpolations ) ->
35
35
Content = # tsinterpolation {
@@ -47,17 +47,32 @@ serialize_interpolations([{Key, Value} | RemainingInterps],
47
47
UpdatedInterps = [# rpbpair {key = Key , value = Value } | SerializedInterps ],
48
48
serialize_interpolations (RemainingInterps , UpdatedInterps ).
49
49
50
- deserialize ({error , {Code , Message }}) when is_integer (Code ), is_list (Message ) ->
50
+ deserialize (Response ) ->
51
+ deserialize (Response , false ).
52
+
53
+ % % 2nd (boolean) argument indicates whether column types should be
54
+ % % included in the response. It's a bit silly that they aren't by
55
+ % % default, but that's an old oversight/decision that can't be
56
+ % % trivially changed without risking backwards compatibility.
57
+ deserialize ({error , {Code , Message }}, _IncludeColumnTypes )
58
+ when is_integer (Code ), is_list (Message ) ->
51
59
{error , {Code , iolist_to_binary (Message )}};
52
- deserialize ({error , {Code , Message }}) when is_integer (Code ), is_atom (Message ) ->
60
+ deserialize ({error , {Code , Message }}, _IncludeColumnTypes )
61
+ when is_integer (Code ), is_atom (Message ) ->
53
62
{error , {Code , iolist_to_binary (atom_to_list (Message ))}};
54
- deserialize ({error , Message }) ->
63
+ deserialize ({error , Message }, _IncludeColumnTypes ) ->
55
64
{error , Message };
56
- deserialize (tsqueryresp ) ->
65
+ deserialize (tsqueryresp , _Types ) ->
57
66
{ok , {[], []}};
58
- deserialize ({tsqueryresp , {ColumnNames , _ColumnTypes , Rows }}) ->
67
+ deserialize ({tsqueryresp , {ColumnNames , _ColumnTypes , Rows }}, false ) ->
59
68
{ok , {ColumnNames , Rows }};
60
- deserialize (# tsqueryresp {columns = C , rows = R }) ->
69
+ deserialize ({tsqueryresp , {ColumnNames , ColumnTypes , Rows }}, true ) ->
70
+ {ok , {lists :zip (ColumnNames , ColumnTypes ), Rows }};
71
+ deserialize (# tsqueryresp {columns = C , rows = R }, false ) ->
61
72
ColumnNames = [ColName || # tscolumndescription {name = ColName } <- C ],
62
73
Rows = riak_pb_ts_codec :decode_rows (R ),
63
- {ok , {ColumnNames , Rows }}.
74
+ {ok , {ColumnNames , Rows }};
75
+ deserialize (# tsqueryresp {columns = C , rows = R }, true ) ->
76
+ Columns = [{ColName , ColType } || # tscolumndescription {name = ColName , type = ColType } <- C ],
77
+ Rows = riak_pb_ts_codec :decode_rows (R ),
78
+ {ok , {Columns , Rows }}.
0 commit comments