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 スパーク定義ガイド

第32章. 言語仕様:Python(PySpark)とR(SparkRとsparklyr)。

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

この章では、Apache Sparkのより微妙な言語仕様のいくつかを取り上げる。本書を通して、我々は膨大な数のPySparkの例を見てきた。第1章では、Sparkが他の言語からコードを実行する方法について高レベルで説明した。ここでは、より具体的な統合について説明しよう:

  • PySpark

  • スパークR

  • sparklyr

図32-1に、これらの言語の基本アーキテクチャを示す。

image
図32-1. スパーク・ドライバ

では、それぞれについて詳しく説明しよう。

PySpark

我々は 本書を通してPySparkを大量に取り上げた。実際、PySparkはScalaやSQLと並んで、本書のほぼすべての章に登場する。そのため、この章ではSpark自体に関連する詳細のみを簡潔に説明する。第1章で説明したように、Spark 2.2ではPySparkをpip 。単純に、pip install pyspark 、ローカルマシンでパッケージとして利用できるようになる。これは新しいものなので、修正すべきバグがあるかもしれないが、今日からプロジェクトで活用できるものだ。

PySparkの基本的な違い

構造化APIを使用している場合、PythonでUDFを使用していない場合を除いて、Scalaで書いた場合とほぼ同じ速度でコードを実行できるはずだ。UDFを使っている場合は、パフォーマンスに影響があるかもしれない。その理由については第6章を参照のこと。

非構造化API、特にRDDを使用している場合、パフォーマンスが低下する(もう少し柔軟性が犠牲になる)。この理由については第12章で触れるが、基本的な考え方は、GoはSparkとJVMが理解できるものからPythonに情報を変換し、また元に戻すのにかなり苦労するということだ。これはデータだけでなく関数も含まれ、シリアライゼーションとして知られるプロセスだ。我々は、シリアライゼーションを使うことが決して意味がないとは言っていない。

パンダの統合

PySparkのパワーの1つ は、プログラミングモデルを横断して動作する能力である。例えば、よくあるパターンは、Sparkで非常に大規模なETL作業を行い、(シングルマシンサイズの)結果をドライバに収集し、それをさらに操作するためにPandasを活用することだ。これにより、ビッグデータにはSpark、スモールデータにはPandasというように、手元のタスクに最適なツールを使うことができる:

import pandas as pd
df = pd.DataFrame({"first":range(200), "second":range(50,250)})
sparkDF = spark.createDataFrame(df)
newPDF = sparkDF.toPandas()
newPDF.head()

Sparkのコミュニティは、他の様々なプロジェクトとの相互運用性の向上に力を注いでおり、SparkとPythonの統合は今後も改善されていくだろう。Sparkのコミュニティは、他の様々なプロジェクトとの相互運用性を向上させることに注力し続けているため、SparkとPythonのインテグレーションは継続的に改善されていくだろう。 ...

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