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 によるストリーム処理

第20章. Sparkストリーミング・シンク

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

、DStreamとして表現されるソースを介してデータを取得し、DStream APIを使用して一連の変換を適用してビジネスロジックを実装した後、その結果を検査、保存、または外部システムに出力したい。

2章を思い出すと、一般的なストリーミングモデルでは、ストリーミング処理からデータを外部出力するコンポーネントをシンクと呼ぶ。 Spark Streamingでは、シンクはいわゆる出力演算子を使って実装される。

この章では、これらの出力演算子を通じて外部システムにデータを出力するためのSpark Streamingの機能と様式を探っていく。

出力演算子

出力演算子 は、すべてのSpark Streamingアプリケーションにおいて重要な役割を果たす。DStream上の計算をトリガーすると同時に、プログラマブルなインタフェースを介して結果データへのアクセスを提供する。

図20-1では、2つのストリームを入力として受け取り、一方を変換し、結果をデータベースに書き込む前にそれらを結合する、一般的なSpark Streamingジョブを示している。 実行時に、その出力操作で終わるDStream変換の連鎖がSparkジョブになる。

spas 2001
図20-1. Spark Streamingジョブ

このジョブはSpark Streamingスケジューラにアタッチされ、図20-2に示すように、スケジューラはバッチ間隔ごとに定義されたジョブの実行をトリガーする。

spas 2002
図20-2. Spark Streamingスケジューラー

出力演算子は以下をつなぐ役割を果たす:

  • Dストリームの遅延変換シーケンス

  • Spark Streamingスケジューラ

  • 我々がデータをプロデュースする外部システム

実行モデルの観点からは、ストリーミングプログラムで宣言されたすべての出力演算は、プログラムで宣言されたのと同じ順序でSpark Streamingスケジューラにアタッチされる。 この順序は、前の演算が実行を終了した後に後の出力演算がトリガーされるシーケンスセマンティクスを保証する。 例えば、以下のコードスニペットでは、検索可能なインデックスに追加される前に、メディア資産をデータベースに格納している。 Spark Streamingで保証された出力演算の実行順序は、新しいメディアが検索インデックスを通じて検索可能になる前にメインデータベースに追加されることを保証する:

// assume a mediaStream is a DStream[Media],
// Media is the type that contains the meta-data for new audio/video assets

// Save to the assets database
mediaStream.foreachRDD ...
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