Use Golang template to customize analaysis result in Kuiper


Golang template introduction


{{if pipeline}} T1 {{else}} T0 {{end}}
{{range pipeline}} T1 {{else}} T0 {{end}}
{{if pipeline}} {"field1": true} {{else}}  {"field1": false} {{end}}

Kuiper sink data format


Send slice data by piece

"sendSingle": true,
"dataTemplate": "{{json .}}"

Data content conversion

"dataTemplate": "{\"device_id\": {{.device_id}}, \"description\": \"{{if lt .t_av 30.0}}Current temperature is {{.t_av}}, it's normal.\"{{else if ge .t_av 30.0}}Current temperature is {{.t_av}}, it's high.\"{{end}}}"
"sendSingle": true,
{"device_id": {{.device_id}}, "description": "
{{if lt .t_av 30.0}}
Current temperature is {{.t_av}}, it's normal."
{{else if ge .t_av 30.0}}
Current temperature is {{.t_av}}, it's high."
{"device_id": 1, "description": "Current temperature is 36.25, it's high."}
{"device_id": 2, "description": "Current temperature is 27, it's normal."}

Data traversal

"values": [
{"temperature": 10.5},
{"temperature": 20.3},
{"temperature": 30.3}
"sendSingle": true,
"dataTemplate": "{{$len := len .values}} {{$loopsize := add $len -1}} {\"device_id\": \"{{.device_id}}\", \"description\": [{{range $index, $ele := .values}} {{if le .temperature 25.0}}\"fine\"{{else if gt .temperature 25.0}}\"high\"{{end}} {{if eq $loopsize $index}}]{{else}},{{end}}{{end}}}"
{{range $index, $ele := .values}} 
{{if le .temperature 25.0}}
{{else if gt .temperature 25.0}}
{{if eq $loopsize $index}}
{"device_id": "1", "description": [ "fine" , "fine" , "high" ]}




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
EMQ Technologies

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.