Connect Soda to Apache Spark

Access configuration details to connect Soda to a Spark data source.

For Soda to run quality scans on your data, you must configure it to connect to your data source. To learn how to set up Soda and configure it to connect to your data sources, see Get started.

Spark packages

There are several Soda Library install packages for Spark.

Package
Description

Enables you to pass dataframe objects into Soda scans programatically, after you have associated the temporary tables to DataFrames via the Spark API. - For use with programmatic Soda scans, only. - Supports Delta Lake Tables on Databricks. - Use for Spark DataFrames on Databricks.

A package you add to soda-spark-df if you are using Apache Hive.

A package you add to soda-spark-df if you are using ODBC.

A package you use to install Soda Library for Databricks SQL on the Databricks Lakehouse Platform.

Connect to Spark DataFrames

  • For use with programmatic Soda scans, only.

  • Unlike other data sources, Soda Library for SparkDF does not require a configuration YAML file to run scans against Spark DataFrames.

A Spark cluster contains a distributed collection of data. Spark DataFrames are distributed collections of data that are organized into named columns, much like a table in a database, and which are stored in-memory in a cluster.

To make a DataFrame available to Soda Library to run scans against, you must use a driver program like PySpark and the Spark API to link DataFrames to individual, named, temporary tables in the cluster. You pass this information into a Soda scan programatically. You can also pass Soda Cloud connection details programmatically; see below.

  1. If you are not installing Soda Library Spark DataFrames on a cluster, skip to step 2. To install Soda Library Spark DataFrames on a cluster, such as a Kubernetes cluster or a Databricks cluster, install libsasl2-dev before installing soda-spark-df. For Ubuntu users, install libsasl2-dev using the following command:

sh sudo apt-get -y install unixodbc-dev libsasl2-dev gcc python-dev
  1. If you are not using Spark with Hive or ODBC, skip to step 3. Otherwise, install the separate dependencies as needed, and configure connection details for each dependency; see below.

  • for Hive, use: pip install -i https://pypi.cloud.soda.io soda-spark[hive] and configure

  • for ODBC, use: pip install -i https://pypi.cloud.soda.io soda-spark[odbc] and configure

  1. Install soda-spark-df (see Install Soda Library) and confirm that you have completed the following.

  • set up a a Spark session

  • confirm that your Spark cluster contains one or more DataFrames

  1. Use the Spark API to link the name of a temporary table to a DataFrame. In this example, the name of the table is customers.

  1. Use the Spark API to link a DataFrame to the name of each temporary table against which you wish to run Soda scans. Refer to PySpark documentation.

  2. Define a programmatic scan for the data in the DataFrames, and include one extra method to pass all the DataFrames to Soda Library: add_spark_session(self, spark_session, data_source_name: str). The default value for data_source_name is "spark_df"; best practice dictates that you customize the name to your implementation. Refer to the example below.

If you are using reference checks with a Spark or Databricks data source to validate the existence of values in two datasets within the same schema, you must first convert your DataFrames into temp views to add them to the Spark session, as in the following example.

Connect Soda Library for SparkDF to Soda Cloud

Unlike other data sources, Soda Library does not require a configuration YAML file to run scans against Spark DataFrames. It is for use with programmatic Soda scans, only.

Therefore, to connect to Soda Cloud, include the Soda Cloud API keys in your programmatic scan using either add_configuration_yaml_file(file_path) or scan.add_configuration_yaml_str(config_string) as in the example below.

Use Soda Library with Spark DataFrames on Databricks

Use the soda-spark-df package to connect to Databricks using a Notebook. 🎥 Watch a video that demonstrates how to add Soda to your Databricks pipeline: https://go.soda.io/soda-databricks-video

  1. Follow steps 1-2 in the instructions to install soda-spark-df.

  2. Reference the following Notebook example to connect to Databricks.

If you are using reference checks with a Spark or Databricks data source to validate the existence of values in two datasets within the same schema, you must first convert your DataFrames into temp views to add them to the Spark session, as in the following example.

Connect to Spark for Hive

An addition to soda-spark-df, install and configure the soda-spark[hive] package if you use Apache Hive.

Property
Required

type

required

method

required

username

required

password

required

host

required

port

required

catalog

required

auth_method

required

Connect to Spark for ODBC

An addition to soda-spark-df, install and configure the soda-spark[odbc] package if you use ODBC.

Property
Required

type

required

method

required

driver

required

host

required

port

required

token

required

organization

required

cluster

required

server_side_parameters

required

Connect to Spark for Databricks SQL

  1. Install soda-spark-df (see above) and soda-spark[databricks] to connect to Databricks SQL. Refer to Install Soda Library for details.

  1. If you have not done so already, install databricks-sql-connector. Refer to Databricks documentation for details.

  2. Configure the data source connection in your configuration.yml file as per the following example.

Property
Required

type

required

method

required

catalog

required

schema

required

host

required

token

required

Test the data source connection

To confirm that you have correctly configured the connection details for the data source(s) in your configuration YAML file, use the test-connection command. If you wish, add a -V option to the command to return results in verbose mode in the CLI.

soda test-connection -d my_datasource -c configuration.yml -V

Supported data types

Category
Data type

text

CHAR, VARCHAR, TEXT

number

NUMERIC, BIT, SMALLMONEY, INT, MONEY, FLOAT, REAL

time

DATE, TIME, DATETIME, DATETIMEOFFSET

Not supported:

  • BIGINT

  • BOOLEAN

  • DECIMAL

  • TIMESTAMP

Last updated

Was this helpful?