错误:列“ blob”的类型为jsonb,但表达式的类型为character

时间:2019-03-28 20:51:00

标签: apache-spark-sql spark-jdbc

val parquetDF = session.read.parquet("s3a://test/ovd").selectExpr("id", "topic", "update_id", "blob")

试图读取实木复合地板文件并转储到Postgres中。 postgres表中的一列是JSONB数据类型,而在镶木地板中则是String格式。

parquetDF.write.format("jdbc")
      .option("driver", "org.postgresql.Driver")
      .option("url", "jdbc:postgresql://localhost:5432/db_metamorphosis?binaryTransfer=true&stringtype=unspecified")
      .option("dbtable", "entitlements.general")
      .option("user", "mdev")
      .option("password", "")
      .option("stringtype", "unspecified")
      .mode(SaveMode.Append)
      .save()

通过erorr失败:

Caused by: org.postgresql.util.PSQLException: ERROR: column "blob" is of type jsonb but expression is of type character
  Hint: You will need to rewrite or cast the expression.
  Position: 85
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
    ... 16 more

SO上的某人建议放置stringtype=unspecified,因为Postgres将决定字符串的数据类型,但似乎不起作用。

<scala.major.version>2.12</scala.major.version>
<scala.version>${scala.major.version}.8</scala.version>
<spark.version>2.4.0</spark.version>
<postgres.version>9.4-1200-jdbc41</postgres.version>

0 个答案:

没有答案