星火Dataframes UPSERT给Postgres表

编程入门 行业动态 更新时间:2024-10-24 22:22:56
本文介绍了星火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表

本文发布于:2023-10-16 11:53:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497477.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:星火   Dataframes   Postgres   UPSERT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!