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 write test code in databricks

rt-slowth
Contributor

 

 

 

 

from databricks.connect import DatabricksSession
from data.dbx_conn_info import DbxConnInfo

class SparkSessionManager:

    _instance = None
    _spark = None

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super(SparkSessionManager, cls).__new__(cls)
        return cls._instance

    def get_spark_session(self):
        if not self._spark:
            self._spark = DatabricksSession.builder.remote(
                host=f"https://{DbxConnInfo.retrieve_workspace_instance_name()}",
                token=DbxConnInfo.retrieve_token(),
                cluster_id=DbxConnInfo.retrieve_cluster_id()
            ).getOrCreate()
        return self._spark

 

 

 

 

When I write and run test code for this code, it keeps telling me that the databricks package doesn't exist. I don't know why.

0 REPLIES 0

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