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

第8章 構造化ストリーム・プログラミング・モデル 構造化ストリーミング・プログラミング・モデル

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

Structured Streaming は、Spark SQLDataFrameDatasetの API の上に構築された基盤の上に構築されている。ストリーミングワークロードをサポートするためにこれらの API を拡張することで、Structured Streaming は、Spark SQL によって導入された高レベル言語の特徴だけでなく、Catalyst クエリオプティマイザの使用、Project Tungsten によって提供された低オーバーヘッドのメモリ管理とコード生成を含む、基礎となる最適化も継承している。 同時に、Structured Streaming は、Spark SQL でサポートされているすべての言語バインディングで利用できるようになった:SparkSQLで使用されている中間クエリ表現のおかげで、プログラムのパフォーマンスは使用する言語バインディングに関係なく同じである。

Structured Streamingでは、すべてのウィンドウ操作と集約操作でイベント時間のサポートが導入され、イベントが処理エンジンに入った時間(処理時間とも呼ばれる)ではなく、イベントが発生した時間を使用するロジックを簡単にプログラムできるようになった。これらの概念は「時間の効果」で学んだ。

SparkエコシステムでStructured Streamingが利用可能になったことで、Sparkは従来のバッチ処理とストリームベースのデータ処理の開発者体験を統一することに成功した。

この章では、Structured Streamingのプログラミングモデルを、Structured Streamingでストリーミングジョブを作成するために通常必要とされる一連のステップを追って検討する:

  • Sparkの初期化

  • ソース:ストリーミング・データの取得

  • ストリーミング・データに適用したい演算子を宣言する。

  • シンク:結果のデータを出力する

Sparkの初期化

Sparkの目に見えるAPIの統合の点 、SparkSession 、Structured Streamingを使用するバッチアプリケーションとストリーミングアプリケーションの単一のエントリポイントになる。

したがって、Sparkジョブを作成するエントリポイントは、SparkバッチAPIを使用する場合と同じである。例8-1で示したように、SparkSession をインスタンス化する。

例8-1. ローカルSparkセッションの作成
import org.apache.spark.sql.SparkSession

val spark = SparkSession
  .builder()
  .appName("StreamProcessing")
  .master("local[*]")
  .getOrCreate()

Spark Shellを使う

Sparkシェルで 、Structured Streamingを探索する場合、SparkSession はすでにspark として提供されている。 Structured Streamingを使用するために追加のコンテキストを作成する必要はない。

ソースストリーミングデータの取得

Structured Streamingでは、 ...

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