Math.abs函数在Scala中的Select语句中

时间:2018-06-07 17:14:52

标签: scala apache-spark dataframe bigdata

我在Scala中有以下代码:

val FilteredPSPDF = PSPDF.select("accountname","amount", "currency", "datestamp","orderid","transactiontype")

但是,我在“金额”列中有一些值为负值,我需要将它们更改为正值。是否可以在Select语句中执行此算术功能?我该怎么做?

2 个答案:

答案 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