-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from MiguelPeralvo/dev
Dev
- Loading branch information
Showing
10 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.cache | ||
__pycache__ | ||
build/ | ||
dist/ | ||
gill.egg-info/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# DBX | ||
|
||
An example PySpark project. | ||
|
||
The project uses pyenv and pytest. It also can be easily leveraged to generate egg/wheel files. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pyspark.sql.functions as F | ||
|
||
def with_status(df): | ||
return df.withColumn("status", F.lit("checked")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pyspark.sql import SparkSession | ||
from functools import lru_cache | ||
|
||
@lru_cache(maxsize=None) | ||
def get_spark(): | ||
return (SparkSession.builder | ||
.appName("dbxdemo") | ||
.getOrCreate()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pytest==3.2.2 | ||
pyspark==2.4.5 | ||
setuptools==28.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from setuptools import setup | ||
|
||
setup(name='dbxdemo', | ||
version='0.0.15', | ||
description='A sample PySpark application - 0.0.15', | ||
author='Peter Tamisin', | ||
author_email='peter.tamisin@databricks.com', | ||
url='www.databricks.com', | ||
packages=['dbxdemo'], | ||
zip_safe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
|
||
from dbxdemo.spark import get_spark | ||
from dbxdemo.appendcol import with_status | ||
|
||
class TestAppendCol(object): | ||
|
||
def test_with_status(self): | ||
source_data = [ | ||
("pete", "tamisin", "peter.tamisin@databricks.com"), | ||
("jason", "baer", "jason.baer@databricks.com") | ||
] | ||
source_df = get_spark().createDataFrame( | ||
source_data, | ||
["first_name", "last_name", "email"] | ||
) | ||
|
||
actual_df = with_status(source_df) | ||
|
||
expected_data = [ | ||
("pete", "tamisin", "peter.tamisin@databricks.com", "checked"), | ||
("jason", "baer", "jason.baer@databricks.com", "checked") | ||
] | ||
expected_df = get_spark().createDataFrame( | ||
expected_data, | ||
["first_name", "last_name", "email", "status"] | ||
) | ||
|
||
assert(expected_df.collect() == actual_df.collect()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Databricks notebook source | ||
from dbxdemo import appendcol | ||
|
||
# COMMAND ---------- | ||
|
||
display(appendcol.with_status(spark.read.parquet("/databricks-datasets/samples/lending_club/parquet/"))) | ||
|
||
|