|
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,53 @@ 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 | + Map<String, Expr> filterMap = showStmt.getFilterMap(); |
| 1703 | + List<OrderByPair> orderByPairs = showStmt.getOrderByPairs(); |
| 1704 | + |
| 1705 | + if (limit != null && limit.hasLimit() && limit.getOffset() == 0 |
| 1706 | + && (orderByPairs == null || !orderByPairs.get(0).isDesc())) { |
| 1707 | + // hmsClient returns unordered partition list, hence if offset > 0 cannot pass limit |
1703 | 1708 | partitionNames = catalog.getClient()
|
1704 |
| - .listPartitionNames(dbName, showStmt.getTableName().getTbl(), limit.getLimit()); |
| 1709 | + .listPartitionNames(dbName, showStmt.getTableName().getTbl(), limit.getLimit()); |
1705 | 1710 | } else {
|
1706 | 1711 | partitionNames = catalog.getClient().listPartitionNames(dbName, showStmt.getTableName().getTbl());
|
1707 | 1712 | }
|
| 1713 | + |
| 1714 | + /* Filter add rows */ |
1708 | 1715 | for (String partition : partitionNames) {
|
1709 | 1716 | List<String> list = new ArrayList<>();
|
| 1717 | + |
| 1718 | + if (filterMap != null && !filterMap.isEmpty()) { |
| 1719 | + if (!PartitionsProcDir.filter(ShowPartitionsStmt.FILTER_PARTITION_NAME, partition, filterMap)) { |
| 1720 | + continue; |
| 1721 | + } |
| 1722 | + } |
1710 | 1723 | list.add(partition);
|
1711 | 1724 | rows.add(list);
|
1712 | 1725 | }
|
1713 | 1726 |
|
1714 | 1727 | // sort by partition name
|
1715 |
| - rows.sort(Comparator.comparing(x -> x.get(0))); |
| 1728 | + if (orderByPairs != null && orderByPairs.get(0).isDesc()) { |
| 1729 | + rows.sort(Comparator.comparing(x -> x.get(0), Comparator.reverseOrder())); |
| 1730 | + } else { |
| 1731 | + rows.sort(Comparator.comparing(x -> x.get(0))); |
| 1732 | + } |
| 1733 | + |
| 1734 | + if (limit != null && limit.hasLimit()) { |
| 1735 | + int beginIndex = (int) limit.getOffset(); |
| 1736 | + int endIndex = (int) (beginIndex + limit.getLimit()); |
| 1737 | + if (endIndex > rows.size()) { |
| 1738 | + endIndex = rows.size(); |
| 1739 | + } |
| 1740 | + rows = rows.subList(beginIndex, endIndex); |
| 1741 | + } |
1716 | 1742 |
|
1717 | 1743 | resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
|
1718 | 1744 | }
|
|
0 commit comments