【发布时间】:2022-06-14 06:18:32
【问题描述】:
我正在尝试使用 jdbc 驱动程序将数据集的数据写入 postgres db。
my_df.write().format('jdbc').mode('append')\
.option('driver', 'org.postgresql.Driver')\
.option('url', 'my_url')\
.option('dbtable', 'my_dbtable')\
.option('user', 'my_user').save()
显然 pyspark 默认尝试将所有文本类型(即 uuid)作为文本插入并抛出该错误:
Caused by: org.postgresql.util.PSQLException: ERROR: column "id" is of type uuid but expression is of type character varying
提示:您需要重写或转换表达式。
为了解决这个问题,我必须设置一个属性:
'stringtype':"unspecified"
但该解决方案不适用于 NULL 值并引发该错误
Caused by: org.postgresql.util.PSQLException: ERROR: column "id" is of type uuid but expression is of type character
这基本上意味着它尝试将 NULL 值作为字符插入。在我的情况下,将数据集分成 2 个数据集(如 @Karuhanga 建议的 Pyspark nullable uuid type uuid but expression is of type character varying )是不可能的。有没有人遇到过这个问题并找到了无法修复特定列的解决方案?
【问题讨论】:
标签: postgresql apache-spark pyspark apache-spark-sql uuid