I have this udf which returns alert severity based on certain conditions.
def alert(name, X_Request, X_Actual):
if "Impact" in name:
return "Highest"
fs = ['FS_00','FS_01','FS_02','FS_03']
if name in fs:
if X_Actual < -3:
return "High"
elif X_Actual <= -2 and X_Actual >= -3 :
return "Medium"
elif X_Actual > -3 and X_Actual <= -0.5:
return "Low"
return None
alert_type = udf(alert, StringType())
df.withColumn("alert_level", alert_type(df["name"],df["x_request"],df["x_actual"]))
Can this be done without applying UDF, as UDF slows down the performance?