Ivan-gfan opened a new issue, #13427:
URL: https://github.com/apache/seatunnel/issues/13427

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22bug%22)
 and found no similar issues.
   
   
   ### What happened
   
   A JDBC sink writing to openGauss with `primary_keys` (generated upsert) 
fails on its first batch:
   
   ```
   ERROR: syntax error at or near "CONFLICT ("
   ```
   
   openGauss does not support PostgreSQL's `INSERT ... ON CONFLICT ... DO 
UPDATE`. `OpenGaussDialect` exists to generate `INSERT ... ON DUPLICATE KEY 
UPDATE` instead, but since 3.1.0 the sink no longer gets that dialect.
   
   Cause:
   
   - `JdbcDialectLoader#load` creates the dialect through 
`JdbcDialectFactory#create(compatibleMode, fieldIde, jdbcConnectionConfig)`.
   - Up to 2.3.13, `PostgresDialectFactory` did not override this method, so 
the interface default delegated to `create(compatibleMode, fieldIde)`, which 
`OpenGaussDialectFactory` overrides to return `OpenGaussDialect`.
   - #12792 (3.1.0) overrode the three-argument `create` in 
`PostgresDialectFactory` to pass `numeric_special_value_as_null`. 
`OpenGaussDialectFactory` extends `PostgresDialectFactory` and inherits that 
override, so the loader now returns a plain `PostgresDialect` for 
`jdbc:opengauss:` URLs (`PostgresLowDialect` with `compatible_mode = 
"postgresLow"`).
   
   The existing `JdbcOpenGaussIT` sink does not set `primary_keys`, so it only 
runs plain inserts and does not catch this.
   
   The two statements against `opengauss/opengauss:5.0.0` (the image 
`JdbcOpenGaussIT` uses):
   
   ```
   INSERT INTO "upsert_probe" ("id", "name") VALUES (1, 'new') ON CONFLICT 
("id") DO UPDATE SET "name"=EXCLUDED."name";
   ERROR:  syntax error at or near "CONFLICT ("
   
   INSERT INTO "upsert_probe" ("id", "name") VALUES (1, 'new') ON DUPLICATE KEY 
UPDATE "name"=EXCLUDED."name";
   INSERT 0 1
   ```
   
   ### SeaTunnel Version
   
   3.1.0 and current `dev` (3.1.1-SNAPSHOT). 2.3.13 is not affected.
   
   ### SeaTunnel Config
   
   ```conf
   env {
     parallelism = 1
     job.mode = "BATCH"
   }
   
   source {
     jdbc {
       url = "jdbc:opengauss://localhost:5432/postgres"
       driver = "org.opengauss.Driver"
       user = "gaussdb"
       password = "******"
       query = "select * from public.source_table"
     }
   }
   
   sink {
     jdbc {
       url = "jdbc:opengauss://localhost:5432/postgres?stringtype=unspecified"
       driver = "org.opengauss.Driver"
       user = "gaussdb"
       password = "******"
       database = "postgres"
       table = "public.sink_table"
       generate_sink_sql = true
       primary_keys = ["id"]
     }
   }
   ```
   
   ### Running Command
   
   ```shell
   ./bin/seatunnel.sh --config opengauss_upsert.conf -m local
   ```
   
   ### Error Exception
   
   ```log
   java.sql.BatchUpdateException: Batch entry 0 INSERT INTO 
"postgres"."public"."sink_table" ("id", ...) VALUES (...) ON CONFLICT ("id") DO 
UPDATE SET ... was aborted
   Caused by: org.opengauss.util.PSQLException: ERROR: syntax error at or near 
"CONFLICT ("
   ```
   
   ### Zeta or Flink or Spark Version
   
   Zeta
   
   ### Java or Scala Version
   
   Java 11
   
   ### Screenshots
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to