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_r361656737
########## File path: fe/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java ########## @@ -65,8 +84,125 @@ public PartitionsProcDir(Database db, OlapTable olapTable) { this.olapTable = olapTable; } - @Override - public ProcResult fetchResult() throws AnalysisException { + public boolean filter(String columnName, Comparable element, Map<String, Expr> filterMap) throws AnalysisException { + if (filterMap == null) { + return true; + } + Expr subExpr = filterMap.get(columnName.toLowerCase()); + if (subExpr == null) { + return true; + } + if (subExpr instanceof BinaryPredicate) { + BinaryPredicate binaryPredicate = (BinaryPredicate) subExpr; + if (subExpr.getChild(1) instanceof StringLiteral && binaryPredicate.getOp() == BinaryPredicate.Operator.EQ) { + return ((StringLiteral) subExpr.getChild(1)).getValue().equals(element); + } + long leftVal; + long rightVal; + if (subExpr.getChild(1) instanceof DateLiteral) { + leftVal = (new DateLiteral((String) element, Type.DATETIME)).getLongValue(); + rightVal = ((DateLiteral) subExpr.getChild(1)).getLongValue(); + } else { + leftVal = Long.parseLong(element.toString()); + rightVal = ((IntLiteral)subExpr.getChild(1)).getLongValue(); + } + switch (binaryPredicate.getOp()) { + case EQ: + case EQ_FOR_NULL: + return leftVal == rightVal; + case GE: + return leftVal >= rightVal; + case GT: + return leftVal > rightVal; + case LE: + return leftVal <= rightVal; + case LT: + return leftVal < rightVal; + case NE: + return leftVal != rightVal; + default: + Preconditions.checkState(false, "No defined binary operator."); + } + } else { + return like((String)element, ((StringLiteral) subExpr.getChild(1)).getValue()); + } + return true; + } + + public boolean like(String str, String expr) { + expr = expr.toLowerCase(); + expr = expr.replace(".", "\\."); + expr = expr.replace("?", "."); + expr = expr.replace("%", ".*"); + str = str.toLowerCase(); + return str.matches(expr); + } + + public ProcResult fetchResultByFilter(Map<String, Expr> filterMap, List<OrderByPair> orderByPairs, LimitElement limitElement) throws AnalysisException { + List<List<Comparable>> partitionInfos = getPartitionInfos(); + List<List<Comparable>> filterPartitionInfos = null; + //where + if (filterMap == null || filterMap.isEmpty()) { + filterPartitionInfos = partitionInfos; + } else { + filterPartitionInfos = Lists.newArrayList(); + for (List<Comparable> partitionInfo : partitionInfos) { + if (partitionInfo.size() != TITLE_NAMES.size()) { + LOG.warn("ParttitionInfos.size() " + partitionInfos.size() Review comment: I think this is bug and should throw exception? ---------------------------------------------------------------- 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