File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -434,6 +434,16 @@ def test_udf_with_array_type(self):
434434 self .assertEqual (list (range (3 )), l1 )
435435 self .assertEqual (1 , l2 )
436436
437+ def test_nondeterministic_udf (self ):
438+ from pyspark .sql .functions import udf
439+ import random
440+ udf_random_col = udf (lambda : int (100 * random .random ()), IntegerType ()).asNondeterministic ()
441+ df = self .spark .createDataFrame ([Row (1 )]).select (udf_random_col ().alias ('RAND' ))
442+ random .seed (1234 )
443+ udf_add_ten = udf (lambda rand : rand + 10 , IntegerType ())
444+ [row ] = df .withColumn ('RAND_PLUS_TEN' , udf_add_ten ('RAND' )).collect ()
445+ self .assertEqual (row [0 ] + 10 , row [1 ])
446+
437447 def test_broadcast_in_udf (self ):
438448 bar = {"a" : "aa" , "b" : "bb" , "c" : "abc" }
439449 foo = self .sc .broadcast (bar )
You can’t perform that action at this time.
0 commit comments