This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new b4f0f6d8256 branch-2.1: [fix](planner)show tablet command return wrong
result when having limit and offset (#43845)
b4f0f6d8256 is described below
commit b4f0f6d8256e0685ff3bd9aace03d9e2aad76889
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Nov 13 21:11:31 2024 +0800
branch-2.1: [fix](planner)show tablet command return wrong result when
having limit and offset (#43845)
Cherry-picked from #43768
Co-authored-by: starocean999 <[email protected]>
---
.../java/org/apache/doris/qe/ShowExecutor.java | 42 +++++++++++-----------
.../suites/show_p0/test_show_tablet.groovy | 36 +++++++++++++++++++
2 files changed, 58 insertions(+), 20 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
index 7eedb23ae61..e9835e4341e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
@@ -1988,30 +1988,32 @@ public class ShowExecutor {
}
}
}
- if (sizeLimit > -1 && tabletInfos.size() < sizeLimit) {
+ if (showStmt.hasOffset() && showStmt.getOffset() >=
tabletInfos.size()) {
tabletInfos.clear();
- } else if (sizeLimit > -1) {
- tabletInfos = tabletInfos.subList((int)
showStmt.getOffset(), (int) sizeLimit);
- }
-
- // order by
- List<OrderByPair> orderByPairs = showStmt.getOrderByPairs();
- ListComparator<List<Comparable>> comparator = null;
- if (orderByPairs != null) {
- OrderByPair[] orderByPairArr = new
OrderByPair[orderByPairs.size()];
- comparator = new
ListComparator<>(orderByPairs.toArray(orderByPairArr));
} else {
- // order by tabletId, replicaId
- comparator = new ListComparator<>(0, 1);
- }
- Collections.sort(tabletInfos, comparator);
+ // order by
+ List<OrderByPair> orderByPairs =
showStmt.getOrderByPairs();
+ ListComparator<List<Comparable>> comparator = null;
+ if (orderByPairs != null) {
+ OrderByPair[] orderByPairArr = new
OrderByPair[orderByPairs.size()];
+ comparator = new
ListComparator<>(orderByPairs.toArray(orderByPairArr));
+ } else {
+ // order by tabletId, replicaId
+ comparator = new ListComparator<>(0, 1);
+ }
+ Collections.sort(tabletInfos, comparator);
+ if (sizeLimit > -1) {
+ tabletInfos = tabletInfos.subList((int)
showStmt.getOffset(),
+ Math.min((int) sizeLimit, tabletInfos.size()));
+ }
- for (List<Comparable> tabletInfo : tabletInfos) {
- List<String> oneTablet = new
ArrayList<String>(tabletInfo.size());
- for (Comparable column : tabletInfo) {
- oneTablet.add(column.toString());
+ for (List<Comparable> tabletInfo : tabletInfos) {
+ List<String> oneTablet = new
ArrayList<String>(tabletInfo.size());
+ for (Comparable column : tabletInfo) {
+ oneTablet.add(column.toString());
+ }
+ rows.add(oneTablet);
}
- rows.add(oneTablet);
}
} finally {
olapTable.readUnlock();
diff --git a/regression-test/suites/show_p0/test_show_tablet.groovy
b/regression-test/suites/show_p0/test_show_tablet.groovy
new file mode 100644
index 00000000000..99a1e191369
--- /dev/null
+++ b/regression-test/suites/show_p0/test_show_tablet.groovy
@@ -0,0 +1,36 @@
+// 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_tablet") {
+ sql """drop table if exists show_tablets_test_t;"""
+ sql """create table show_tablets_test_t (
+ id BIGINT,
+ username VARCHAR(20)
+ )
+ DISTRIBUTED BY HASH(id) BUCKETS 5
+ PROPERTIES (
+ "replication_num" = "1"
+ );"""
+ def res = sql """SHOW TABLETS FROM show_tablets_test_t limit 5, 1;"""
+ assertTrue(res.size() == 0)
+
+ res = sql """SHOW TABLETS FROM show_tablets_test_t limit 3, 5;"""
+ assertTrue(res.size() == 2)
+
+ res = sql """SHOW TABLETS FROM show_tablets_test_t limit 10;"""
+ assertTrue(res.size() == 5)
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]