티스토리 뷰

반응형

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 절에 있으니 참고하자.

https://nightlies.apache.org/flink/flink-docs-release-1.15/docs/dev/table/sql/queries/joins/#array-expansion

 

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

 

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함