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

第13章. 高度なステートフル・オペレーション

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

第8章 構造Spark APIの既存の集約関数を使用して、構造化ストリーミングで集約を表現することがいかに簡単であるかを示した。第12章では、イベントストリームに埋め込まれた時間情報を呼び出すためのSparkの組み込みサポート、いわゆるイベントタイム処理の有効性を示した。

しかし、組み込みモデルで直接サポートされていない、 カスタム集約基準を満たす必要がある場合もある。この章では、このような状況に対処するために、高度なステートフル演算を行う方法を探る。

Structured Streamingは、 任意のステートフル処理を実装するためのAPIを提供する。このAPIは、 mapGroupsWithStateflatMapGroupsWithState という2つの演算子で表される。どちらの演算子も、状態のカスタム定義を作成し、新しいデータが時間経過とともに入ってきたときにこの状態がどのように進化するかの規則を設定し、その状態がいつ期限切れになるかを決定し、この状態定義と入ってくるデータを組み合わせて結果を生成するメソッドを提供することができる。

mapGroupsWithStateflatMapGroupsWithState の主な違いは、前者が処理されたグループごとに単一結果をプロデューサ ーしなければならないのに対し、後者は0個以上の結果を生成する可能性があることである。意味的には、新しいデータが常に新しい状態になる場合はmapGroupsWithState 、それ以外の場合はflatMapGroupsWithState

内部的には、Structured Streamingは演算子間のステートを管理し、ストリーミング・プロセスの実行中および実行期間中におけるステートの可用性と耐障害性を保証する。

例カーフリート管理

例えば、 、車両がワイヤレス・ネットワーク機能を備えた車両群管理ソリューションを想像してみよう。 各車両は定期的に、地理的な位置や、燃料レベル、速度、加速度、方位、エンジン温度などの多くの演算子を報告する。関係者は、このテレメトリー・データのストリームを利用して、ビジネスの運用面と財務面の管理に役立つ様々なアプリケーションを実装したいと考えている。

これまでわかっている構造化ストリーミングの機能を使えば、イベント・タイム・ウィンドウを使って1日の走行キロ数を監視したり、フィルタを適用して低燃費警告を出した車両を発見するなど、すでに多くのユースケースを実装することができる。

トリップの概念は、個別に燃費を計算したり、ジオフェンシング協定の遵守を監視したりするのに有用である。 トリップ情報をグループで分析すれば、交通パターンや交通のホットスポットが明らかになるかもしれないし、他のセンサー情報と組み合わせれば、道路状況を報告することもできる。 ストリーム処理の観点からは、トリップを、車両が動き始めたときに開き、最終的に停止したときに閉じる、任意のウィンドウとして見ることができる。第12章で見たイベント時間ウィンドウ集約は、ウィンドウ基準として固定時間間隔を使用しているため、トリップ分析を実装するのに役立たない。

純粋に時間だけでなく、任意の条件付きで、より強力な状態の定義が必要であることは理解できる。 この例では、車両が走行中であることが条件となる。 ...

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