星火Dataframes UPSERT给Postgres表 [英] Spark Dataframes UPSERT to Postgres Table

查看:278
本文介绍了星火Dataframes UPSERT给Postgres表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache星火DataFrames加入两个数据源,并得到的结果作为另一个数据框。我想写的结果到另一个Postgres的表。我看到这个选项:

I am using Apache Spark DataFrames to join two data sources and get the result as another DataFrame. I want to write the result to another Postgres table. I see this option :

myDataFrame.write.jdbc(url, table, connectionProperties)

但是,我想要做的就是UPSERT数据框到表基于表的主键。这是怎么做?我使用的Spark 1.6.0。

But, what I want to do is UPSERT the dataframe into table based on the Primary Key of the Table. How is this to be done? I am using Spark 1.6.0.

推荐答案

这是不支持的。 DataFrameWriter 可以追加到或覆盖现有的表。如果应用程序需要更复杂的逻辑,你必须手动处理这个。

It is not supported. DataFrameWriter can either append to or overwrite existing table. If your application requires more complex logic you'll have to deal with this manually.

一种选择是使用标准的JDBC连接的操作(的foreach foreachPartition )。另外一个是写一个临时的,直接在数据库中处理其余部分。

One option is to use an action (foreach, foreachPartition) with standard JDBC connection. Another one is to write to a temporary and handle the rest directly in the database.

这篇关于星火Dataframes UPSERT给Postgres表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆