Skip to main content
HareshAmin
Silver ⭐️
Nov 19, 2021 10:30 AM UTC
Solved

Is there any way to cast string to map?

 

Is there any way to cast string to map in Impala?

e.g: 

select cast("A:1,B:1,C:1") as map<string, int>

 

mszurap
mszurapAnswer
Platinum ⭐️
Nov 22, 2021 3:06 PM UTC

Hi, the complex MAP data type is supported, however it may not be as usable as other simple types. Please see:
https://docs.cloudera.com/runtime/7.2.10/impala-sql-reference/topics/impala-map.html

and

https://docs.cloudera.com/runtime/7.2.10/impala-sql-reference/topics/impala-complex-types.html#complex_types/complex_sample_schema 

There is a similar "GET_JSON_OBJECT" built-in UDF, which may help you - depending what you need to achieve, please see:

https://docs.cloudera.com/runtime/7.2.10/impala-sql-reference/topics/impala-misc-functions.html#misc_functions__get_json_object 

2 replies

mszurap
Platinum ⭐️
mszurapAnswer
Platinum ⭐️
Nov 22, 2021 3:06 PM UTC

Hi, the complex MAP data type is supported, however it may not be as usable as other simple types. Please see:
https://docs.cloudera.com/runtime/7.2.10/impala-sql-reference/topics/impala-map.html

and

https://docs.cloudera.com/runtime/7.2.10/impala-sql-reference/topics/impala-complex-types.html#complex_types/complex_sample_schema 

There is a similar "GET_JSON_OBJECT" built-in UDF, which may help you - depending what you need to achieve, please see:

https://docs.cloudera.com/runtime/7.2.10/impala-sql-reference/topics/impala-misc-functions.html#misc_functions__get_json_object 

Translate
VidyaSargur
Community Manager
Community Manager
Dec 1, 2021 6:28 AM UTC

@HareshAmin, Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future. 

Translate
Regards, Vidya Sargur Madabhushi| Senior Community Manager | Was your question answered? Make sure to mark the answer as the Best Answer. If you find a reply useful, say thanks by clicking on the thumbs up button.