Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9RXr-0006TV-3O for pgsql-jdbc@arkaria.postgresql.org; Tue, 09 Feb 2021 11:51:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l9RXp-00074Z-HE for pgsql-jdbc@arkaria.postgresql.org; Tue, 09 Feb 2021 11:51:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9QUV-0000Fi-DF for pgsql-jdbc@lists.postgresql.org; Tue, 09 Feb 2021 10:43:31 +0000 Received: from cczrelay01.in2p3.fr ([134.158.66.141]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l9QU9-0005yl-FL for pgsql-jdbc@postgresql.org; Tue, 09 Feb 2021 10:43:30 +0000 Received: from cczmbox05.in2p3.fr (cczmbox05.in2p3.fr [134.158.66.135]) by cczrelay01.in2p3.fr (8.14.4/8.14.4) with ESMTP id 119AgXSQ005904 for ; Tue, 9 Feb 2021 11:42:33 +0100 X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.100.3 at cczrelay01 Date: Tue, 9 Feb 2021 11:42:33 +0100 (CET) From: Antoine DUBOIS To: pgsql-jdbc@postgresql.org Message-ID: <1094480618.3358882.1612867353140.JavaMail.zimbra@cc.in2p3.fr> Subject: Double insertion from scala spark job MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="----=_Part_3358884_1201366099.1612867353161" X-Originating-IP: [134.158.231.80] X-Mailer: Zimbra 8.7.11_GA_3865 (ZimbraWebClient - FF83 (Linux)/8.7.11_GA_3865) Thread-Index: C7kKTKmnbx6UyQhS6qREhAVVdrMeew== Thread-Topic: Double insertion from scala spark job List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_3358884_1201366099.1612867353161 Date: Tue, 9 Feb 2021 11:42:33 +0100 (CET) From: Antoine DUBOIS To: pgsql-jdbc@postgresql.org Message-ID: <1094480618.3358882.1612867353140.JavaMail.zimbra@cc.in2p3.fr> Subject: Double insertion from scala spark job MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_add3ba3a-b588-43db-bbc0-a3b19de3bd16" X-Originating-IP: [134.158.231.80] X-Mailer: Zimbra 8.7.11_GA_3865 (ZimbraWebClient - FF83 (Linux)/8.7.11_GA_3865) Thread-Index: C7kKTKmnbx6UyQhS6qREhAVVdrMeew== Thread-Topic: Double insertion from scala spark job --=_add3ba3a-b588-43db-bbc0-a3b19de3bd16 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello I'm working with spark and postgresql to compute stat. I came to encounter a strange behaviour in my job, when working with postgresql output I sometime have a double insertion happenning into my table (and violating constraint). Detail: Key (xxx, xxx, xxx, xxx, xxx, xxxx, xxxx)=(2021-02-05 00:00:00, data, moredate, evenmoredata, somuchmoredata, dataagain, somuchofit) already exists. Call getNextException to see other errors in the batch. My data are generated as duplicate if I write the same data into mysql or into a parquet file with the same input and treatment I don't observe this behaviour. Dev spec: Scala 2.12 Spark Version 3.0.1 JDK 8 jdbc "org.postgresql" % "postgresql" % "42.2.18" PostgreSQL 12.5 My code is pretty simple and apply a SQL request to a parquet file and write the result like this : outputDF.write.format("jdbc").option("driver", " org.postgresql.Driver ").option("url", " jdbc:postgresql://:/?user=&password= ").option("dbtable", "mytable").mode(append).save() What lead me to think it's a postgres jdbc bug more than anything else is the fact that this same command to output in mysql or in a parquet file produce no duplicate in this particular edge case i have with only some of my input files. If any of you had any idea what could cause such a behavior (special char in the input, misconfigured something, maybe an option I don't know could help solving this issue ) I came to a point where I'm not sure of anything any longer. Hope anyone will have some though about it. Hope your doing fine Antoine --=_add3ba3a-b588-43db-bbc0-a3b19de3bd16 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hello
<= br data-mce-bogus=3D"1">
I'm working with spark and postgresql to= compute stat.
I came to encounter a strange behaviour in my = job, when working with postgresql output I sometime have a double insertion= happenning into my table (and violating constraint).
Detail: Key (xxx, xxx, xxx=
, xxx, xxx, xxxx, xxxx)=3D(2021-02-05 00:00:00, data, moredate, evenmoredat=
a, somuchmoredata, dataagain, somuchofit) already exists.  Call getNextExce=
ption to see other errors in the batch.
My data are = generated as duplicate if I write the same data into mysql or into a parque= t file with the same input and treatment I don't observe this behaviour.
Dev spec:
<= div>Scala 2.12
Spark Version 3.0.1
JDK 8
jdbc=   "org.postgresql" % "postgresql" % "42.2.18"
=

PostgreSQL 12.5

My code is pret= ty simple and apply a SQL request to a parquet file and write the result li= ke this :

outputDF.write.format("jdbc").option("driver", "org.postgresql= .Driver").option("url", "jdbc:postgresql://<HOST>:<PO= RT>/<SCHEMA>?user=3D<USERNAME>&password=3D<PASSWORD&g= t;").option("dbtable", "mytable").mode(append).save()

What lead me to th= ink it's a postgres jdbc bug more than anything else is the fact that this = same command to output in mysql or in a parquet file produce no duplicate i= n this particular edge case i have with only some of my input files.
<= div>If any of you had any idea what could cause such a behavior (special ch= ar in the input, misconfigured something, maybe an option I don't know coul= d help solving this issue )

I came to a point where I'm not sure of= anything any longer.
Hope anyone will h= ave some though about it.

Hope your doing fine

Antoine
--=_add3ba3a-b588-43db-bbc0-a3b19de3bd16-- ------=_Part_3358884_1201366099.1612867353161 Content-Type: application/pkcs7-signature; name=smime.p7s; smime-type=signed-data Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCAMIIE vDCCA6SgAwIBAgIDAPs4MA0G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