Querying Databricks Delta Share tables using Spark engine

You can query remote Databricks Delta Share tables using the watsonx.data Spark engine through zero-copy data federation. Delta Sharing is an open protocol for secure exchange of large datasets, allowing Spark to read shared Delta tables directly from external storage without copying data.

This topic covers querying Delta tables shared from Databricks using a Delta Sharing profile file (.share) and the watsonx.data Spark application submission workflow.

For general information about Databricks integrations, including Unity Catalog-based access, see Integrating Databricks Unity Catalog in watsonx.data.

Before you begin

Databricks requirements:

  • An external location configured with AWS S3 or Cloudflare R2 in Databricks
  • A catalog configured to use that external location
  • Delta Sharing enabled for sharing outside your organization
  • A provisioned Delta Share and recipient configured in Databricks
  • A Delta Sharing profile file (.share format) downloaded from the Databricks recipient activation link

watsonx.data requirements:

  • Provisioned Spark engine (version 3.5 or later)
  • Network connectivity to Databricks workspace endpoints
  • A storage bucket accessible by the Spark engine for uploading the PySpark application script

Storage requirements:

  • AWS S3 or Cloudflare R2 configured as external location in Databricks
  • Storage access credentials:
    • AWS S3: Access key, secret key, and S3 region information
    • Cloudflare R2: Account ID, access key, and secret key
Important:
  • Delta Sharing tables are read-only from watsonx.data. Write operations are not supported.
  • SQL access using spark.sql() for Delta Sharing tables is not supported in watsonx.data Spark. The open-source runtime does not include the required Delta Sharing SQL connector integration. Use the DataFrame API (spark.read.format("deltaSharing")) instead.

Procedure

  1. Upload the Delta Sharing profile file to a storage volume.
    Note: This step applies to the Cloud Pak for Data deployment of watsonx.data only. For the SaaS deployment, upload the profile file to the same bucket where your PySpark application script is uploaded.
    1. Log in to IBM Software Hub.
    2. Click Navigation Menu > Storage volumes.
    3. Click New volume and provide the following details:
      • Volume name: Enter a name for the volume.
      • Type: Select New PVC.
      • Storage class: Select nfs-client.
      • Size: Enter the required storage size.
      • Mount path: Enter the mount path (for example, /mnts/conf).
    4. Click Add.
    5. Navigate to the created volume and click File browser.
    6. Upload your Delta Sharing profile file (for example, config.share) to the volume.
  2. Upload the PySpark application script to a storage bucket.

    Create a PySpark script using the following template and upload it to your storage bucket. The script reads a Delta Sharing table using the deltaSharing format and the path constructed from your profile file and table coordinates.

    """
    Delta Share reader for IBM watsonx.data Spark engine.
    Reads shared Delta tables using the Delta Sharing open protocol.
    """
    
    from pyspark.sql import SparkSession
    
    
    def read_delta_share_table(spark, config_path, share_name, schema_name, table_name):
        """
        Read a Delta Share table.
    
        Args:
            spark: SparkSession provided by the watsonx.data Spark engine
            config_path: Full path to the .share profile file
                         CP4D example:  /mnts/conf/config.share
                         SaaS example:  s3a://<bucket>/config.share
            share_name:  Name of the Delta Share
            schema_name: Schema name within the share
            table_name:  Table name within the schema
        Returns:
            DataFrame containing the shared table data
        """
        # Table path format: <config_path>#<share_name>.<schema_name>.<table_name>
        table_path = f"{config_path}#{share_name}.{schema_name}.{table_name}"
    
        print(f"Reading Delta Share table: {table_path}")
        df = spark.read.format("deltaSharing").load(table_path)
    
        print(f"Rows: {df.count():,}  Columns: {len(df.columns)}")
        df.printSchema()
        return df
    
    
    def main():
        CONFIG_PATH  = "<path_to_profile_file>/config.share"
        SHARE_NAME   = "<share_name>"
        SCHEMA_NAME  = "<schema_name>"
        TABLE_NAME   = "<table_name>"
    
        spark = SparkSession.builder.getOrCreate()
        print(f"Spark version: {spark.version}")
    
        df = read_delta_share_table(
            spark=spark,
            config_path=CONFIG_PATH,
            share_name=SHARE_NAME,
            schema_name=SCHEMA_NAME,
            table_name=TABLE_NAME,
        )
    
        print("Sample data (first 10 rows):")
        df.show(10, truncate=False)
        return df
    
    
    if __name__ == "__main__":
        df = main()

    Replace the following placeholders in the script:

    • <path_to_profile_file>: Mount path of the storage volume containing the profile file (CP4D), or the S3 path (SaaS). Example CP4D value: /mnts/conf.
    • <share_name>: Name of the Delta Share as configured in Databricks.
    • <schema_name>: Schema name within the share.
    • <table_name>: Table name within the schema.
  3. Submit the Spark application from watsonx.data.
    1. In the watsonx.data console, click Infrastructure manager and select your Spark engine.
    2. Click the Applications tab, then click Create application.
    3. In the Application path field, enter the path to your uploaded PySpark script.
      s3a://<bucket_name>/<script_name>.py
    4. In the Spark configuration properties field, add the following properties.

      Replace the placeholder values as described after the code block.

      spark.hadoop.fs.s3a.bucket.<bucket_name>.endpoint=<bucket_endpoint>
      spark.hadoop.fs.s3a.bucket.<bucket_name>.access.key=<access_key>
      spark.hadoop.fs.s3a.bucket.<bucket_name>.secret.key=<secret_key>
      spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension
      spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog
      spark.sql.parquet.fieldId.read.enabled=true
      spark.sql.shuffle.partitions=1
      spark.jars.packages=io.delta:delta-sharing-spark_<version>

      Replace the following placeholders:

      • <bucket_name>: Name of the bucket where the PySpark script is uploaded.
      • <bucket_endpoint>: Bucket endpoint URL without the https:// prefix.
      • <access_key>: Access key for the bucket.
      • <secret_key>: Secret key for the bucket.
      • <version>: Delta Sharing Spark package version. Use 4.0_2.13:4.2.0 for Spark 4.0 or 2.12:1.0.0 for Spark 3.5.
    5. In the Volume field, select the storage volume created in step 1 and enter its mount path.
      Note: This substep applies to Cloud Pak for Data deployments only. Skip this substep for SaaS deployments.
    6. Click Submit application.

Results

The Spark application runs and reads the shared Delta table directly from the external storage location. No data is copied into watsonx.data.

Example output

The following example shows a customers table shared from Databricks, queried from watsonx.data Spark using the profile file at /mnts/conf/config.share#your_share.your_schema.customers.

Table as seen in Databricks workspace (SELECT * FROM your_share.your_schema.customers):

customer_id  customer_name  city    email
-----------  -------------  ------  -----------------
1            Alice James    Kochi   alice@example.com
2            Bob Thomas     Mumbai  bob@example.com

Output from watsonx.data Spark:

+-----------+-------------+------+------------------+
|customer_id|customer_name|city  |email             |
+-----------+-------------+------+------------------+
|1          |Alice James  |Kochi |alice@example.com |
|2          |Bob Thomas   |Mumbai|bob@example.com   |
+-----------+-------------+------+------------------+

What to do next

Related information