일반적으로 사용되는 몇 가지 기능

캐스트

cast(value as type)
# 将int类型的id转化为了String类型
cast(id as string)

Cast는 특정 컬럼의 표시된 값을 특정 유형으로 변환하는 기능입니다. 일반적으로 데이터 오버 플로우의 위험이 있으므로 큰 유형을 작은 유형으로 변환해야합니다.

연결

concat(string s1, string s2, string s3,...)
# 输出1-2
concat(1,"-",2)

Concat은 연결 문자열 인 MySQL의 concat 함수와 동일하며 Java +

concat_ws

concat_ws(seperator, string s1, string s2,...)

Concat_ws는 MySQL의 concat_ws 함수와 동일하며 지정된 구분 기호를 사용하여 여러 문자열을 연결합니다.

수집 _ 세트

collect_set은 group by와 함께 사용해야합니다.

collect_set은 그룹화 된 데이터를 가능한 한 간주하고 그룹화 된 값은 집합에 연결됩니다.

예를 들어 테이블 idname이 있습니다.

id name
1  a
2  a
1  b

SQL :

select id,collect_set(name) as cname from table_name group by id;

결과:

id  cname
1   [a,b]
2   [a]

Collect_set 및 concat_ws를 함께 사용하여 MySQL group_concat 함수를 구현합니다.

select id,group_concat(name) as cname from idname group by id;

하이브와 동일 :

select id,concat_ws(",",collect_set(name)) as cname from idname group by id;

수집 _ 목록

collect_list와 collect_set은 기본적으로 동일하지만 이름에서 한 가지 차이점을 추측 할 수 있습니다.
, collect_set은 그룹화 후 값을 중복 해제하지만 collect_list는 중복되지 않습니다.

추천

출처blog.csdn.net/trayvontang/article/details/103427843