Forum Discussion
Extract Data from Databricks Unity Catalog
- 2 years ago
I found a solution to my previous mentioned problem. The connection from Fabric Notebook to Databricks Unity Catalog is now working as expected - but not as described initially by Microsoft Documentation.
What I did now - in case anybody meets the same issue:1. Download the Databricks JDBC Driver and store the .jar to Fabric Lakehouse.
2. Create a custom environment in Fabric
3. Add a spark property for spark.jars that is pointing to the ABFSS location of the uploaded .jar file:
4. In the Notebook itself, connect to this custom environment and use this call for reading the data:personal_access_token = "XXX" jdbc_url = "jdbc:databricks://adb-XXX.azuredatabricks.net:443/default" http_path = "sql/protocolv1/o/XXX/XXX" query = "[catalog].[schema].[table]" # or "(SELECT [selection] FROM [table]) as alias" df = (spark.read.format("jdbc") .option("url", jdbc_url) .option("dbtable", query) .option("user", "token") .option("password", personal_access_token) .option("driver", "com.databricks.client.jdbc.Driver") .option("ssl", "1") .option("ThriftTransport", "2") .option("AuthMech", "3") .option("httpPath", http_path) .option("UseNativeQuery", "0") .load())The option "UseNativeQuery" is necessary too. Otherwise the jdbc dialect seems to be wrong, causing the before mentioned issue with data types (+ issues with quotes).
Thanks v-cboorla-msft for your help.
Hi H26027
Thanks for using Microsoft Fabric Community.
As I understnad that you’re trying to connect to Databricks UnityCatalog tables from Fabric Notebooks using the Databricks JDBC driver. The error message you’re encountering, java.lang.ClassNotFoundException: com.databricks.client.jdbc.Driver, indicates that the JDBC driver class is not found.
Could you please make sure that you’ve correctly added the Databricks JDBC driver .jar file to your custom environment. Double-check the path and make sure it’s accessible to your Spark session.
Confirm that the driver version matches your Databricks environment.
If the issue still persists please do let us know. Glad to help.
Please refer to this documentation which might help you.
Documentation link : Integrating Microsoft Fabric and Databricks Unity Catalog
I hope this information helps.
Thanks.
- H260272 years agoRegular Visitor
The exact steps I did were:
Create a custom environment (preview) and upload a custom library to it:
After the upload, I published these changes.Then I referenced this environment as the default environment for my workspace.
The Notebook that I am using is connected to this environment.
Then I just launched the code I gave in my initial post. I did not call this library specifically in the notebook though. Is that necessary? If so, how?
Thanks.- v-cboorla-msft2 years agoMicrosoft Employee
Hi H26027
Apologize for the delay in response from my end.
Following up to see if you have a resolution yet. In case if you have any resolution please do share that same with the community as it can be helpful to others .
If the issue still persists, kindly provide the following additional information for further assistance.
To ensure compatibility and troubleshoot the Databricks JDBC driver error you're encountering, could you please confirm the version of your Databricks? Version compatibility might be a potential cause. We can troubleshoot by verifying the appropriate JDBC driver for your specific Databricks runtime version. This might help you resolve the issue.
For additional information please refer : Unity Catalog limitations
I hope this information helps. Please do let us know if you have any further queries.
Thanks.
- H260272 years agoRegular Visitor
Hi v-cboorla-msft,
I am using databricks cluster with runtime version 13.3 LTS in shared access mode that is unity catalog enabled.
The JDBC Driver I downloaded is the latest (2.6.36) downloaded from here https://www.databricks.com/spark/jdbc-drivers-archive.
The Databricks side is not the problem though, since the fabric notebook already says it cannot find the driver. I believe the driver is not loaded in the environment correctly, but I don't see anything I did wrong.For testing purpose I added a public library from pip to the same environment. This library is available in the notebook without any problem.