|
24 | 24 | import org.apache.doris.analysis.AdminShowReplicaStatusStmt;
|
25 | 25 | import org.apache.doris.analysis.AdminShowTabletStorageFormatStmt;
|
26 | 26 | import org.apache.doris.analysis.DescribeStmt;
|
| 27 | +import org.apache.doris.analysis.Expr; |
27 | 28 | import org.apache.doris.analysis.HelpStmt;
|
28 | 29 | import org.apache.doris.analysis.LimitElement;
|
29 | 30 | import org.apache.doris.analysis.PartitionNames;
|
@@ -1691,28 +1692,54 @@ private void handleShowMaxComputeTablePartitions(ShowPartitionsStmt showStmt) {
|
1691 | 1692 | resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
|
1692 | 1693 | }
|
1693 | 1694 |
|
1694 |
| - private void handleShowHMSTablePartitions(ShowPartitionsStmt showStmt) { |
| 1695 | + private void handleShowHMSTablePartitions(ShowPartitionsStmt showStmt) throws AnalysisException { |
1695 | 1696 | HMSExternalCatalog catalog = (HMSExternalCatalog) (showStmt.getCatalog());
|
1696 | 1697 | List<List<String>> rows = new ArrayList<>();
|
1697 | 1698 | String dbName = ClusterNamespace.getNameFromFullName(showStmt.getTableName().getDb());
|
1698 | 1699 |
|
1699 | 1700 | List<String> partitionNames;
|
1700 | 1701 | LimitElement limit = showStmt.getLimitElement();
|
1701 |
| - if (limit != null && limit.hasLimit()) { |
1702 |
| - // only limit is valid on Hive |
| 1702 | + if (limit != null && limit.hasLimit() |
| 1703 | + && (!limit.hasOffset() || limit.getOffset() == 0)) { |
| 1704 | + // hmsClient returns unordered partition list, hence if offset > 0 cannot pass limit |
1703 | 1705 | partitionNames = catalog.getClient()
|
1704 |
| - .listPartitionNames(dbName, showStmt.getTableName().getTbl(), limit.getLimit()); |
| 1706 | + .listPartitionNames(dbName, showStmt.getTableName().getTbl(), limit.getLimit()); |
1705 | 1707 | } else {
|
1706 | 1708 | partitionNames = catalog.getClient().listPartitionNames(dbName, showStmt.getTableName().getTbl());
|
1707 | 1709 | }
|
| 1710 | + |
| 1711 | + Map<String, Expr> filterMap = showStmt.getFilterMap(); |
| 1712 | + List<OrderByPair> orderByPairs = showStmt.getOrderByPairs(); |
| 1713 | + LimitElement limitElement = showStmt.getLimitElement(); |
| 1714 | + |
| 1715 | + /* Filter add rows */ |
1708 | 1716 | for (String partition : partitionNames) {
|
1709 | 1717 | List<String> list = new ArrayList<>();
|
| 1718 | + |
| 1719 | + if (filterMap != null && !filterMap.isEmpty()) { |
| 1720 | + if (!PartitionsProcDir.filter(ShowPartitionsStmt.FILTER_PARTITION_NAME, partition, filterMap)) { |
| 1721 | + continue; |
| 1722 | + } |
| 1723 | + } |
1710 | 1724 | list.add(partition);
|
1711 | 1725 | rows.add(list);
|
1712 | 1726 | }
|
1713 | 1727 |
|
1714 | 1728 | // sort by partition name
|
1715 |
| - rows.sort(Comparator.comparing(x -> x.get(0))); |
| 1729 | + if (orderByPairs != null && orderByPairs.get(0).isDesc()) { |
| 1730 | + rows.sort(Comparator.comparing(x -> x.get(0), Comparator.reverseOrder())); |
| 1731 | + } else { |
| 1732 | + rows.sort(Comparator.comparing(x -> x.get(0))); |
| 1733 | + } |
| 1734 | + |
| 1735 | + if (limitElement != null && limitElement.hasLimit()) { |
| 1736 | + int beginIndex = (int) limitElement.getOffset(); |
| 1737 | + int endIndex = (int) (beginIndex + limitElement.getLimit()); |
| 1738 | + if (endIndex > rows.size()) { |
| 1739 | + endIndex = rows.size(); |
| 1740 | + } |
| 1741 | + rows = rows.subList(beginIndex, endIndex); |
| 1742 | + } |
1716 | 1743 |
|
1717 | 1744 | resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
|
1718 | 1745 | }
|
|
0 commit comments