This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new b7b461aa334 [fix](show txn)Optimize the NPE error when using an
invalid label in the show txn command. (#55880)
b7b461aa334 is described below
commit b7b461aa33406826da7a8a004de3086b903eb6c7
Author: Refrain <[email protected]>
AuthorDate: Thu Sep 11 09:09:11 2025 +0800
[fix](show txn)Optimize the NPE error when using an invalid label in the
show txn command. (#55880)
### What problem does this PR solve?
Issue Number: https://github.com/apache/doris/issues/55729
Related PR: #xxx
Problem Summary:
When using an unrecorded label in the SHOW TRANSACTION command, a
NullPointerException is thrown.
Check the null pointers and optimize the error message to: "Transaction
with label 'xxx' does not exist."
---
.../plans/commands/ShowTransactionCommand.java | 5 +--
.../suites/show_p0/test_show_txn_error_msg.groovy | 38 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTransactionCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTransactionCommand.java
index 104644374d1..183796c7d64 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTransactionCommand.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTransactionCommand.java
@@ -92,10 +92,11 @@ public class ShowTransactionCommand extends ShowCommand {
resultSet = new ShowResultSet(getMetaData(),
transactionMgr.getDbTransInfoByLabelMatch(db.getId(), label));
} else {
if (!label.isEmpty()) {
- txnId = transactionMgr.getTransactionId(db.getId(), label);
- if (txnId == -1) {
+ Long txnIdObj = transactionMgr.getTransactionId(db.getId(),
label);
+ if (txnIdObj == null || txnIdObj == -1) {
throw new AnalysisException("transaction with label " +
label + " does not exist");
}
+ txnId = txnIdObj;
}
resultSet = new ShowResultSet(getMetaData(),
transactionMgr.getSingleTranInfo(db.getId(), txnId));
}
diff --git a/regression-test/suites/show_p0/test_show_txn_error_msg.groovy
b/regression-test/suites/show_p0/test_show_txn_error_msg.groovy
new file mode 100644
index 00000000000..13a1a817ed6
--- /dev/null
+++ b/regression-test/suites/show_p0/test_show_txn_error_msg.groovy
@@ -0,0 +1,38 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_show_txn_error_msg") {
+ def unique_label = "label_a_" +
UUID.randomUUID().toString().replaceAll("-", "")
+ sql """ DROP TABLE IF EXISTS test """
+ sql """ CREATE TABLE test (id INT, x INT) PROPERTIES("replication_num" =
"1") """
+ sql """ INSERT INTO test WITH LABEL ${unique_label} VALUES (1, 2) """
+
+ test {
+ sql """ SHOW TRANSACTION WHERE label = '${unique_label}' """
+ check { result, exception, startTime, endTime ->
+ assertTrue(result.size() > 0, "Expected to find transaction with
label ${unique_label}")
+ }
+ }
+
+ // transaction with label 'label_b' does not exist
+ test {
+ sql """ SHOW TRANSACTION WHERE label = 'label_b' """
+ exception("errCode = 2, detailMessage = transaction with label label_b
does not exist")
+ }
+
+ sql """ DROP TABLE IF EXISTS test """
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]