Copilot commented on code in PR #9593:
URL: https://github.com/apache/seatunnel/pull/9593#discussion_r2218123371
##########
seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/sink/TDengineSinkWriter.java:
##########
@@ -103,11 +104,16 @@ public void write(SeaTunnelRow element) {
conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY)) {
String sql =
String.format(
- "INSERT INTO %s using %s tags ( %s ) VALUES ( %s
);",
+ "INSERT INTO %s using %s tags ( %s ) %s VALUES (
%s );",
element.getField(0),
config.getStable(),
tagValues,
+ config.getFieldNames().isEmpty()
+ ? ""
+ : "( " + config.getFieldNames() + " )",
StringUtils.join(convertDataType(metrics), ","));
+ statement.addBatch(sql);
+ statement.executeBatch();
final int rowCount = statement.executeUpdate(sql);
if (rowCount == 0) {
Review Comment:
The statement.addBatch(sql) is called but then immediately followed by
statement.executeUpdate(sql) on line 117. This creates inconsistent execution -
either use batch processing with executeBatch() or direct execution with
executeUpdate(), but not both for the same SQL statement.
```suggestion
// Error handling for batch execution
if (statement.getUpdateCount() == 0) {
```
##########
seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/sink/TDengineSinkWriter.java:
##########
@@ -103,11 +104,16 @@ public void write(SeaTunnelRow element) {
conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY)) {
String sql =
String.format(
- "INSERT INTO %s using %s tags ( %s ) VALUES ( %s
);",
+ "INSERT INTO %s using %s tags ( %s ) %s VALUES (
%s );",
element.getField(0),
config.getStable(),
tagValues,
+ config.getFieldNames().isEmpty()
+ ? ""
+ : "( " + config.getFieldNames() + " )",
StringUtils.join(convertDataType(metrics), ","));
+ statement.addBatch(sql);
+ statement.executeBatch();
final int rowCount = statement.executeUpdate(sql);
if (rowCount == 0) {
Review Comment:
The executeBatch() call is placed before executeUpdate() which will cause
the batch to execute prematurely. This line should be removed if using
executeUpdate(), or the executeUpdate() call should be removed if using batch
processing.
```suggestion
if (statement.getUpdateCount() == 0) {
```
--
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]