morningman commented on a change in pull request #2553: Add filter conditions 
for 'show partitions from table' syntax
URL: https://github.com/apache/incubator-doris/pull/2553#discussion_r361656033
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java
 ##########
 @@ -122,6 +146,94 @@ public void analyze(Analyzer analyzer) throws 
AnalysisException, UserException {
         }
     }
 
+    public void analyzeSynTax(Analyzer analyzer) throws UserException {
+        super.analyze(analyzer);
+        if (Strings.isNullOrEmpty(dbName)) {
+            dbName = analyzer.getDefaultDb();
+            if (Strings.isNullOrEmpty(dbName)) {
+                ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
+            }
+        } else {
+            dbName = ClusterNamespace.getFullName(getClusterName(), dbName);
+        }
+
+        // analyze where clause if not null
+        if (whereClause != null) {
+            analyzeSubPredicate(whereClause);
+        }
+
+        // order by
+        if (orderByElements != null && !orderByElements.isEmpty()) {
+            orderByPairs = new ArrayList<>();
+            for (OrderByElement orderByElement : orderByElements) {
+                if (!(orderByElement.getExpr() instanceof SlotRef)) {
+                    throw new AnalysisException("Should order by column");
+                }
+                SlotRef slotRef = (SlotRef) orderByElement.getExpr();
+                int index = 
PartitionsProcDir.analyzeColumn(slotRef.getColumnName());
+                OrderByPair orderByPair = new OrderByPair(index, 
!orderByElement.getIsAsc());
+                orderByPairs.add(orderByPair);
+            }
+        }
+
+        if (limitElement != null) {
+            limitElement.analyze(analyzer);
+        }
+    }
+
+    private void analyzeSubPredicate(Expr subExpr) throws AnalysisException {
+        if (subExpr == null) {
+            return;
+        }
+        if (subExpr instanceof CompoundPredicate) {
+            CompoundPredicate cp = (CompoundPredicate) subExpr;
+            if (cp.getOp() != CompoundPredicate.Operator.AND) {
+                throw new AnalysisException("Only allow compound predicate 
with operator AND");
+            }
+            analyzeSubPredicate(cp.getChild(0));
+            analyzeSubPredicate(cp.getChild(1));
+            return;
+        }
+
+        if (!(subExpr.getChild(0) instanceof SlotRef)) {
+            throw new AnalysisException("Show filter by column");
+        }
+
+        String leftKey = ((SlotRef) subExpr.getChild(0)).getColumnName();
+        if (subExpr instanceof BinaryPredicate) {
+            BinaryPredicate binaryPredicate = (BinaryPredicate) subExpr;
+            if (leftKey.equalsIgnoreCase("PartitionName") || 
leftKey.equalsIgnoreCase("State")) {
 
 Review comment:
   You can list the filter name at the beginning of the class like:
   
   `private static final String FILTER_PARTITION_NAME = "PartitionName";`
   
   So it would be more easy to maintain. And same as "State", 
"LastConsistencyCheckTime", ...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to