cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Configure Databricks (spark) context from PyCharm

kmartin62
New Contributor III

Hello. I'm trying to connect to Databricks from my IDE (PyCharm) and then run delta table queries from there. However, the cluster I'm trying to access has to give me permission. In this case, I'd go to my cluster, run the cell which gives me permission and then go back to my PyCharm so I can query the tables. The question I'm trying to ask here is, is there some way to do this kind of configuration from PyCharm directly? This is the code I use to give permission

if StorageAccountName is not None and StorageAccountAccessKey is not None:
  print('Configuring the spark context...')
  spark_context._jsc.hadoopConfiguration().set(
    f"fs.azure.account.key.{StorageAccountName}.blob.core.windows.net",
    StorageAccountAccessKey)

I use it this way, and not directly as a Spark configuration, because my StorageAccountAccessKey is stored in key-vault and a cluster might have info from various storage accounts which means I'd have various access keys, etc.

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

"I'm trying to connect to Databricks from my IDE (PyCharm) and then run delta table queries from there."

If you are going to deploy later your code to databricks the only solutions which I see is to use databricks-connect or just make development environment in cloud and work there (and use repos for pull requests to production).

If your code will not be deployed to databricks and you want just to query table from somewhere else you can use just JDBC/ODBC connector. If you want to make cluster and different administrator operations you can install databricks-cli and than extend it inside your code something like below example:

from databricks_cli.sdk import ApiClient

from databricks_cli.sdk import service

host = "your_host"

token = "your_token"

client = ApiClient(host=host, token=token)

workspace = service.WorkspaceService(client)

View solution in original post

9 REPLIES 9

Hubert-Dudek
Esteemed Contributor III

Are you using databricks-connect ?

For some bad reason, I can't use databricks-connect. I get module java.base does not "opens java.nio" to unnamed module error and I can't solve it nor I know what it is. For now, I use python-sql-connector (https://docs.databricks.com/dev-tools/python-sql-connector.html)

Hubert-Dudek
Esteemed Contributor III

"I'm trying to connect to Databricks from my IDE (PyCharm) and then run delta table queries from there."

If you are going to deploy later your code to databricks the only solutions which I see is to use databricks-connect or just make development environment in cloud and work there (and use repos for pull requests to production).

If your code will not be deployed to databricks and you want just to query table from somewhere else you can use just JDBC/ODBC connector. If you want to make cluster and different administrator operations you can install databricks-cli and than extend it inside your code something like below example:

from databricks_cli.sdk import ApiClient

from databricks_cli.sdk import service

host = "your_host"

token = "your_token"

client = ApiClient(host=host, token=token)

workspace = service.WorkspaceService(client)

So you suggest to go with databricks-connect, I see. Do you have any ideas what could cause the error explained in my previous comment and how could I fix it?

Hubert-Dudek
Esteemed Contributor III
  • Java Runtime Environment (JRE) 8. The client has been tested with the OpenJDK 8 JRE. The client does not support Java 11.
  • The minor version of your client Python installation must be the same as the minor Python version of your Databricks cluster.

------------------------------------------------------------------------------

Databricks Runtime version >> Python version

------------------------------------------------------------------------------

9.1 LTS ML, 9.1 LTS >> 3.8

7.3 LTS ML, 7.3 LTS >> 3.7

6.4 ML, 6.4 >> 3.7

5.5 LTS ML >> 3.6

5.5 LTS >> 3.5

------------------------------------------------------------------------------

currently only above runtimes are supported

more here https://docs.databricks.com/dev-tools/databricks-connect.html

kmartin62
New Contributor III

Thanks! I downgraded to Java 8 and it works now. I must have the winutils from hadoop added as env var, right? Without it, if I delete it let's say, it won't work?

Hubert-Dudek
Esteemed Contributor III

yes it is necessary and path to folder have to be added PATH=%PATH%;%HADOOP_PREFIX%\bin

Any chance to be selected as the best answer? 🙂

kmartin62
New Contributor III

Sure 🙂

Hi @Martin Kostadinov​ ,

Did you check the troubleshooting section from DBconnect docs? did this help you to find the response to your issue? docs here https://docs.databricks.com/dev-tools/databricks-connect.html#troubleshooting

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.