toTable (DataStreamWriter)
ストリーミングクエリの実行を開始し、新しいデータが到着するたびに結果を指定されたテーブルに継続的に出力します。StreamingQuery オブジェクトを返します。
構文
toTable(tableName, format=None, outputMode=None, partitionBy=None, queryName=None, **options)
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
| str | テーブル名。 |
| 文字列、オプション | 保存に使用されるフォーマット。 |
| 文字列、オプション | シンクへのデータの書き込み方法: |
| 文字列またはリスト(省略可能) | パーティショニング列の名前。既に存在するv2テーブルについては無視されます。 |
| 文字列、オプション | クエリの一意の名前。 |
| - | その他の文字列オプション。ほとんどのストリームには |
戻り値
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")