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

第9章 データソース データソース

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

この章では、Sparkですぐに使用できる様々なデータソースと、コミュニティによって構築された無数のデータソースを紹介する。Sparkには6つの "コア "データソースと、コミュニティによって書かれた何百もの外部データソースがある。あらゆる種類のデータソースの読み取りと書き込みが可能で、コミュニティが独自の貢献を作成できることは、間違いなくSparkの最大の強みの1つである。以下は、 、Sparkのコア・データソースである:

  • CSV

  • JSON

  • パルケ

  • ORC

  • JDBC/ODBC接続

  • プレーンテキストファイル

、Sparkにはコミュニティが作成した数多くのデータソースがある。ほんの一例だ:

この章の目標は、Sparkのコアデータソースからの読み取りと書き込みができるようになり、サードパーティのデータソースと統合する際に何を見るべきかを理解するのに十分な知識を身につけることである。そのために、認識・理解する必要のある中核概念に焦点を当てる。

データソースAPIの構造

特定の形式からの読み取りと書き込みの方法を説明する前に、データソースAPIの全体的な組織構造を見てみよう。

API構造を読み取る

、データを読み取るためのコア構造は以下の通りである:

DataFrameReader.format(...).option("key", "value").schema(...).load()

デフォルト値ではSparkはParquet形式を使用するため、format はオプションである。option では、データをどのように読み取るかをパラメータ化するためのキー・バリュー設定を行うことができる。最後に、schema は、データソースがスキーマを提供しているか、スキーマ推論を使用する場合はオプションである。当然ながら、各形式にはいくつかの必須オプションがあり、それについては各形式を見るときに説明する。

Sparkコミュニティには多くの省略記法があり、データソース読み取りAPIも例外ではない。本書では一貫性を保ちつつ、いくつかの省略記法を明らかにする。

データ読みの基本

Sparkでデータを読み取るための基盤は、DataFrameReaderread 属性を介して、SparkSession にアクセスする:

spark.read

DataFrame読者ができたら、いくつかの値を指定する:

  • 形式

  • スキーマ

  • 読み取りモード

  • 一連のオプション

形式、オプション、スキーマはそれぞれDataFrameReader を返し、さらに変換を行うことができる。各データソースは、データをSparkにどのように読み取るかを決定する特定のオプションセットを持っている(これらのオプションについては後ほど説明する)。最低限、DataFrameReader に読み取り元のパスを指定する必要がある。

これが全体的なレイアウトの例だ:

spark.read.format("csv") .option("mode", "FAILFAST") .option("inferSchema", "true") .option("path", ...
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

AI支援プログラミング

AI支援プログラミング

Tom Taulli
高性能Spark

高性能Spark

Holden Karau, Rachel Warren

Publisher Resources

ISBN: 9798341627567