File tree 4 files changed +33
-12
lines changed
4 files changed +33
-12
lines changed Original file line number Diff line number Diff line change 6
6
## pytest is the default package used for testing
7
7
pytest
8
8
9
+ ## Add code completion support for DLT
10
+ databricks-dlt
11
+
9
12
## databricks-connect can be used to run parts of this project locally.
10
13
## See https://docs.databricks.com/dev-tools/databricks-connect.html.
11
14
##
Original file line number Diff line number Diff line change 1
1
from pyspark .sql import SparkSession
2
2
3
- def get_taxis ():
4
- spark = SparkSession .builder .getOrCreate ()
3
+ def get_taxis (spark : SparkSession ):
5
4
return spark .read .table ("samples.nyctaxi.trips" )
6
5
7
6
def main ():
8
- get_taxis ().show (5 )
7
+ get_taxis (spark ).show (5 )
9
8
10
9
if __name__ == '__main__' :
11
10
main ()
Original file line number Diff line number Diff line change 19
19
},
20
20
{
21
21
"cell_type" : " code" ,
22
- "execution_count" : 0 ,
22
+ "execution_count" : null ,
23
+ "metadata" : {},
24
+ "outputs" : [],
25
+ "source" : [
26
+ " %load_ext autoreload\n " ,
27
+ " %autoreload 2"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type" : " code" ,
32
+ "execution_count" : null ,
23
33
"metadata" : {
24
34
"application/vnd.databricks.v1+cell" : {
25
35
"cellMetadata" : {
36
46
"source" : [
37
47
" from default_python import main\n " ,
38
48
" \n " ,
39
- " main.get_taxis().show(10)"
49
+ " main.get_taxis(spark ).show(10)"
40
50
]
41
51
}
42
52
],
56
66
"name" : " python3"
57
67
},
58
68
"language_info" : {
69
+ "codemirror_mode" : {
70
+ "name" : " ipython" ,
71
+ "version" : 3
72
+ },
73
+ "file_extension" : " .py" ,
74
+ "mimetype" : " text/x-python" ,
59
75
"name" : " python" ,
60
- "version" : " 3.11.4"
76
+ "nbconvert_exporter" : " python" ,
77
+ "pygments_lexer" : " ipython3" ,
78
+ "version" : " 3.11.6"
61
79
}
62
80
},
63
81
"nbformat" : 4 ,
Original file line number Diff line number Diff line change 1
- from databricks .connect import DatabricksSession
2
- from pyspark .sql import SparkSession
1
+ from databricks .connect import DatabricksSession as SparkSession
3
2
from default_python import main
3
+ from pytest import fixture
4
4
5
5
# Create a new Databricks Connect session. If this fails,
6
6
# check that you have configured Databricks Connect correctly.
7
7
# See https://docs.databricks.com/dev-tools/databricks-connect.html.
8
8
9
- SparkSession .builder = DatabricksSession .builder
10
- SparkSession .builder .getOrCreate ()
9
+ @fixture (scope = "session" )
10
+ def spark ():
11
+ return SparkSession .builder .getOrCreate ()
11
12
12
- def test_main ():
13
- taxis = main .get_taxis ()
13
+ def test_main (spark ):
14
+ taxis = main .get_taxis (spark )
14
15
assert taxis .count () > 5
You can’t perform that action at this time.
0 commit comments