メインコンテンツまでスキップ

toTable (DataStreamWriter)

ストリーミングクエリの実行を開始し、新しいデータが到着するたびに結果を指定されたテーブルに継続的に出力します。StreamingQuery オブジェクトを返します。

構文

toTable(tableName, format=None, outputMode=None, partitionBy=None, queryName=None, **options)

パラメーター

パラメーター

Type

説明

tableName

str

テーブル名。

format

文字列、オプション

保存に使用されるフォーマット。

outputMode

文字列、オプション

シンクへのデータの書き込み方法: appendcomplete 、またはupdate

partitionBy

文字列またはリスト(省略可能)

パーティショニング列の名前。既に存在するv2テーブルについては無視されます。

queryName

文字列、オプション

クエリの一意の名前。

**options

-

その他の文字列オプション。ほとんどのストリームにはcheckpointLocationを指定してください。

戻り値

StreamingQuery

注意

v1テーブルの場合、 partitionBy列は常に尊重されます。v2テーブルの場合、 partitionByテーブルがまだ存在しない場合にのみ有効です。

データストリームをテーブルに保存する:

Python
import tempfile
import time
_ = spark.sql("DROP TABLE IF EXISTS my_table2")
with tempfile.TemporaryDirectory(prefix="toTable") as d:
q = spark.readStream.format("rate").option(
"rowsPerSecond", 10).load().writeStream.toTable(
"my_table2",
queryName='that_query',
outputMode="append",
format='parquet',
checkpointLocation=d)
time.sleep(3)
q.stop()
spark.read.table("my_table2").show()
_ = spark.sql("DROP TABLE my_table2")