This topic describes how to use the table-valued function MULTI_KEYVALUE in Realtime Compute.

Note This function is only available in Realtime Compute V2.2.2 and later.

Syntax

MULTI_KEYVALUE(VARCHAR str, VARCHAR split1, VARCHAR split2, VARCHAR key_name1, VARCHAR key_name2, ...)

Input parameters

Parameter Data type Description
str VARCHAR The key-value pairs in a string.
split1 VARCHAR The separator of key-value pairs. If split1 is null, a whitespace is used as the separator between key-value pairs. If the length of split1 is greater than 1, split1 only represents a set of separators, in which each character represents a valid separator.
split2 VARCHAR The key-value separator. If split2 is null, a whitespace is used as the key-value separator. If the length of split2 is greater than 1, split2 only represents a set of separators, in which each character represents a valid separator.
key_name1, key_name2, ... VARCHAR The list of keys whose values you want to obtain.

Description

Parses the key-value pairs in a string based on the key-value pair separator and key-value separator, and then returns a list of values for the key names such as key_name1 and key_name2. If a key_name does not exist, the return value is null.

Example

  • Test data
    str (VARCHAR) split1 (VARCHAR) split2 (VARCHAR) key1 (VARCHAR) key2 (VARCHAR)
    k1=v1;k2=v2 ; = k1 k2
    null ; = k1 k2
    k1:v1;k2:v2 ; : k1 k3
    k1:v1;k2:v2 ; = k1 k2
    k1:v1;k2:v2 , : k1 k2
    k1:v1;k2=v2 ; : k1 k2
    k1:v1abck2:v2 cab : k1 k2
    k1:v1;k2=v2 ; := k1 k2
    k1:v1 k2:v2 null : k1 k2
    k1 v1;k2 v2 ; null k1 k2
  • Test statements
    SELECT c1, c2 
    FROM T1, lateral table(MULTI_KEYVALUE(str, split1, split2, key1, key2)) 
    as T(c1, c2);                
  • Test results
    c1 (VARCHAR) c2 (VARCHAR)
    v1 v2
    null null
    v1 null
    null null
    null null
    v1 null
    v1 v2
    v1 v2
    v1 v2
    v1 v2