File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
src/databricks/labs/pytester/fixtures Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -11,22 +11,29 @@ def spark(ws: WorkspaceClient):
1111 """
1212 Get Databricks Connect Spark session. Requires `databricks-connect` package to be installed.
1313
14+ To enable serverless set the local environment variable DATABRICKS_SERVERLESS_COMPUTE_ID to auto.
15+ If this environment variable is set, Databricks Connect ignores the cluster_id.
16+
1417 Usage:
1518 ```python
1619 def test_databricks_connect(spark):
1720 rows = spark.sql("SELECT 1").collect()
1821 assert rows[0][0] == 1
1922 ```
2023 """
21- if not ws .config .cluster_id :
22- skip ("No cluster_id found in the environment" )
23- ws .clusters .ensure_cluster_is_running (ws .config .cluster_id )
24+ if not ws .config .serverless_compute_id :
25+ if not ws .config .cluster_id :
26+ skip ("No cluster_id found in the environment" )
27+ ws .clusters .ensure_cluster_is_running (ws .config .cluster_id )
28+
2429 try :
2530 # pylint: disable-next=import-outside-toplevel
2631 from databricks .connect import ( # type: ignore[import-untyped]
2732 DatabricksSession ,
2833 )
2934
35+ if ws .config .serverless_compute_id :
36+ return DatabricksSession .builder .sdkConfig (ws .config ).serverless (True ).getOrCreate ()
3037 return DatabricksSession .builder .sdkConfig (ws .config ).getOrCreate ()
3138 except ImportError :
3239 skip ("Please run `pip install databricks-connect`" )
You can’t perform that action at this time.
0 commit comments