siwen-yu opened a new issue, #10933:
URL: https://github.com/apache/seatunnel/issues/10933

   
   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### What happened
   
   When using Dameng (达梦) as the sink database with `auto_create_table = true`, 
if the source table has column comments, the table creation fails because the 
generated SQL contains multiple statements (CREATE TABLE + COMMENT ON COLUMN) 
that are executed in a single `execute()` call, which is not supported by the 
Dameng JDBC driver.
   
   ### SeaTunnel Version
   
   2.3.13 (2.3.13-release branch) and dev branch (confirmed, latest commit: 
`0f8e9855b`)
   
   ### SeaTunnel Config
   
   ```hocon
   env {
     parallelism = 1
     job.mode = "BATCH"
   }
   
   source {
     Jdbc {
       url = "..."
       driver = "..."
       user = "..."
       password = "..."
       query = "select * from source_table"
       result_table_name = "test_data"
     }
   }
   
   transform {
   }
   
   sink {
     Jdbc {
       url = "jdbc:dm://localhost:5236/SCHEMA"
       driver = "dm.jdbc.driver.DmDriver"
       user = "..."
       password = "..."
       table = "sink_table"
       schema_save_mode = "CREATE_SCHEMA_WHEN_NOT_EXIST"
       data_save_mode = "APPEND_DATA"
       auto_create_table = true
     }
   }
   ```
   
   ### Running Command
   
   ```shell
   ./bin/seatunnel.sh --config config/test.conf
   ```
   
   ### Error Exception
   
   ```
   Caused by: java.sql.SQLException: Cannot execute multiple SQL statements in 
a single execute() call
        at 
dm.jdbc.driver.DmdbPreparedStatement.execute(DmdbPreparedStatement.java:xxx)
        at 
org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.dm.DamengCatalog.createTableInternal(DamengCatalog.java:xxx)
        ...
   ```
   
   ### Zeta or Flink or Spark Version
   
   Zeta (SeaTunnel Engine)
   
   ### Java or Scala Version
   
   Java 8 (Dameng JDBC driver requirement)
   
   ### 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)
   
   ### Additional Context
   
   **Root Cause:**
   
   In `DamengCreateTableSqlBuilder.build()`, when the table has column 
comments, the generated SQL looks like:
   
   ```sql
   CREATE TABLE "SCHEMA"."TABLE" ( "col1" VARCHAR(100) NOT NULL ) ;
   COMMENT ON COLUMN "SCHEMA"."TABLE"."col1" IS 'column comment' ;
   ```
   
   This entire string is returned as a single SQL by 
`DamengCatalog.getCreateTableSql()`. Although 
`AbstractJdbcCatalog.createTableInternal()` iterates over 
`getCreateTableSqls()` list, the default implementation wraps the single 
combined SQL string in a singleton list, so `executeInternal()` still passes 
the entire multi-statement string to a single `PreparedStatement.execute()` 
call.
   
   The Dameng JDBC driver (`dm.jdbc.driver.DmDriver`) does **not** support 
executing multiple SQL statements in a single `execute()` call, unlike MySQL or 
PostgreSQL drivers.
   
   **Proposed Fix:**
   
   Override `getCreateTableSqls()` in `DamengCatalog` to split the combined SQL 
string by `;` into separate statements, so each `executeInternal()` call only 
executes one SQL statement:
   
   ```java
   @Override
   protected List<String> getCreateTableSqls(
           TablePath tablePath, CatalogTable table, boolean createIndex) {
       String sql = getCreateTableSql(tablePath, table, createIndex);
       return Arrays.stream(sql.split(";"))
               .map(String::trim)
               .filter(s -> !s.isEmpty())
               .map(s -> s + ";")
               .collect(Collectors.toList());
   }
   ```
   
   **Affected Modules:**
   
   - `seatunnel-connectors-v2/connector-jdbc`
   - `DamengCreateTableSqlBuilder.java`
   - `DamengCatalog.java`
   
   **Branch Verification (2025-05-23):**
   
   | Branch | Bug Present | Notes |
   |--------|-------------|-------|
   | `2.3.13-release` | ✅ Fixed (local commit `18ebc79bc`) | 
`getCreateTableSqls()` override added |
   | `dev` (latest: `0f8e9855b`) | ❌ **Bug still exists** | `DamengCatalog` 
does NOT override `getCreateTableSqls()`; 
`AbstractJdbcCatalog.getCreateTableSqls()` returns 
`Collections.singletonList(...)` which wraps the full multi-statement SQL into 
a single `execute()` call |
   
   The fix needs to be applied to both `2.3.13-release` and `dev` branches. A 
PR targeting `dev` is needed.
   


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