Skip to content

Commit d8084a7

Browse files
committed
fix running main
1 parent 931f1cd commit d8084a7

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

default_python/scratch/exploration.ipynb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"%load_ext autoreload\n",
10+
"%autoreload 2"
11+
]
12+
},
313
{
414
"cell_type": "code",
515
"execution_count": null,
@@ -21,7 +31,7 @@
2131
"sys.path.append('../src')\n",
2232
"from default_python import main\n",
2333
"\n",
24-
"main.get_taxis().show(10)"
34+
"main.get_taxis(spark).show(10)"
2535
]
2636
}
2737
],
@@ -41,8 +51,16 @@
4151
"name": "python3"
4252
},
4353
"language_info": {
54+
"codemirror_mode": {
55+
"name": "ipython",
56+
"version": 3
57+
},
58+
"file_extension": ".py",
59+
"mimetype": "text/x-python",
4460
"name": "python",
45-
"version": "3.11.4"
61+
"nbconvert_exporter": "python",
62+
"pygments_lexer": "ipython3",
63+
"version": "3.11.8"
4664
}
4765
},
4866
"nbformat": 4,

default_python/src/default_python/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from pyspark.sql import SparkSession
22

3-
def get_taxis(spark: SparkSession):
3+
def get_taxis(spark: SparkSession):
44
return spark.read.table("samples.nyctaxi.trips")
55

66
def main():
7+
from databricks.connect import DatabricksSession as SparkSession
8+
spark = SparkSession.builder.getOrCreate()
79
get_taxis(spark).show(5)
810

911
if __name__ == '__main__':

default_python/src/notebook.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"name": "python",
7676
"nbconvert_exporter": "python",
7777
"pygments_lexer": "ipython3",
78-
"version": "3.11.6"
78+
"version": "3.11.8"
7979
}
8080
},
8181
"nbformat": 4,

default_python/tests/main_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from databricks.connect import DatabricksSession as SparkSession
2+
from pytest import fixture
23
from default_python import main
34
from pytest import fixture
45

5-
# Create a new Databricks Connect session. If this fails,
6-
# check that you have configured Databricks Connect correctly.
7-
# See https://docs.databricks.com/dev-tools/databricks-connect.html.
8-
96
@fixture(scope="session")
107
def spark():
11-
return SparkSession.builder.getOrCreate()
8+
spark = SparkSession.builder.getOrCreate()
9+
yield spark
10+
spark.stop()
11+
1212

13-
def test_main(spark):
13+
def test_main(spark: SparkSession):
1414
taxis = main.get_taxis(spark)
1515
assert taxis.count() > 5

0 commit comments

Comments
 (0)