Skip to content

Commit

Permalink
Merge pull request #12276 from lafirest/fix/iotdb_schema
Browse files Browse the repository at this point in the history
fix(iotdb): improve the schema for IotDB
  • Loading branch information
HJianBo committed Jan 10, 2024
2 parents 3d7264c + 2bf7ac0 commit 7b211b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
16 changes: 3 additions & 13 deletions apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fields(action_parameters_data) ->
[
{timestamp,
mk(
binary(),
hoconsc:union([now, now_ms, now_ns, now_us, binary()]),
#{
desc => ?DESC("config_parameters_timestamp"),
default => <<"now">>
Expand All @@ -129,20 +129,10 @@ fields(action_parameters_data) ->
)},
{data_type,
mk(
binary(),
hoconsc:union([text, boolean, int32, int64, float, double, binary()]),
#{
required => true,
desc => ?DESC("config_parameters_data_type"),
validator => fun(Type) ->
lists:member(Type, [
<<"TEXT">>,
<<"BOOLEAN">>,
<<"INT32">>,
<<"INT64">>,
<<"FLOAT">>,
<<"DOUBLE">>
])
end
desc => ?DESC("config_parameters_data_type")
}
)},
{value,
Expand Down
24 changes: 20 additions & 4 deletions apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb_connector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ preproc_data(
maps:get(<<"timestamp">>, Data, <<"now">>)
),
measurement => emqx_placeholder:preproc_tmpl(Measurement),
data_type => DataType,
data_type => emqx_placeholder:preproc_tmpl(DataType),
value => maybe_preproc_tmpl(Value)
}
| Acc
Expand Down Expand Up @@ -409,10 +409,11 @@ proc_data(PreProcessedData, Msg) ->
#{
timestamp := TimestampTkn,
measurement := Measurement,
data_type := DataType,
data_type := DataType0,
value := ValueTkn
}
) ->
DataType = emqx_placeholder:proc_tmpl(DataType0, Msg),
#{
timestamp => iot_timestamp(TimestampTkn, Msg, Nows),
measurement => emqx_placeholder:proc_tmpl(Measurement, Msg),
Expand Down Expand Up @@ -610,6 +611,12 @@ eval_response_body(Body, Resp) ->
end.

preproc_data_template(DataList) ->
Atom2Bin = fun
(Atom, Converter) when is_atom(Atom) ->
Converter(Atom);
(Bin, _) ->
Bin
end,
lists:map(
fun(
#{
Expand All @@ -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),
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)
}
end,
Expand Down
3 changes: 2 additions & 1 deletion rel/i18n/emqx_bridge_iotdb.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ config_parameters_measurement.label:
"""Measurement"""

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
- BOOLEAN
- INT32
Expand Down

0 comments on commit 7b211b5

Please sign in to comment.