Last active
January 31, 2019 14:47
-
-
Save afranzi/040e0a6f0e7a7268cf089e38f55ca787 to your computer and use it in GitHub Desktop.
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
from pyspark.sql.types import StringType | |
from pyspark.sql.functions import udf | |
# 1.- UDF with f as a lambda | |
to_upper = udf(lambda s: s.upper() if s else None, StringType()) | |
# 2.- UDF with f as a method | |
def to_upper(s): | |
if s is not None: | |
return s.upper() | |
to_upper = udf(to_upper) | |
# 3.- function using the @udf annotation | |
@udf(returnType=StringType()) | |
def to_upper(s): | |
if s is not None: | |
return s.upper() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment