Skip to content
Prev Previous commit
Next Next commit
Add UDFInitializationTests
  • Loading branch information
zero323 committed Jan 30, 2017
commit 489ef5437d89b795903565e9be56d73af49adcfa
27 changes: 27 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ def filename(path):
self.assertTrue(row2[0].find("people.json") != -1)

def test_udf_defers_judf_initalization(self):
# This is separate of UDFInitializationTests
# to avoid context initialization
# when udf is called

from pyspark.sql.functions import UserDefinedFunction

f = UserDefinedFunction(lambda x: x, StringType())
Expand Down Expand Up @@ -1964,6 +1968,29 @@ def test_sparksession_with_stopped_sparkcontext(self):
df.collect()


class UDFInitializationTests(unittest.TestCase):
Copy link
Member Author

@zero323 zero323 Jan 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And add a separate test case checking SparkContext and SparkSession state.

def tearDown(self):
if SparkSession._instantiatedSession is not None:
SparkSession._instantiatedSession.stop()

if SparkContext._active_spark_context is not None:
SparkContext._active_spark_contex.stop()

def test_udf_init_shouldnt_initalize_context(self):
from pyspark.sql.functions import UserDefinedFunction

UserDefinedFunction(lambda x: x, StringType())

self.assertIsNone(
SparkContext._active_spark_context,
"SparkContext shouldn't be initialized when UserDefinedFunction is created."
)
self.assertIsNone(
SparkSession._instantiatedSession,
"SparkSession shouldn't be initialized when UserDefinedFunction is created."
)


class HiveContextSQLTests(ReusedPySparkTestCase):

@classmethod
Expand Down