xml (DataStreamReader)
XMLファイルストリームを読み込み、結果をDataFrameとして返します。schemaが指定されていない場合、入力スキーマはデータから推論されます。
構文
xml(path, schema=None, **options)
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
| str | XML入力のパス。 |
| 構造体型またはstr(オプション) | スキーマは、StructType または DDL 形式の文字列 (例: |
戻り値
DataFrame
例
DataFrameをXMLに書き込み、それをストリームとして読み込む:
Python
import tempfile
import time
with tempfile.TemporaryDirectory(prefix="xml") as d:
spark.createDataFrame(
[{"age": 100, "name": "Hyukjin Kwon"}]
).write.mode("overwrite").option("rowTag", "person").xml(d)
q = spark.readStream.schema(
"age INT, name STRING"
).xml(d, rowTag="person").writeStream.format("console").start()
time.sleep(3)
q.stop()