Skip to content

Commit

Permalink
Make code compatible with spark 3.2 (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
drudim committed Dec 17, 2022
1 parent 77e4c05 commit 7267a91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sparkly/writer.py
Expand Up @@ -50,7 +50,7 @@ class SparklyWriter(object):
"""
def __init__(self, df):
self._df = df
self._spark = df.sparkSession
self._spark = df.sql_ctx.sparkSession

def by_url(self, url):
"""Write a dataframe to a destination specified by `url`.
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/test_utils.py
Expand Up @@ -215,15 +215,15 @@ def test_type_mismatch(self):
{'f1': T.IntegerType()},
)

with self.assertRaisesRegex(TypeError, r'f1 is IntegerType\(\), expected LongType\(\)'):
with self.assertRaisesRegex(TypeError, r'f1 is IntegerType\(?\)?, expected LongType\(?\)?'):
schema_has(
T.StructType([T.StructField('f1', T.IntegerType())]),
T.StructType([T.StructField('f1', T.LongType())]),
)

with self.assertRaisesRegex(
TypeError,
r'f1\.element\.s1 is IntegerType\(\), expected LongType\(\)',
r'f1\.element\.s1 is IntegerType\(?\)?, expected LongType\(?\)?',
):
schema_has(
T.StructType([
Expand All @@ -242,20 +242,26 @@ def test_type_mismatch(self):

with self.assertRaisesRegex(
TypeError,
r'element is IntegerType\(\), expected LongType\(\)',
r'element is IntegerType\(?\)?, expected LongType\(?\)?',
):
schema_has(
T.ArrayType(T.IntegerType()),
T.ArrayType(T.LongType()),
)

with self.assertRaisesRegex(TypeError, r'key is StringType\(\), expected LongType\(\)'):
with self.assertRaisesRegex(
TypeError,
r'key is StringType\(?\)?, expected LongType\(?\)?',
):
schema_has(
T.MapType(T.StringType(), T.IntegerType()),
T.MapType(T.LongType(), T.IntegerType()),
)

with self.assertRaisesRegex(TypeError, r'value is IntegerType\(\), expected LongType\(\)'):
with self.assertRaisesRegex(
TypeError,
r'value is IntegerType\(?\)?, expected LongType\(?\)?'
):
schema_has(
T.MapType(T.StringType(), T.IntegerType()),
T.MapType(T.StringType(), T.LongType()),
Expand Down Expand Up @@ -286,7 +292,7 @@ def test_undefined_field(self):

with self.assertRaisesRegex(
TypeError,
r'element is IntegerType\(\), expected LongType\(\)',
r'element is IntegerType\(?\)?, expected LongType\(?\)?',
):
schema_has(
T.ArrayType(T.IntegerType()),
Expand Down
10 changes: 9 additions & 1 deletion tox.ini
Expand Up @@ -15,7 +15,15 @@
#

[tox]
envlist = spark33,no_extras,docs
envlist = spark32,spark33,no_extras,docs

[testenv:spark32]
commands = py.test --cov=sparkly --cov-report term-missing tests/integration tests/unit
deps =
-rrequirements.txt
-rrequirements_dev.txt
-rrequirements_extras.txt
pyspark==3.2.3

[testenv:spark33]
commands = py.test --cov=sparkly --cov-report term-missing tests/integration tests/unit
Expand Down

0 comments on commit 7267a91

Please sign in to comment.