0
我在Spark中有一個數據框,並且我在這個數據框上應用了一些過濾器。根據通過這些過濾器的記錄,我在數據框中添加了一個新列。請參閱下面的代碼:在Spark中簡化列
val rule_name = when(col("product_name").isin("N") && col("territory").isin("Metro","GA"), "rule1").otherwise(when(col("product_name").isin("XGE") && col("territory").isin("14721"), "rule2").otherwise(""))
val df_final = df_join.withColumn("rule_name" , rule_name)
爲了更好的可見性的目的,我想打破下面的代碼在多行:
val rule_name = when(col("product_name").isin("N") && col("territory").isin("Metro","GA"), "rule1").otherwise(when(col("product_name").isin("XGE") && col("territory").isin("14721"), "rule2").otherwise(""))
有沒有辦法在Scala和pyspark實現這一目標的火花?