DataPrime array functions
This guide provides a glossary of all available IBM® Cloud Logs DataPrime functions for processing arrays.
arrayContains
Returns true if an array includes the specified element, or false if the array does not include the element. Supported element types include string, bool, number, interval,
timestamp, regex, and enum.
This function is the inverse of inArray.
arrayContains(array: array<T>, element: T): bool
arrayContains can also be specified in method notation:
(array: array<T>).arrayContains(element: T): bool
Where:
element- Is the element to check for in the array.
array- Is the array to search. The array must contain elements of the same type as
element.
Example
In this example you have a firewall log that records blocked IDs.
{
"action": "BLOCK",
"client_ip": "134.56.32.98",
"blocked_ips": [
"134.56.32.91",
"134.56.32.93",
"134.56.32.90",
"134.56.32.105"
]
}
By checking if client_ip is contained in blocked_ips you can determine if the request was from a blocked address. Either of these notations can be used.
create is_blocked_ip from arrayContains(blocked_ips, client_ip)
create is_blocked_ip from blocked_ips.arrayContains(client_ip)
The result will will include a new field (is_blocked_ip) with a boolean value.
{
"action": "BLOCK",
"client_ip": "134.56.32.98",
"blocked_ips": [
"134.56.32.91",
"134.56.32.93",
"134.56.32.90",
"134.56.32.105"
],
"is_blocked_ip": false
}
inArray
Returns true if the specified element exists in the array, or false if the element does not exist in the array. Supported element types include string, bool, number, interval,
timestamp, regex, and enum.
This function is the inverse of arrayContains.
inArray(element: T, array: array<T>): bool
inArray can also be specified in method notation:
(element: T).inArray(array: array<T>): bool
Where:
element- Is the element to check for in the array.
array- Is the array to search. The array must contain elements of the same type as
element.
Example
In this example you have a log entry with a client IP address.
{
"client_ip": "192.168.1.105"
}
You want to check if the client_ip value exists in an array of blocked IP addresses so you can identify if a request should be blocked. Either of these notations can be used.
filter inArray(client_ip, ['192.168.1.105', '192.168.1.112', '192.168.1.32'])
filter client_ip.inArray(['192.168.1.105', '192.168.1.112', '192.168.1.32'])
The result will be true since 192.168.1.105 is included in the array.
{
"client_ip": "192.168.1.105",
"is_blocked": true
}