load (DataStreamReader)
Loads a data stream from a data source and returns it as a DataFrame.
Syntax
load(path=None, format=None, schema=None, **options)
Parameters
Parameter | Type | Description |
|---|---|---|
| str, optional | Path for file-system-backed data sources. |
| str, optional | Format of the data source. Defaults to |
| StructType or str, optional | Schema for the input data as a StructType or DDL-formatted string (for example, |
| All other string options. |
Returns
DataFrame
Examples
Load a stream from a temporary JSON file:
Python
import tempfile
import time
with tempfile.TemporaryDirectory(prefix="load") as d:
spark.createDataFrame(
[(100, "Hyukjin Kwon"),], ["age", "name"]
).write.mode("overwrite").format("json").save(d)
q = spark.readStream.schema(
"age INT, name STRING"
).format("json").load(d).writeStream.format("console").start()
time.sleep(3)
q.stop()