Skip to content

[Feature] Similar to support request for str_to_map function in Hive #9957

@FreeOnePlus

Description

@FreeOnePlus

Search before asking

  • I had searched in the issues and found no similar issues.

Description

Currently in Apache Doris, there is no functionality to support this scenario. I hope the official can support such a function, thank you~

Use case

str_to_map(string parameters, delimiter 1, delimiter 2)

Split text into key-value pairs using two delimiters.

Delimiter 1 splits the text into K-V pairs, Delimiter 2 splits each K-V pair. The default delimiter is ',' for delimiter 1 and '=' for delimiter 2.

example:

  1. Create a map field

`DROP TABLE IF EXISTS tmp.tmp_str_to_map;

CREATE TABLE IF NOT EXISTS tmp.tmp_str_to_map

(
ocolumn string comment 'original field',
rcolumn map<string,string> comment 'map field'
);`

If the data really wants kv to directly clean the data and convert it into a map:

str_to_map(regexp_replace(params,'["|{|}]',''),'&',':') as params, --- data is divided by &, kv is divided by:

  1. concat + str_to_map function
    Use concat + & to splicing table fields into map type
    `insert overwrite table tmp.tmp_str_to_map

SELECT

concat('&crowd:', m0.id,'&clicker:',m0.dui_leader,'&sen:',m0.application_type) ocolumn,

str_to_map(concat('column1:', m0.id,'&column2:',m0.dui_leader,'&column3:',m0.application_type), '&', ':') rcolumn

FROM tmp.tmp_adhoc_detail_20180927 m0

limit 1

;3. To use the fields in the map, use [""]select

rcolumn,

rcolumn["column1"] column1

from tmp.tmp_str_to_map;`

  1. It can also be directly converted and used without storing fields
    `SELECT

m0.id column1,

str_to_map(concat('column1:', m0.id,'&column2:',m0.dui_leader,'&column3:',m0.application_type), '&', ':')["column1"] column1_1

from tmp.tmp_adhoc_detail_20180927 m0
limit 1
`

  1. Results:
    {"column1":"1","column2":"李某某","column3":"创新班"}

Related issues

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stalekind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions