데이터처리/Flink
[Flink] Explode 쿼리 표현하기 - Cross join unnest
정선생
2022. 5. 31. 09:00
반응형
Hive 에서 list 와 같이 N개의 아이템이 담기는 필드를 행으로 풀어낼때 explode 쿼리를 사용한다. 하지만 flink 에서는 아무리 검색해도 해당 문법이 잘 안나오는데 그 이유는 hive 에서는 explode 라는 문법을 쓰지만 flink sql 에서는 cross join unnest 라는 문법을 사용해야 하기 때문에 검색이 안된 문제였다.
explode 쿼리 예시
100번의 설명보다는 하나의 예시가 더 도움이 될것같아 예시를 들어보겠다.
다음과 같이 authros 필드에 n개의 필드가 1개의 row 를 풀어내려면 어떻게 해야할까?
Flink SQL 로 표현하면 아래와 같이 cross join unnest 를 이용해 표현 가능하다.
SELECT
book_title,
price,
author.name as author_name,
author.comment as author_comment
FROM
myBooks as t CROSS JOIN UNNEST(t.authors) as author
flink document 상에서는 join 절에 있으니 참고하자.
Joins
Joins # Batch Streaming Flink SQL supports complex and flexible join operations over dynamic tables. There are several different types of joins to account for the wide variety of semantics queries may require. By default, the order of joins is not optimize
nightlies.apache.org
반응형