kangpinghuang commented on a change in pull request #1687: add limit to show
tablet(#1547)
URL: https://github.com/apache/incubator-doris/pull/1687#discussion_r318354377
##########
File path: fe/src/main/java/org/apache/doris/analysis/ShowTabletStmt.java
##########
@@ -79,10 +135,112 @@ public void analyze(Analyzer analyzer) throws
UserException {
} else {
dbName = ClusterNamespace.getFullName(getClusterName(), dbName);
}
+ if (limitElement != null) {
+ limitElement.analyze(analyzer);
+ }
- // check access
- if
(!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(),
PrivPredicate.ADMIN)) {
-
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
"SHOW TABLET");
+ // analyze where clause if not null
+ if (whereClause != null) {
+ if (whereClause instanceof CompoundPredicate) {
+ CompoundPredicate cp = (CompoundPredicate) whereClause;
+ if (cp.getOp() !=
org.apache.doris.analysis.CompoundPredicate.Operator.AND) {
+ throw new AnalysisException("Only allow compound predicate
with operator AND");
+ }
+
+ analyzeSubPredicate(cp.getChild(0));
+ analyzeSubPredicate(cp.getChild(1));
+ } else {
+ analyzeSubPredicate(whereClause);
+ }
+ }
+
+ // order by
+ if (orderByElements != null && !orderByElements.isEmpty()) {
+ orderByPairs = new ArrayList<OrderByPair>();
+ for (OrderByElement orderByElement : orderByElements) {
+ if (!(orderByElement.getExpr() instanceof SlotRef)) {
+ throw new AnalysisException("Should order by column");
+ }
+ SlotRef slotRef = (SlotRef) orderByElement.getExpr();
+ int index =
TabletsProcDir.analyzeColumn(slotRef.getColumnName());
+ OrderByPair orderByPair = new OrderByPair(index,
!orderByElement.getIsAsc());
+ orderByPairs.add(orderByPair);
+ }
+ }
+ }
+
+ private void analyzeSubPredicate(Expr subExpr) throws AnalysisException {
+ if (subExpr == null) {
+ return;
+ }
+ if (subExpr instanceof CompoundPredicate) {
+ CompoundPredicate cp = (CompoundPredicate) subExpr;
+ if (cp.getOp() !=
org.apache.doris.analysis.CompoundPredicate.Operator.AND) {
+ throw new AnalysisException("Only allow compound predicate
with operator AND");
+ }
+
+ analyzeSubPredicate(cp.getChild(0));
+ analyzeSubPredicate(cp.getChild(1));
+ return;
+ }
+ boolean valid = true;
+ do {
+ if (!(subExpr instanceof BinaryPredicate)) {
+ valid = false;
+ break;
+ }
+ BinaryPredicate binaryPredicate = (BinaryPredicate) subExpr;
+ if (binaryPredicate.getOp() != BinaryPredicate.Operator.EQ) {
+ valid = false;
+ break;
+ }
+
+ if (!(subExpr.getChild(0) instanceof SlotRef)) {
+ valid = false;
+ break;
+ }
+ String leftKey = ((SlotRef) subExpr.getChild(0)).getColumnName();
+ if (leftKey.equalsIgnoreCase("version")) {
+ if (!(subExpr.getChild(1) instanceof IntLiteral) || version >
-1) {
+ valid = false;
+ break;
+ }
+ version = ((IntLiteral) subExpr.getChild(1)).getValue();
+ } else if (leftKey.equalsIgnoreCase("backendid")) {
+ if (!(subExpr.getChild(1) instanceof IntLiteral) || backendId
> -1) {
+ valid = false;
+ break;
+ }
+ backendId = ((IntLiteral) subExpr.getChild(1)).getValue();
+ } else if (leftKey.equalsIgnoreCase("indexname")) {
+ if (!(subExpr.getChild(1) instanceof StringLiteral) ||
indexName != null) {
+ valid = false;
+ break;
+ }
+ indexName = ((StringLiteral) subExpr.getChild(1)).getValue();
+ } else if (leftKey.equalsIgnoreCase("state")) {
+ if (!(subExpr.getChild(1) instanceof StringLiteral) ||
replicaState != null) {
+ valid = false;
+ break;
+ }
+ String state = ((StringLiteral)
subExpr.getChild(1)).getValue().toUpperCase();
+ try {
+ replicaState = Replica.ReplicaState.valueOf(state);
+ } catch (Exception e) {
+ replicaState = null;
+ valid = false;
+ break;
+ }
+ } else {
+ valid = false;
+ break;
+ }
+ } while(false);
+
+ if (!valid) {
+ throw new AnalysisException("Where clause should looks like:
Version = \"version\","
+ + " State = \"NORMAL|ROLLUP|CLONE|DECOMMISSION\", or
BackendId = 10000"
+ + " or compound predicate with operator AND");
Review comment:
ok
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]