Splits text into key-value pairs by using delimiter1 and then separates keys from values in the key-value pairs by using delimiter2.

Syntax

str_to_map([string <mapDupKeyPolicy>,] <text> [, <delimiter1> [, <delimiter2>]])

Parameters

  • mapDupKeyPolicy: optional. A value of the STRING type. This parameter specifies the method that is used to process duplicate keys. Valid values:
    • exception: An error is returned.
    • last_win: The latter key overwrites the former key.
    Note The behavior implementation of MaxCompute is determined based on mapDupKeyPolicy. If you do not specify mapDupKeyPolicy, the value of odps.sql.map.key.dedup.policy prevails.
  • text: required. The string that you want to split, which is of the STRING type.
  • delimiter1: optional. The delimiter of the STRING type. If no value is specified for this parameter, commas (,) are used.
  • delimiter2: optional. The delimiter of the STRING type. If no value is specified for this parameter, equal signs (=) are used.
    Note If the delimiter is a regular expression or special character, you must add two backslashes (\\) before the delimiter for escaping. The following special characters can be used as a delimiter: . ? + * :.

Return value

A value in the format of MAP<STRING, STRING> is returned. The return value indicates that the string specified by text is split by using delimiter1 and delimiter2.

Examples

-- {test1:1, test2:2} is returned. 
select str_to_map('test1&1-test2&2','-','&');
-- {test1:1, test2:2} is returned. 
select str_to_map("test1.1,test2.2", ",", "\\.");
-- {test1:1, test2:3} is returned. 
select str_to_map("test1.1,test2.2,test2.3", ",", "\\.");