我将整个表达式变为String (subCategory == "Serveware Sets") || (category == "Cookware & Bakeware") || (category == "Small Appliances") || (category == "Dinnerware & Serveware")
现在我想将此字符串转换为表达式,以便我可以直接比较subCategory和类别的值。 我怎么能这样做。
答案 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
表达式,或者从数据帧中选择行。