-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PySpark dataframe related tests (#5906)
Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
- Loading branch information
1 parent
207cc03
commit 5678344
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
tests/adapter/dbt/tests/adapter/python_model/test_spark.py
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,73 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt | ||
|
||
PANDAS_MODEL = """ | ||
import pandas as pd | ||
def model(dbt, session): | ||
dbt.config( | ||
materialized="table", | ||
) | ||
df = pd.DataFrame( | ||
{'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'], | ||
'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'], | ||
'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48], | ||
'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]} | ||
) | ||
return df | ||
""" | ||
PYSPARK_MODEL = """ | ||
def model(dbt, session): | ||
dbt.config( | ||
materialized="table", | ||
) | ||
df = spark.createDataFrame( | ||
[ | ||
("Buenos Aires", "Argentina", -34.58, -58.66), | ||
("Brasilia", "Brazil", -15.78, -47.91), | ||
("Santiago", "Chile", -33.45, -70.66), | ||
("Bogota", "Colombia", 4.60, -74.08), | ||
("Caracas", "Venezuela", 10.48, -66.86), | ||
], | ||
["City", "Country", "Latitude", "Longitude"] | ||
) | ||
return df | ||
""" | ||
|
||
PANDAS_ON_SPARK_MODEL = """ | ||
import pyspark.pandas as ps | ||
def model(dbt, session): | ||
dbt.config( | ||
materialized="table", | ||
) | ||
df = ps.DataFrame( | ||
{'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'], | ||
'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'], | ||
'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48], | ||
'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]} | ||
) | ||
return df | ||
""" | ||
|
||
|
||
class BasePySparkTests: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"pandas_df.py": PANDAS_MODEL, | ||
"pyspark_df.py": PYSPARK_MODEL, | ||
"pandas_on_spark_df.py": PANDAS_ON_SPARK_MODEL, | ||
} | ||
|
||
def test_different_dataframes(self, project): | ||
# test | ||
results = run_dbt(["run"]) | ||
assert len(results) == 3 |