fix(iotdb): improve the schema for IotDB

This commit is contained in:
firest 2024-01-09 14:39:54 +08:00
parent 7365160eeb
commit 2bf7ac00a0
3 changed files with 25 additions and 18 deletions

View File

@ -113,7 +113,7 @@ fields(action_parameters_data) ->
[ [
{timestamp, {timestamp,
mk( mk(
binary(), hoconsc:union([now, now_ms, now_ns, now_us, binary()]),
#{ #{
desc => ?DESC("config_parameters_timestamp"), desc => ?DESC("config_parameters_timestamp"),
default => <<"now">> default => <<"now">>
@ -129,20 +129,10 @@ fields(action_parameters_data) ->
)}, )},
{data_type, {data_type,
mk( mk(
binary(), hoconsc:union([text, boolean, int32, int64, float, double, binary()]),
#{ #{
required => true, required => true,
desc => ?DESC("config_parameters_data_type"), desc => ?DESC("config_parameters_data_type")
validator => fun(Type) ->
lists:member(Type, [
<<"TEXT">>,
<<"BOOLEAN">>,
<<"INT32">>,
<<"INT64">>,
<<"FLOAT">>,
<<"DOUBLE">>
])
end
} }
)}, )},
{value, {value,

View File

@ -376,7 +376,7 @@ preproc_data(
maps:get(<<"timestamp">>, Data, <<"now">>) maps:get(<<"timestamp">>, Data, <<"now">>)
), ),
measurement => emqx_placeholder:preproc_tmpl(Measurement), measurement => emqx_placeholder:preproc_tmpl(Measurement),
data_type => DataType, data_type => emqx_placeholder:preproc_tmpl(DataType),
value => maybe_preproc_tmpl(Value) value => maybe_preproc_tmpl(Value)
} }
| Acc | Acc
@ -409,10 +409,11 @@ proc_data(PreProcessedData, Msg) ->
#{ #{
timestamp := TimestampTkn, timestamp := TimestampTkn,
measurement := Measurement, measurement := Measurement,
data_type := DataType, data_type := DataType0,
value := ValueTkn value := ValueTkn
} }
) -> ) ->
DataType = emqx_placeholder:proc_tmpl(DataType0, Msg),
#{ #{
timestamp => iot_timestamp(TimestampTkn, Msg, Nows), timestamp => iot_timestamp(TimestampTkn, Msg, Nows),
measurement => emqx_placeholder:proc_tmpl(Measurement, Msg), measurement => emqx_placeholder:proc_tmpl(Measurement, Msg),
@ -610,6 +611,12 @@ eval_response_body(Body, Resp) ->
end. end.
preproc_data_template(DataList) -> preproc_data_template(DataList) ->
Atom2Bin = fun
(Atom, Converter) when is_atom(Atom) ->
Converter(Atom);
(Bin, _) ->
Bin
end,
lists:map( lists:map(
fun( fun(
#{ #{
@ -620,9 +627,18 @@ preproc_data_template(DataList) ->
} }
) -> ) ->
#{ #{
timestamp => emqx_placeholder:preproc_tmpl(Timestamp), timestamp => emqx_placeholder:preproc_tmpl(
Atom2Bin(Timestamp, fun erlang:atom_to_binary/1)
),
measurement => emqx_placeholder:preproc_tmpl(Measurement), measurement => emqx_placeholder:preproc_tmpl(Measurement),
data_type => DataType, data_type => emqx_placeholder:preproc_tmpl(
Atom2Bin(
DataType,
fun(Atom) ->
erlang:list_to_binary(string:uppercase(erlang:atom_to_list(Atom)))
end
)
),
value => emqx_placeholder:preproc_tmpl(Value) value => emqx_placeholder:preproc_tmpl(Value)
} }
end, end,

View File

@ -89,7 +89,8 @@ config_parameters_measurement.label:
"""Measurement""" """Measurement"""
config_parameters_data_type.desc: config_parameters_data_type.desc:
"""Data Type, can be:</br> """Data Type, an enumerated or a string. </br>
For string placeholders in format of ${var} is supported, the final value can be:</br>
- TEXT - TEXT
- BOOLEAN - BOOLEAN
- INT32 - INT32