Apache spark structured streaming 2.3.0 如何让接收器知道新行是对现有行的更新?

How does Apache spark structured streaming 2.3.0 let the sink know that a new row is an update of an existing row?

更新模式 中 运行 时,spark 结构化流如何让接收器知道新行是对现有行的更新?它会查看新行和现有行的所有列的所有值以进行相等匹配还是计算某种哈希?

阅读 documentation,我们看到一些关于更新模式的有趣信息(我添加的粗体格式):

Update Mode - Only the rows that were updated in the Result Table since the last trigger will be written to the external storage (available since Spark 2.1.1). Note that this is different from the Complete Mode in that this mode only outputs the rows that have changed since the last trigger. If the query doesn’t contain aggregations, it will be equivalent to Append mode.

因此,要使用更新模式,需要进行某种聚合,否则所有数据都将简单地添加到结果的末尾 table。反过来,要使用聚合,数据需要使用一个或多个列作为键。由于需要一个键,因此很容易知道一行是否已更新 - 只需将值与 table 的前一次迭代进行比较(键会告诉您要与哪一行进行比较)。在包含 groupby 的聚合中,分组的列是键。

return 单个值的简单聚合不需要键。但是,由于只有一个值被 returned,如果该值被更改,它将更新。这里的一个例子可能是对一列求和(没有 groupby)。

文档包含一张图片,可以很好地理解这一点,请参阅上面 link 中的 "Model of the Quick Example"。