Share via


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
path str, optional Path for file-system-backed data sources.
format str, optional Format of the data source. Defaults to 'parquet'.
schema StructType or str, optional Schema for the input data as a StructType or DDL-formatted string (for example, col0 INT, col1 DOUBLE).
**options All other string options.

Returns

DataFrame

Examples

Load a stream from a temporary JSON file:

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()