cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

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
1 ACCEPTED SOLUTION

Accepted Solutions

-werners-
Esteemed Contributor III

Lol so I was typing a response but now I see you edited your post.

A private method cannot be called indeed.

I worked with the connector but only to run queries and such, not to fetch metadata.

But the golden rule is: if autocomplete shows it, you can use it.

Maybe with a lot of effort because of missing docs, but it can be done.

View solution in original post

5 REPLIES 5

-werners-
Esteemed Contributor III

Have you tried to pass as simple query to Synapse to see if that works?

WillJMSFT
New Contributor III

@Werner Stinckensโ€‹  Thanks for the reply! The SQL DW Connector itself is working just fine and I can retrieve the results from the SQL DW. I'm trying to extract the metadata (i.e. the Server, Database, and Table name) from the logical plan (or through any other means).

-werners-
Esteemed Contributor III

Lol so I was typing a response but now I see you edited your post.

A private method cannot be called indeed.

I worked with the connector but only to run queries and such, not to fetch metadata.

But the golden rule is: if autocomplete shows it, you can use it.

Maybe with a lot of effort because of missing docs, but it can be done.

WillJMSFT
New Contributor III

Ah! Yes! Sorry about that! I realized this morning that it was a private class and that's why I wasn't seeing it show up in autocomplete.

The next step is to figure out how we can still access that data even when it's using a BaseRelation and not just the (private) SqlDWRelation.

I really appreciate your replies, @werners!

Hi @Will Johnsonโ€‹ ,

If @Werner Stinckensโ€‹ 's reply helped you to solved this issue, could you select it as best response? it will help to move it to the top.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group