Skip to content

Commit

Permalink
Inner dev loop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fjakobs committed Jan 23, 2024
1 parent dc7b2e6 commit c62fe05
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
3 changes: 3 additions & 0 deletions default_python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
## pytest is the default package used for testing
pytest

## Add code completion support for DLT
databricks-dlt

## databricks-connect can be used to run parts of this project locally.
## See https://docs.databricks.com/dev-tools/databricks-connect.html.
##
Expand Down
5 changes: 2 additions & 3 deletions default_python/src/default_python/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from pyspark.sql import SparkSession

def get_taxis():
spark = SparkSession.builder.getOrCreate()
def get_taxis(spark: SparkSession):
return spark.read.table("samples.nyctaxi.trips")

def main():
get_taxis().show(5)
get_taxis(spark).show(5)

if __name__ == '__main__':
main()
24 changes: 21 additions & 3 deletions default_python/src/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"application/vnd.databricks.v1+cell": {
"cellMetadata": {
Expand All @@ -36,7 +46,7 @@
"source": [
"from default_python import main\n",
"\n",
"main.get_taxis().show(10)"
"main.get_taxis(spark).show(10)"
]
}
],
Expand All @@ -56,8 +66,16 @@
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.11.4"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
13 changes: 7 additions & 6 deletions default_python/tests/main_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from databricks.connect import DatabricksSession
from pyspark.sql import SparkSession
from databricks.connect import DatabricksSession as SparkSession
from default_python import main
from pytest import fixture

# Create a new Databricks Connect session. If this fails,
# check that you have configured Databricks Connect correctly.
# See https://docs.databricks.com/dev-tools/databricks-connect.html.

SparkSession.builder = DatabricksSession.builder
SparkSession.builder.getOrCreate()
@fixture(scope="session")
def spark():
return SparkSession.builder.getOrCreate()

def test_main():
taxis = main.get_taxis()
def test_main(spark):
taxis = main.get_taxis(spark)
assert taxis.count() > 5

0 comments on commit c62fe05

Please sign in to comment.