如何使用结构化流媒体过滤掉数字?

时间:2018-03-14 21:43:03

标签: scala apache-spark spark-structured-streaming

我正在使用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   

但是,我错过了滤除负数的逻辑。我以为我已经想通了,但我似乎无法过滤掉它们

1 个答案:

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