我在Scala中有以下代码:
val FilteredPSPDF = PSPDF.select("accountname","amount", "currency", "datestamp","orderid","transactiontype")
但是,我在“金额”列中有一些值为负值,我需要将它们更改为正值。是否可以在Select语句中执行此算术功能?我该怎么做?
答案 0 :(得分:3)
Spark SQL中有abs
函数
您可以使用selectExpr
代替select
PSPDF.selectExpr("accountname","abs(amount) as amount", "currency", "datestamp","orderid","transactiontype")
或使用select
的重载版本来获取列类型:
PSPDF.select($"accountname", abs($"amount").as("amount"), $"currency", $"datestamp", $"orderid", $"transactiontype")
答案 1 :(得分:0)
您可以使用<shadow></shadow>
和when
内置功能作为
negate