hello :slightly_smiling_face: I would like to use ...
# questions
l
hello šŸ™‚ I would like to use your spark.SparkStreamingDataSet with a Kafka integration. Due to project constraints, I am working with Kedro 0.19.14, and the following jars (
spark.jars.packages: org.apache.spark:spark-sql-kafka-0-10_2.12:3.2.4,org.apache.spark:spark-token-provider-kafka-0-10_2.12:3.2.4
) From what i have understood, my dataset definition in the catalogue should be something like this:
Copy code
data:
  type: spark.SparkStreamingDataSet
  file_format: kafka
  load_args:
    options:
      subscribe: my-topic
      kafka.bootstrap.servers: kafka:0000
      startingOffsets: earliest
however, I cannot navigate around the error :
Copy code
DatasetError: Failed while loading data from data set 
SparkStreamingDataset(file_format=kafka, filepath=., load_args={'options': 
{'kafka.bootstrap.servers': kafka:0000, 'startingOffsets': earliest, 
'subscribe': my-topic}}, save_args={}).
schema should be StructType or string
Would you have any example projects or extra docs to point me to ? Thanks a bunch 😊
l
thank you ! 😊 I have found these and they are quite useful, especially the first one that has kafka in the pipeline (the others do not if i am not mistaken) any idea where this schema issue is coming from though?
j
l
I had it originally but removed it after getting the following error šŸ˜“
Copy code
DatasetError: Failed while loading data from data set 
SparkStreamingDataset(file_format=kafka, filepath=., 
load_args={'kafka.bootstrap.servers': kafka:0000, 'startingOffsets': earliest, 
'subscribe': my-topic}, save_args={}).
requirement failed: Kafka source has a fixed schema and cannot be set with a 
custom one
I had understood the schema argument was necessary when tied to the file_format json or csv i.e. spark streaming not coupled to kafka.
in the example project I also see there's an absence of the schema argument https://github.com/deepyaman/kedro-streaming/blob/develop/conf/base/catalog.yml
j
Hey, what version of
kedro-datasets
are you using?
d
in the example project I also see there's an absence of the schema argument
https://github.com/deepyaman/kedro-streaming/blob/develop/conf/base/catalog.yml
FWIW this is a hackathon project from 2021. šŸ™‚ It implements it's own dataset that predates whatever is in
kedro-datasets
, so the configuration may not line up. I wasn't very involved in the version that is in
kedro-datasets
, but it looks like I commented that it was OK to require schema? šŸ˜… https://github.com/kedro-org/kedro-plugins/pull/198#discussion_r1209233565 I would consider streaming support in Kedro to be rather experimental at best. This doesn't answer your question, but do you know how you want to use streaming with Kedro? As in, are you looking to interactively run something streaming (more like a demo) or deploy some streaming tables? One other option you could consider is using the Ibis dataset, depending on what you're looking to do, as Ibis also has Spark Streaming backend support. I haven't tried it with Kedro.
l
Hello, thank you both for your input! šŸ™ 😊 • we are trying to do: deploy some streaming tables (monitor some tables on a PostGres and if there are new inputs, run a preprocessing pipeline streaming version) • our kedro dataset version:
kedro-datasets 1.8.0
the kedro dataset version seems really low (Considering it's now at 8.1.0), we had let kedro decide the version based on the below constraints:
Copy code
[project]
requires-python = ">=3.8,<3.9"
name = "XXX"
readme = "README.md"
dynamic = [ "version",]
dependencies = ["kedro-datasets[spark]", "pyspark~=3.2.0", "psycopg2-binary==2.9.9"]
but we now set a version higher or equal to 6.0.0 Edit: we are also going to update to python 3.9 and above to be able to have a more recent version of kedro datasets, else we have to stay below 1.8.0 ...
d
if there are new inputs, run a preprocessing pipeline streaming version
What do you mean by this? I would say the main difference with a streaming pipeline is that it's always running. Do you just mean a deployed streaming pipeline, and if you get new events in Kafka it will process them?
l
yes exactly. it is constantly running and picks up changes
so we have now kedro datasets 4.1.0 under python 3.9 we see an inherent incompatibility between letting the file_format be kafka, but then in the load_args it seems all arguments are sent to Kafka, and arguments such as inferSchema (set to True to avoid having to specify a custom schema) are also passed and cause an error to occur... is this correct?
we have found the function here: https://github.com/kedro-org/kedro-plugins/blob/main/kedro-datasets/kedro_datasets/spark/spark_streaming_dataset.py
Copy code
def load(self) -> DataFrame:
        """Loads data from filepath.
        If the connector type is kafka then no file_path is required, schema needs to be
        seperated from load_args.
        Returns:
            Data from filepath as pyspark dataframe.
        """
        load_path = strip_dbfs_prefix(self._fs_prefix + str(self._filepath))
        data_stream_reader = (
            get_spark()
            .readStream.schema(self._schema)
            .format(self._file_format)
            .options(**self._load_args)
        )
        return data_stream_reader.load(load_path)
we think it jsut needs an if/else for filepath kafka or not kafka. For not kafka the readStream should keep the .schema and for kafka it should not have it. we will open an issue / PR šŸ™‚ any recommendation on the kedro processes? is it correct we should make the PR here: https://github.com/kedro-org/awesome-kedro ?
we will internalize the dataset definition for now and try with this new kafka based condition. to see if it can work like that
šŸ™Œ 1
d
You can make the PR to https://github.com/kedro-org/kedro-plugins, where kedro-datasets lives
šŸ‘ 1
l
thanks, keep you posted then šŸ™‚