Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/td 27733 #132

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQ
public void setObject(int parameterIndex, Object x) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (parameterIndex < 1 && parameterIndex >= parameters.length)
if (parameterIndex < 1 || parameterIndex > parameters.length)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
parameters[parameterIndex - 1] = x;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/taosdata/jdbc/ws/tmq/WSConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ public Map<TopicPartition, OffsetAndMetadata> committed(Set<TopicPartition> part
@Override
public void commitSync(Map<TopicPartition, OffsetAndMetadata> offsets) throws SQLException {
for (Map.Entry<TopicPartition, OffsetAndMetadata> entry : offsets.entrySet()) {
if (entry.getValue().offset() < 0) {
continue;
}
Request request = factory.generateCommitOffset(entry.getKey(), entry.getValue().offset());
CommitOffsetResp resp = (CommitOffsetResp) transport.send(request);
if (Code.SUCCESS.getCode() != resp.getCode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public class CommitOffsetReq extends Payload {
private String topic;

@JSONField(name = "vg_id")
private int vgId;
@JSONField(name = "vgroup_id")
private int vgroupId;

private long offset;

Expand All @@ -19,12 +19,12 @@ public void setTopic(String topic) {
this.topic = topic;
}

public int getVgId() {
return vgId;
public int getVgroupId() {
return vgroupId;
}

public void setVgId(int vgId) {
this.vgId = vgId;
public void setVgroupId(int vgroupId) {
this.vgroupId = vgroupId;
}

public long getOffset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public Request generateCommitOffset(TopicPartition topicPartition, long offset){
CommitOffsetReq commitOffsetReq = new CommitOffsetReq();
commitOffsetReq.setReqId(reqId);
commitOffsetReq.setTopic(topicPartition.getTopic());
commitOffsetReq.setVgId(topicPartition.getVGroupId());
commitOffsetReq.setVgroupId(topicPartition.getVGroupId());
commitOffsetReq.setOffset(offset);
return new Request(ConsumerAction.COMMIT_OFFSET.getAction(), commitOffsetReq);
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/taosdata/jdbc/ws/ConsumerCommittedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testJNI() throws Exception {
properties.setProperty(TMQConstants.CONNECT_PASS, "taosdata");
properties.setProperty(TMQConstants.MSG_WITH_TABLE_NAME, "true");
properties.setProperty(TMQConstants.ENABLE_AUTO_COMMIT, "false");
properties.setProperty(TMQConstants.GROUP_ID, "g_ws");
properties.setProperty(TMQConstants.GROUP_ID, "g_jni");
properties.setProperty(TMQConstants.AUTO_OFFSET_RESET, "earliest");
properties.setProperty(TMQConstants.VALUE_DESERIALIZER, "com.taosdata.jdbc.tmq.ResultDeserializer");

Expand Down Expand Up @@ -91,7 +91,7 @@ public void testWS() throws Exception {
properties.setProperty(TMQConstants.CONNECT_PASS, "taosdata");
properties.setProperty(TMQConstants.MSG_WITH_TABLE_NAME, "true");
properties.setProperty(TMQConstants.ENABLE_AUTO_COMMIT, "false");
properties.setProperty(TMQConstants.GROUP_ID, "g_jni");
properties.setProperty(TMQConstants.GROUP_ID, "g_ws");
properties.setProperty(TMQConstants.AUTO_OFFSET_RESET, "earliest");
properties.setProperty(TMQConstants.VALUE_DESERIALIZER, "com.taosdata.jdbc.tmq.ResultDeserializer");

Expand Down Expand Up @@ -124,8 +124,8 @@ public void testWS() throws Exception {
System.out.println(topicPartition + " : " + committed.get(topicPartition));
});
Assert.assertFalse(committed.isEmpty());
// TODO sync commit with offset
// consumer.commitSync(committed);
// sync commit with offset
consumer.commitSync(committed);
// unsubscribe
consumer.unsubscribe();
}
Expand Down
Loading