我正在使用Spark Structured Streaming并尝试从实验室流式传输的字段中过滤掉负数。我的代码如下所示:
val records = labs.filter(
$" data.trays.tray1” <= 5 ||
$" data.trays.tray2" <= 10 ||
$" data.trays.tray3" <= 20)
.select("data.labs", "data.labs.tray1", “data.labs.tray2”, “data.labs.tray3”)
.writeStream.outputMode("append").format("console").start()
上面代码的输出是:
Lab | Tray 1 | Tray 2 | Tray 3
----------------------------------
FGF 0 -8 13
RFF -3 9 -14
WER 2 -8 -16
但是,我错过了滤除负数的逻辑。我以为我已经想通了,但我似乎无法过滤掉它们
答案 0 :(得分:0)
filter
将保留所有值,以便谓词返回true
。尝试
val records = labs.filter(
$"data.trays.tray1" > 5 &&
$"data.trays.tray2" > 10 &&
$"data.trays.tray3" > 20)
.select("data.labs", "data.labs.tray1", "data.labs.tray2", "data.labs.tray3")
.writeStream.outputMode("append").format("console").start()