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

试图读取镶木地板文件并转储到 Postgres。postgres 表中的一列是 JSONB 数据类型,在 parquet 中它是字符串格式。

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()

它失败了这个错误:

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=unspecifiedPostgres确定为字符串的数据类型,但它似乎不起作用。

<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>
4

0 回答 0