如何在db后端进行写入时不断更新spark数据帧?

时间:2015-06-14 15:46:21

标签: apache-spark apache-spark-sql

基本上我让Spark坐在数据库前面,我想知道如何使用后端的新数据不断更新数据框。

我能想到解决这个问题的简单方法是每隔几分钟就对数据库运行一次查询,但这显然效率低下,并且仍然会导致更新之间的时间过时。

我不是100%确定我使用的数据库是否有此限制,但我认为只添加了行,没有对现有行进行修改。

1 个答案:

答案 0 :(得分:1)

DF is RDD+Schema+Many other functionalities. From basic spark design, RDD is immutable. Hence, you can not update a DF after it is materialized. In your case, you can probably mix a streaming + SQL like below:

  1. In your DB, write data to a queue along with writes in tables
  2. Use spark queue stream to consume from the queue and create Dstreams (RDDs every x seconds)
  3. For each incoming RDD, join with existing DF and create a new DF