kedro_datasets.spark.SparkStreamingDataset¶
- class kedro_datasets.spark.SparkStreamingDataset(filepath='', file_format='', save_args=None, load_args=None)[source]¶
SparkStreamingDatasetloads data to Spark Streaming Dataframe objects.Example usage for the YAML API:
raw.new_inventory: type: spark.SparkStreamingDataset filepath: data/01_raw/stream/inventory/ file_format: json save_args: output_mode: append checkpoint: data/04_checkpoint/raw_new_inventory header: True load_args: schema: filepath: data/01_raw/schema/inventory_schema.json
Attributes
Methods
exists()Checks whether a data set's output already exists by calling the provided _exists() method.
from_config(name, config[, load_version, ...])Create a data set instance using the configuration provided.
load()Loads data by delegation to the provided load method.
release()Release any cached data.
save(data)Saves data by delegation to the provided save method.
- DEFAULT_LOAD_ARGS: Dict[str, Any] = {}¶
- DEFAULT_SAVE_ARGS: Dict[str, Any] = {}¶
- __init__(filepath='', file_format='', save_args=None, load_args=None)[source]¶
Creates a new instance of SparkStreamingDataset.
- Parameters:
filepath (
str) – Filepath in POSIX format to a Spark dataframe. When using Databricks specifyfilepath``s starting with ``/dbfs/. For message brokers such as Kafka and all filepath is not required.file_format (
str) – File format used during load and save operations. These are formats supported by the running SparkContext including parquet, csv, and delta. For a list of supported formats please refer to the Apache Spark documentation at https://spark.apache.org/docs/latest/structured-streaming-programming-guide.htmlload_args (
Optional[Dict[str,Any]]) – Load args passed to Spark DataFrameReader load method. It is dependent on the selected file format. You can find a list of read options for each selected format in Spark DataFrame read documentation, see https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html. Please note that a schema is mandatory for a streaming DataFrame ifschemaInferenceis not True.save_args (
Optional[Dict[str,Any]]) – Save args passed to Spark DataFrameReader write options. Similar to load_args, this is dependent on the selected file format. You can passmodeandpartitionByto specify your overwrite mode and partitioning respectively. You can find a list of options for each selected format in Spark DataFrame write documentation, see https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html
- exists()¶
Checks whether a data set’s output already exists by calling the provided _exists() method.
- Return type:
bool- Returns:
Flag indicating whether the output already exists.
- Raises:
DatasetError – when underlying exists method raises error.
- classmethod from_config(name, config, load_version=None, save_version=None)¶
Create a data set instance using the configuration provided.
- Parameters:
name – Data set name.
config – Data set config dictionary.
load_version – Version string to be used for
loadoperation if the data set is versioned. Has no effect on the data set if versioning was not enabled.save_version – Version string to be used for
saveoperation if the data set is versioned. Has no effect on the data set if versioning was not enabled.
- Returns:
An instance of an
AbstractDatasetsubclass.- Raises:
DatasetError – When the function fails to create the data set from its config.
- load()¶
Loads data by delegation to the provided load method.
- Return type:
TypeVar(_DO)- Returns:
Data returned by the provided load method.
- Raises:
DatasetError – When underlying load method raises error.
- release()¶
Release any cached data.
- Raises:
DatasetError – when underlying release method raises error.
- Return type:
None
- save(data)¶
Saves data by delegation to the provided save method.
- Parameters:
data (
TypeVar(_DI)) – the value to be saved by provided save method.- Raises:
DatasetError – when underlying save method raises error.
FileNotFoundError – when save method got file instead of dir, on Windows.
NotADirectoryError – when save method got file instead of dir, on Unix.
- Return type:
None