[英]Column is of type uuid but expression is of type character varying in Spark Scala
Good day.再会。 I am deploying a streaming job to insert data from Spark (Scala) to Postgres.我正在部署一个流式作业以将数据从 Spark (Scala) 插入到 Postgres。
df.select("col1","col2").write.mode(SaveMode.Append).jdbc(url, "tableName", connectionProperties)
Here col2 is having uuid values in the dataframe df, but it is a string datatype.这里 col2 在 dataframe df 中有 uuid 值,但它是字符串数据类型。 When it tries to insert in to the table that has col2 column defined as type uuid its failing with the Column is of type uuid but expression is of type character varying
.当它尝试插入将 col2 列定义为 uuid 类型的表中时,它的失败与Column is of type uuid but expression is of type character varying
。 Can someone help me with a workaround for this.有人可以帮我解决这个问题。 ? ?
Thank you.谢谢你。
When you have column column in dataframe that has string data type but had values of type UUID then you can set the specific property in your connection properties and that will allow you to save your dataframe.当 dataframe 中的列具有字符串数据类型但具有 UUID 类型的值时,您可以在连接属性中设置特定属性,这将允许您保存 dataframe。 If you don't set that property it will not allow you to save the data in the sql/postgres table, if the column has datatype of UUID.如果您不设置该属性,如果该列的数据类型为 UUID,它将不允许您将数据保存在 sql/postgres 表中。
You can set this property in the Connection Properties您可以在连接属性中设置此属性
connectionProps.setProperty("stringtype", "unspecified")
Setting the above property will allow you to save the string type column having UUID values in the dataframe to a column of type UUID in the postgres database.设置上述属性将允许您将 dataframe 中具有 UUID 值的字符串类型列保存到 postgres 数据库中 UUID 类型的列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.