File tree Expand file tree Collapse file tree 5 files changed +37
-17
lines changed Expand file tree Collapse file tree 5 files changed +37
-17
lines changed Original file line number Diff line number Diff line change 33## For defining dependencies used by jobs in Databricks Workflows, see
44## https://docs.databricks.com/dev-tools/bundles/library-dependencies.html
55
6+ ## Add code completion support for DLT
7+ databricks-dlt
8+
69## pytest is the default package used for testing
710pytest
811
Original file line number Diff line number Diff line change 11from pyspark .sql import SparkSession
22
3- def get_taxis ():
4- spark = SparkSession .builder .getOrCreate ()
3+ def get_taxis (spark : SparkSession ):
54 return spark .read .table ("samples.nyctaxi.trips" )
65
76def main ():
8- get_taxis ().show (5 )
7+ get_taxis (spark ).show (5 )
98
109if __name__ == '__main__' :
1110 main ()
Original file line number Diff line number Diff line change 1919 },
2020 {
2121 "cell_type" : " code" ,
22- "execution_count" : 0 ,
22+ "execution_count" : null ,
2323 "metadata" : {
2424 "application/vnd.databricks.v1+cell" : {
2525 "cellMetadata" : {},
3333 "source" : [
3434 " # Import DLT and src/default_python\n " ,
3535 " import dlt\n " ,
36- " import sys\n " ,
3736 " from pyspark.sql.functions import expr\n " ,
3837 " from default_python import main"
3938 ]
4039 },
4140 {
4241 "cell_type" : " code" ,
43- "execution_count" : 0 ,
42+ "execution_count" : null ,
4443 "metadata" : {
4544 "application/vnd.databricks.v1+cell" : {
4645 "cellMetadata" : {},
5453 "source" : [
5554 " @dlt.view\n " ,
5655 " def taxi_raw():\n " ,
57- " return main.get_taxis()\n " ,
56+ " return main.get_taxis(spark )\n " ,
5857 " \n " ,
5958 " @dlt.table\n " ,
6059 " def filtered_taxis():\n " ,
7978 },
8079 "language_info" : {
8180 "name" : " python" ,
82- "version" : " 3.11.4 "
81+ "version" : " 3.11.6 "
8382 }
8483 },
8584 "nbformat" : 4 ,
Original file line number Diff line number Diff line change 1919 },
2020 {
2121 "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 ,
2333 "metadata" : {
2434 "application/vnd.databricks.v1+cell" : {
2535 "cellMetadata" : {
3646 "source" : [
3747 " from default_python import main\n " ,
3848 " \n " ,
39- " main.get_taxis().show(10)"
49+ " main.get_taxis(spark ).show(10)"
4050 ]
4151 }
4252 ],
5666 "name" : " python3"
5767 },
5868 "language_info" : {
69+ "codemirror_mode" : {
70+ "name" : " ipython" ,
71+ "version" : 3
72+ },
73+ "file_extension" : " .py" ,
74+ "mimetype" : " text/x-python" ,
5975 "name" : " python" ,
60- "version" : " 3.11.4"
76+ "nbconvert_exporter" : " python" ,
77+ "pygments_lexer" : " ipython3" ,
78+ "version" : " 3.11.6"
6179 }
6280 },
6381 "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
32from default_python import main
3+ from pytest import fixture
44
55# Create a new Databricks Connect session. If this fails,
66# check that you have configured Databricks Connect correctly.
77# See https://docs.databricks.com/dev-tools/databricks-connect.html.
88
9- SparkSession .builder = DatabricksSession .builder
10- SparkSession .builder .getOrCreate ()
9+ @fixture (scope = "session" )
10+ def spark ():
11+ return SparkSession .builder .getOrCreate ()
1112
12- def test_main ():
13- taxis = main .get_taxis ()
13+ def test_main (spark ):
14+ taxis = main .get_taxis (spark )
1415 assert taxis .count () > 5
You can’t perform that action at this time.
0 commit comments