表达式字符串到Scala中的字符串

时间:2018-02-22 19:14:17

标签: scala

我将整个表达式变为String (subCategory == "Serveware Sets") || (category == "Cookware & Bakeware") || (category == "Small Appliances") || (category == "Dinnerware & Serveware")

现在我想将此字符串转换为表达式,以便我可以直接比较subCategory和类别的值。 我怎么能这样做。

2 个答案:

答案 0 :(得分:1)

可以使用expr

来完成
val filterExpression = """(subCategory == "Serveware Sets") || (category == "Cookware & Bakeware") || (category == "Small Appliances") || (category == "Dinnerware & Serveware")"""

import org.apache.spark.sql.functions.expr

df
 .where(expr(filterExpression))

答案 1 :(得分:0)

您可以将||符号更改为or,以便表达式变为

(subCategory == "Serveware Sets") or (category == "Cookware & Bakeware") or (category == "Small Appliances") or (category == "Dinnerware & Serveware")

然后您应该能够在过滤中使用string表达式,或者数据帧中选择行。