Skip to content

Commit

Permalink
[fix](planner)show tablet command return wrong result when having lim…
Browse files Browse the repository at this point in the history
…it and offset
  • Loading branch information
starocean999 committed Nov 13, 2024
1 parent 9c74a96 commit de8cb00
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
42 changes: 22 additions & 20 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1890,30 +1890,32 @@ private void handleShowTablet() throws AnalysisException {
}
}
}
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();
Expand Down
36 changes: 36 additions & 0 deletions regression-test/suites/show_p0/test_show_tablet.groovy
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit de8cb00

Please sign in to comment.