복붙노트

[HADOOP] 하이브에서 문자열을 어떻게 배열로 변환합니까?

HADOOP

하이브에서 문자열을 어떻게 배열로 변환합니까?

나는 하이브 1.1을 사용하고 있습니다.

 hive> select country from releases limit 1;
 OK
 ["us","ca","fr"]

현재 country는 hive의 string 유형입니다. 이것을 Array [String]으로 어떻게 변환합니까?

아래를 시도했지만 오류가 발생합니다.

 hive> select country, cast(country as Array[String]) from releases limit 1;
 FAILED: ParseException line 1:48 cannot recognize input near 'Array' '[' 'String' in primitive type specification

누군가가 타입 캐스팅을 도와 줄 수 있습니까?

해결법

  1. ==============================

    1.

    hive> with releases as (select '["us","ca","fr"]' as country)
        > select  split(regexp_extract(country,'^\\["(.*)\\"]$',1),'","')
        > from    releases
        > ;
    OK
    _c0
    ["us","ca","fr"]
    
  2. from https://stackoverflow.com/questions/45965889/how-do-we-convert-a-string-into-array-in-hive by cc-by-sa and MIT license