Function list
You can use the following functions in time series data storage rule scripts to process device data. The functions include data type conversion, time type conversion, and basic data type operations.
Background information
You can use the supported script syntax to call functions that store custom topic data from devices into time series data storage.
Time series data storage related functions
|
Expression |
Description |
|
convert2HotStorageData(fields, time) |
Converts fields data into a standardized format for storage.
The data is converted into the following format:
|
|
writeHotStorage(params) |
Writes standardized data params to time series data storage. params must include
Important
The params parameter can include a maximum of 500 |
Data type conversion functions
Expression | Description |
toBoolean(Object) | Converts an Object value to a Boolean value. The parameter supports the following value types:
|
toNumber(Object) | Converts an Object value to a Number value. The parameter supports the following value types:
|
toString(Object) | Converts an Object value to a String value. The parameter can be of any type. The function returns the corresponding String value. If the parameter value is null, the function returns an empty string. If the parameter is a binary type, the function returns the corresponding value based on UTF-8 encoding. |
toMap(Object) | Converts an Object value to a Map value. The parameter supports the following value types:
|
toArray(Object) | Converts an Object value to an Array value. The parameter supports the following value types:
|
toBinary(Object) | Converts an Object value to a binary value. The parameter supports the following value types:
|
Time type conversion functions
Function expression | Description |
format_date(timestamp, pattern, timeZone) | Converts a millisecond timestamp to a time string in a specified format. Returns a String value.
|
to_timestamp(dateString, pattern, timeZone) | Converts a time string in a specified format to a millisecond timestamp. Returns a numeric timestamp.
|
Functions supported by basic data types
Map type
Expression
Description
[Object]
Gets the
Valuefor a specifiedKey.size()
Gets the number of key-value pairs in the Map data.
containsKey(String)
Checks whether the Map data contains a specified key.
keySet()
Gets the set of keys in the Map data. Returns an Array.
remove(Object)
Removes the key-value pair for a specified key from the Map data.
put(Object, Object)
Adds a key-value pair to the Map data.
putAll(map)
Adds a set of Map data to the Map data in a batch.
Array type
Function
Description
[int]
Gets the value at a specified index. The index of the first element is 0.
contains(Object)
Checks whether the array contains a specified element.
remove(Object)
Removes a specified element from the array.
removeAt(int)
Removes the element at a specified index from the array.
add(Object)
Adds an element to the end of the array.
add(index, Object)
Adds an element at a specified index.
addAll(array)
Adds another array to the array.
size()
Gets the number of elements in the array.
String type
Function
Description
substring(start, end)
Extracts a substring from the
startposition to theend-1position. Ifendis not specified, the substring is extracted to the end of the string.length()
Gets the length of the string.
split(String)
Splits a string using a separator character.
startsWith(String)
Checks whether a string starts with a specified string.
endsWith(String)
Checks whether a string ends with a specified substring.
indexOf(String, index)
Returns the position of the first occurrence of a specified string, starting from a specified index.
If index is not specified, the default value is 0.
Other functions
Expression | Description |
endWith(input, suffix) | Checks whether the string input ends with the string suffix. Returns a Boolean value. |
productKey() | Returns the ProductKey of the current product. |
getDeviceTag(key) | Returns the device tag that corresponds to the specified |
getOrNull(data, "items", ......) | Returns the value of a specified field from the JSON data data. You can specify any number of fields, but you must specify them in hierarchical order. The function returns the value of the last field. If the last field does not exist or its value is empty, the function returns null. For example, the data parameter contains the following: Function examples:
|
payload(textEncoding) | Returns the escaped data of the payload that a device publishes. textEncoding specifies the character encoding for escaping the payload. Valid values:
|
parseNumber(numberString, radix) | Converts the string numberString to a number in the specified radix. radix is an optional parameter. Valid values:
For example: |