-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test data frames with pyspark (#135)
* Add tags to test_dual_write * Add the Python 3.5 example. * Fix up style and imports * Remove excess newline * Fix new test
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
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,39 @@ | ||
import os | ||
import tempfile | ||
|
||
# tag::test[] | ||
import unittest | ||
from pyspark.sql import SparkSession | ||
from pyspark.sql.functions import current_timestamp | ||
from pyspark.sql.types import Row | ||
from pyspark.testing.utils import assertDataFrameEqual | ||
from .dual_write import DualWriteExample | ||
|
||
|
||
class DualWriteTest(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.spark = SparkSession.builder.appName( | ||
"Testing PySpark Example" | ||
).getOrCreate() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.spark.stop() | ||
|
||
def test_always_passes(self): | ||
self.assertTrue(True) | ||
|
||
def test_actual_dual_write(self): | ||
tempdir = tempfile.mkdtemp() | ||
p1 = os.path.join(tempdir, "data1") | ||
p2 = os.path.join(tempdir, "data2") | ||
df = self.spark.createDataFrame([Row("timbit"), Row("farted")], ["names"]) | ||
combined = df.withColumn("times", current_timestamp()) | ||
DualWriteExample().do_write(combined, p1, p2) | ||
df1 = self.spark.read.format("parquet").load(p1) | ||
df2 = self.spark.read.format("parquet").load(p2) | ||
assertDataFrameEqual(df2.select("times"), df1, 0.1) | ||
|
||
|
||
# end::test[] |
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