Skip to Content
Apache Spark によるストリーム処理
book

Apache Spark によるストリーム処理

by Gerard Maas, Francois Garillot
May 2025
Intermediate to advanced
452 pages
6h 3m
Japanese
O'Reilly Media, Inc.
Content preview from Apache Spark によるストリーム処理

第10章. 構造化ストリーミング・ソース

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

前の章では、Structured Streaming プログラミングモデルの概要と、それを実用的に適用する方法について説明した。 また、ソースが各 Structured Streaming プログラムの出発点であることも説明した。 この章では、ソースの一般的な特徴を学び、利用可能なソースについて、そのさまざまな設定オプションや演算子モードを含め、より詳細に検討する。

情報源を理解する

Structured Streamingでは、ソースはストリーミング・データ・プロバイダを表す抽象化である。ソース・インタフェースの背後にある概念は、ストリーミング・データは、単調にインクリメントするカウンタでインデックス付けされたシーケンスとして見ることができる、時間の経過に伴うイベントの連続的な流れであるということである。

図10-1は、ストリーム内の各イベントが、 オフセットが増加し続けるものとみなされる様子を示している。

spas 1001
図10-1. インデックス化されたイベントのシーケンスとして見たストリーム

図 10-2 に示すように、オフセットは、外部ソースにデータを要求し、どのデータがすでに消費され たかを示すために使用される。構造化ストリーミングは、外部システムから現在のオフセットを要求し、最後に処 理されたオフセットと比較することによって、処理するデータがいつあるかを知る。処理するデータは、2 つのオフセットstartend の間のバッチを取得することによって要求される。 ソースは、指定されたオフセットをコミットすることで、データが処理されたことを通知される。 ソース契約は、コミットされたオフセット以下のオフセットを持つすべてのデータが処理されたこと、および後続の要求がそのコミットされたオフセットより大きいオフセットのみを規定することを保証する。 これらの保証を考慮すると、ソースは、システムリソースを解放するために、処理されたデータを破棄することを選択する可能性がある。

spas 1002
図10-2. オフセット処理のシーケンス

図10-2に示したオフセット・ベースの処理のダイナミクスを詳しく見てみよう:

  1. t1において、システムはgetOffset を呼び出し、ソースの現在のオフセットを取得する。

  2. t2において、システムは、getBatch(start, end) を呼び出し、最後の既知のオフセットまでのバッチを取得する。その間に新しいデータが到着している可能性があることに注意。

  3. t3で、システムはオフセットをcommits 、ソースは対応するレコードを削除する。

このプロセスは絶え間なく繰り返され、ストリーミングデータの取得を保証する。 最終的な故障から回復するために、オフセットは外部ストレージにチェックポイントされることが多い。

オフセットに基づく相互作用の他に、ソースは2つの要件を満たす必要がある。 ...

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

Apache Flinkによるストリーム処理

Apache Flinkによるストリーム処理

Fabian Hueske, Vasiliki Kalavri

Publisher Resources

ISBN: 9798341650602