-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add example and improve readme
- Loading branch information
Showing
12 changed files
with
137 additions
and
14 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
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,23 @@ | ||
# Databricks notebook source | ||
import sys | ||
from pathlib import Path | ||
|
||
MODULE_DIR = Path.cwd().parent | ||
sys.path.append(MODULE_DIR.as_posix()) | ||
|
||
# COMMAND ---------- | ||
|
||
from myjobpackage.processing import process_data | ||
|
||
# COMMAND ---------- | ||
|
||
input_table = dbutils.widgets.get('input_table') # noqa: F821 | ||
output_table = dbutils.widgets.get('output_table') # noqa: F821 | ||
|
||
# COMMAND ---------- | ||
|
||
process_data( | ||
session=spark, # noqa: F821 | ||
input_table=input_table, | ||
output_table=output_table, | ||
) |
File renamed without changes.
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,2 @@ | ||
{"id": 0, "time_utc": "2024-01-08T11:00:00", "name": "Jorge", "feature": 0.5876} | ||
{"id": 1, "time_utc": "2024-01-11T14:28:00", "name": "Ricardo", "feature": 0.42} |
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,2 @@ | ||
{"id": 0, "time_utc": "2024-01-08T11:00:00", "name": "Jorge", "result": 58.76} | ||
{"id": 1, "time_utc": "2024-01-11T14:28:00", "name": "Ricardo", "result": 42} |
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 @@ | ||
{ | ||
"type": "struct", | ||
"fields": | ||
[ | ||
{ | ||
"name": "id", | ||
"type": "long", | ||
"nullable": false, | ||
"metadata": {} | ||
}, | ||
{ | ||
"name": "time_utc", | ||
"type": "timestamp", | ||
"nullable": false, | ||
"metadata": {} | ||
}, | ||
{ | ||
"name": "name", | ||
"type": "string", | ||
"nullable": true, | ||
"metadata": {} | ||
}, | ||
{ | ||
"name": "feature", | ||
"type": "double", | ||
"nullable": true, | ||
"metadata": {} | ||
} | ||
] | ||
} |
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 @@ | ||
{ | ||
"type": "struct", | ||
"fields": | ||
[ | ||
{ | ||
"name": "id", | ||
"type": "long", | ||
"nullable": false, | ||
"metadata": {} | ||
}, | ||
{ | ||
"name": "time_utc", | ||
"type": "timestamp", | ||
"nullable": false, | ||
"metadata": {} | ||
}, | ||
{ | ||
"name": "name", | ||
"type": "string", | ||
"nullable": true, | ||
"metadata": {} | ||
}, | ||
{ | ||
"name": "result", | ||
"type": "double", | ||
"nullable": true, | ||
"metadata": {} | ||
} | ||
] | ||
} |
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,35 @@ | ||
import os | ||
|
||
from pyspark.sql import SparkSession | ||
from pyspark.testing import assertDataFrameEqual | ||
from pytest import fixture | ||
|
||
from example.myjobpackage.processing import process_data | ||
from pysparkdt import reinit_local_metastore, spark_base | ||
|
||
DATA_DIR = f'{os.path.dirname(__file__)}/data' | ||
JSON_TABLES_DIR = f'{DATA_DIR}/tables' | ||
TMP_DIR = f'{DATA_DIR}/tmp' | ||
METASTORE_DIR = f'{TMP_DIR}/metastore' | ||
|
||
|
||
@fixture(scope='module') | ||
def spark(): | ||
yield from spark_base(METASTORE_DIR) | ||
|
||
|
||
def test_process_data( | ||
spark: SparkSession, | ||
): | ||
reinit_local_metastore(spark, JSON_TABLES_DIR) | ||
process_data( | ||
session=spark, | ||
input_table='example_input', | ||
output_table='output', | ||
) | ||
output = spark.read.format('delta').table('output') | ||
expected = spark.read.format('delta').table('expected_output') | ||
assertDataFrameEqual( | ||
actual=output.select(sorted(output.columns)), | ||
expected=expected.select(sorted(expected.columns)), | ||
) |