All Products
Search
Document Center

Realtime Compute for Apache Flink:MULTI_KEYVALUE

Last Updated:Jul 17, 2024

This topic describes how to use the MULTI_KEYVALUE function. This function splits a string into key-value pairs based on the key-value pair delimiter specified by split1, splits a key-value pair based on the delimiter specified by split2, and returns the values of key_name1 and key_name2.

Limits

This function is supported only in Realtime Compute for Apache Flink that uses Ververica Runtime (VVR) 3.0.0 or later.

Warning

In Realtime Compute for Apache Flink that uses VVR 8.0.7 or earlier, you must use the KEYVALUE function instead of the MULTI_KEYVALUE function in the following scenarios to avoid parsing errors:

  • Constant strings are used in the delimiters specified by the split1 and split2 parameters and the values of all key_name parameters of the MULTI_KEYVALUE function.

  • In a namespace of Realtime Compute for Apache Flink of a specific engine version, the MULTI_KEYVALUE function is invoked multiple times, and different delimiters that are specified by the split1 and split2 parameters are used each time the MULTI_KEYVALUE function is invoked. The MULTI_KEYVALUE function can be repeatedly invoked in a single deployment or separately invoked in multiple deployments.

If you use the KEYVALUE function to parse different key_name values in the same field multiple times, Realtime Compute for Apache Flink reuses intermediate parsing results and uses the binary parsing mechanism for strings. This optimizes the overall processing efficiency. The KEYVALUE function is a scalar function. To parse multiple fields, the KEYVALUE function must be invoked multiple times.

Syntax

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

Input parameters

Parameter

Data type

Description

str

VARCHAR

The string that you want to split.

split1

VARCHAR

The key-value pair delimiter.

If the value of split1 is NULL, spaces are used as key-value pair delimiters. If the length of split1 is greater than 1, split1 represents only a set of delimiters, in which each character represents a valid delimiter.

split2

VARCHAR

The key-value delimiter.

If the value of split2 is NULL, spaces are used as key-value delimiters. If the length of split2 is greater than 1, split2 represents only a set of delimiters, in which each character represents a valid delimiter.

key_name1, key_name2, ...

VARCHAR

The list of keys whose values you want to obtain.

Example

  • Test data

    Table 1 T1

    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

    abc

    :

    k1

    k2

    k1:v1;k2=v2

    ;

    :=

    k1

    k2

    k1:v1 k2:v2

    NULL

    :

    k1

    k2

    k1 v1;k2 v2

    ;

    NULL

    k1

    k2

  • Test statement

    SELECT c1, c2 
    FROM T1, lateral table(MULTI_KEYVALUE(str, split1, split2, key1, key2)) 
    as T(c1, c2);                
  • Test result

    c1(VARCHAR)

    c2(VARCHAR)

    v1

    v2

    NULL

    NULL

    v1

    NULL

    NULL

    NULL

    NULL

    NULL

    v1

    NULL

    v1

    v2

    v1

    v2

    v1

    v2

    v1

    v2