Skip to Content
Spark를 사용한 데이터 알고리즘
book

Spark를 사용한 데이터 알고리즘

by Mahmoud Parsian
May 2025
Beginner to intermediate
438 pages
6h 57m
Korean
O'Reilly Media, Inc.
Content preview from Spark를 사용한 데이터 알고리즘

11장. 디자인 패턴 조인

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

이 장에서는 데이터 집합을 조인하기 위한 실용적인 디자인 패턴을 살펴보겠습니다. 이전 장에서와 마찬가지로 실제 환경에서 유용한 패턴에 초점을 맞출 것입니다. PySpark는 대부분의 사용 사례에 충분한 RDD(pyspark.RDD.join()) 및 데이터프레임(pyspark.sql.DataFrame.join())에 대한 기본 조인 작업을 지원합니다. 그러나 이 조인이 비용이 많이 들 수 있는 상황이 있으므로 유용할 수 있는 몇 가지 특수 조인 알고리즘도 보여드리겠습니다.

이 장에서는 두 데이터 집합을 조인하는 기본 개념을 소개하고 유용하고 실용적인 조인 디자인 패턴의 예제를 제공합니다. 맵리듀스 패러다임에서 조인 작업이 어떻게 구현되는지, 그리고 Spark의 변환을 사용하여 조인을 수행하는 방법을 보여드리겠습니다. RDD 및 데이터 프레임을 사용하여 맵 사이드 조인을 수행하는 방법과 블룸 필터를 사용하여 효율적인 조인을 수행하는 방법을 살펴봅니다.

조인 작업 소개

관계형 데이터베이스 세계에서 공통 키, 즉 테이블의 각 레코드(튜플 또는 행)를 고유하게 식별할 수 있는 하나 이상의 열에 있는 속성 또는 속성 집합을 사용하여 두 테이블(일명 '관계')을 조인하는작업은 빈번한작업입니다.

다음 두 표( T1 및 T2)를 살펴보세요:

T1 = {(k1, v1)}
T2 = {(k2, v2)}

어디에:

  • k1은 T1의 키이고 v1은 관련 속성입니다.

  • k2는 T2의 키이고 v2는 관련 속성입니다.

두 개 이상의 테이블에서 일치하는 키가 있는 행을 결합하여 새 테이블을 만드는 단순 내부 조인은 다음과 같이 정의할 수 있습니다:

T1.join(T2) = {(k, (v1, v2))}
T2.join(T1) = {(k, (v2, v1))}

어디에:

  • K = K1 = K2.

  • (k, v1)은 T1에 있습니다.

  • (k, v2)가 T2에 있습니다.

작동 방식을 설명하기 위해 두 개의 테이블을 만들어 샘플 데이터로 채운 다음 조인해 보겠습니다. 먼저 T1 와 T2 테이블을 만들겠습니다:

>>> d1 = [('a', 10), ('a', 11), ('a', 12), ('b', 100), ('b', 200), ('c', 80)]
>>> T1 = spark.createDataFrame(d1, ['id', 'v1'])
>>> T1.show()
+---+---+
| id| v1|
+---+---+
|  a| 10|
|  a| 11|
|  a| 12|
|  b|100|
|  b|200|
|  c| 80|
+---+---+

>>> d2 = [('a', 40), ('a', 50), ('b', 300), ('b', 400), ('d', 90)]
>>> T2 = spark.createDataFrame(d2, ['id', 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

데이터 엔지니어를 위한 97가지 조언

데이터 엔지니어를 위한 97가지 조언

Tobias Macey, 임혜연(Lim Hye Yeon)
실무자를 위한 그래프 데이터 활용법

실무자를 위한 그래프 데이터 활용법

마티아스 브뢰헬러, 데니즈 고즈넬

Publisher Resources

ISBN: 9798341655317