spark-sql 在 REPL 中工作但代码无法编译的情况

spark-sql case when works in REPL but code doesnt compile

此代码在 REPL 中有效,但无法编译。我想我错过了一个隐含的。但是

people.select(when(people("gender") === "male", 0)
    .when(people("gender") === "female", 1)
    .otherwise(2))

在非 REPL 代码中,您应该使用以下导入:

import org.apache.spark.sql.functions._