How to import SqlDWRelation from com.databricks.spark.sqldw

WillJMSFT
New Contributor III

Hello, All - I'm working on a project using the SQL DataWarehouse connector built into Databricks (https://docs.databricks.com/data/data-sources/azure/synapse-analytics.html). From there, I'm trying to extract information from the logical plan / logical relation which will help me identify the table and database (or at least JDBC URL) that is being used to query the data.

I believe I need to cast from BaseRelation to SqlDWRelation after extracting the relation from the logical plan as seen below.

val df = spark.read.format("com.databricks.spark.sqldw")
.option("url", sqlDwUrl)
.option("tempDir", tempDir)
.option("forwardSparkAzureStorageCredentials", "true")
.option("dbTable", tableName)
.load()
val logicalPlan = df.queryExecution.logical
val logicalRelation = logicalPlan.asInstanceOf[LogicalRelation]
val sqlBaseRelation = logicalRelation.relation

However, after doing so, I try to cast `sqlBaseRelation.asInstanceOf[SqlDWRelation]` and it results in an error that looks like:

object SqlDWRelation in package sqldw cannot be accessed in package com.databricks.spark.sqldw

Edit: The above error makes sense since it's a private class 😞

When looking at the jar provided in the workspace for the SQL DW connector, I can see SqlDWRelation as a (edit public ) private class but it's not available via tab / autocomplete inside a Databricks Notebook.

Has anyone here ever attempted to work with a SqlDWRelation and extract information about the table and database names for the given logicalrelation? Thank you for any guidance!

In my environment, I'm using:

  • Azure Databricks
  • Databricks Runtime 9.1
  • Scala Notebook
  • Azure Synapse SQL Pools