Skip to Content
スパーク定義ガイド
book

スパーク定義ガイド

by Bill Chambers, Matei Zaharia
March 2025
Intermediate to advanced
606 pages
9h
Japanese
O'Reilly Media, Inc.
Content preview from スパーク定義ガイド

第13章. 高度なRDD

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

第12章では、 、単一のRDD操作の基本を探った。RDDの作成方法と、RDDを使いたくなる理由を学んだ。さらに、マッピング、フィルタリング、リデュース、単一の RDD データを変換する関数の作成方法についても説明した。この章では、高度なRDD演算子をカバーし、データを操作するための強力な抽象化であるキー・バリューRDDに焦点を当てる。また、カスタムパーティショニングのような、より高度なトピックにも触れる。カスタムパーティション分割関数を使えば、データのクラスタ上での配置を正確に制御し、それに応じて個々のパーティションを操作することができる。その前に、これから取り上げる主要なトピックをまとめておこう:

  • 集約とキー・バリューRDD

  • カスタムパーティショニング

  • RDDが結合する

このAPIセットは、基本的にSparkの初期から存在しており、このAPIセットに関するサンプルはウェブ上に山ほどある。このため、これらの演算子の使い方を示す例を検索して発見するのは簡単だ。

前章で使ったのと同じデータセットを使ってみよう:

// in Scala
val myCollection = "Spark The Definitive Guide : Big Data Processing Made Simple"
  .split(" ")
val words = spark.sparkContext.parallelize(myCollection, 2)
# in Python
myCollection = "Spark The Definitive Guide : Big Data Processing Made Simple"\
  .split(" ")
words = spark.sparkContext.parallelize(myCollection, 2)

キー・バリューの基本(キー・バリューRDD)

RDDには、データをkey-value形式で置くことを要求するメソッドがたくさんある。これが必要であることを示すヒントは、メソッドに<some-operation>ByKey が含まれていることである。メソッド名にByKey がある場合は、PairRDD 型に対してのみ実行できることを意味する。最も簡単な方法は、現在のRDDを基本的なkey-value構造にマッピングすることである。これは、RDDの各レコードに2つの値を持つことを意味する:

// in Scala
words.map(word => (word.toLowerCase, 1))
# in Python
words.map(lambda word: (word.lower(), 1))

キーバイ

先ほどの例では、キーを作成する簡単な方法を示した。しかし、現在の値からキーを作成する関数を指定することで、keyBy 関数を使用して同じ結果を得ることもできる。この場合、単語の最初の文字をキーとしている。そして、SparkはそのレコードをキーとなるRDDの値として保持する:

// in Scala
val keyword = words.keyBy(word => word.toLowerCase.toSeq(0).toString)
# in Python
keyword = words.keyBy(lambda
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

高性能Spark

高性能Spark

Holden Karau, Rachel Warren
生成AIの可視化

生成AIの可視化

Priyanka Vergadia, Valliappa Lakshmanan
ソフトウェア工学の基礎

ソフトウェア工学の基礎

Nathaniel Schutta, Dan Vega

Publisher Resources

ISBN: 9798341627567