pyspark.sql.streaming.
DataStreamReader
Interface used to load a streaming DataFrame from external storage systems (e.g. file systems, key-value stores, etc). Use SparkSession.readStream to access this.
DataFrame
SparkSession.readStream
New in version 2.0.0.
Notes
This API is evolving.
Examples
>>> spark.readStream <pyspark.sql.streaming.readwriter.DataStreamReader object ...>
The example below uses Rate source that generates rows continuously. After that, we operate a modulo by 3, and then writes the stream out to the console. The streaming query stops in 3 seconds.
>>> import time >>> df = spark.readStream.format("rate").load() >>> df = df.selectExpr("value % 3 as v") >>> q = df.writeStream.format("console").start() >>> time.sleep(3) >>> q.stop()
Methods
csv(path[, schema, sep, encoding, quote, …])
csv
Loads a CSV file stream and returns the result as a DataFrame.
format(source)
format
Specifies the input data source format.
json(path[, schema, primitivesAsString, …])
json
Loads a JSON file stream and returns the results as a DataFrame.
load([path, format, schema])
load
Loads a data stream from a data source and returns it as a DataFrame.
option(key, value)
option
Adds an input option for the underlying data source.
options(**options)
options
Adds input options for the underlying data source.
orc(path[, mergeSchema, pathGlobFilter, …])
orc
Loads a ORC file stream, returning the result as a DataFrame.
parquet(path[, mergeSchema, pathGlobFilter, …])
parquet
Loads a Parquet file stream, returning the result as a DataFrame.
schema(schema)
schema
Specifies the input schema.
table(tableName)
table
Define a Streaming DataFrame on a Table.
text(path[, wholetext, lineSep, …])
text
Loads a text file stream and returns a DataFrame whose schema starts with a string column named “value”, and followed by partitioned columns if there are any.