chenhao7253886 commented on a change in pull request #1527: Expose data 
pruned-filter-scan ability
URL: https://github.com/apache/incubator-doris/pull/1527#discussion_r306280568
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/http/rest/RestQueryPlanAction.java
 ##########
 @@ -0,0 +1,310 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.http.rest;
+
+import com.google.common.base.Strings;
+import io.netty.handler.codec.http.HttpMethod;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import org.apache.doris.analysis.SelectStmt;
+import org.apache.doris.analysis.StatementBase;
+import org.apache.doris.analysis.TableName;
+import org.apache.doris.analysis.TableRef;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.cluster.ClusterNamespace;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.DorisHttpException;
+import org.apache.doris.http.ActionController;
+import org.apache.doris.http.BaseRequest;
+import org.apache.doris.http.BaseResponse;
+import org.apache.doris.http.IllegalArgException;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.planner.PlanFragment;
+import org.apache.doris.planner.Planner;
+import org.apache.doris.planner.ScanNode;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.thrift.TDataSink;
+import org.apache.doris.thrift.TDataSinkType;
+import org.apache.doris.thrift.TMemoryScratchSink;
+import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.thrift.TPaloScanRange;
+import org.apache.doris.thrift.TPlanFragment;
+import org.apache.doris.thrift.TQueryOptions;
+import org.apache.doris.thrift.TQueryPlanInfo;
+import org.apache.doris.thrift.TScanRangeLocations;
+import org.apache.doris.thrift.TTabletVersionInfo;
+import org.apache.doris.thrift.TUniqueId;
+import org.apache.thrift.TException;
+import org.apache.thrift.TSerializer;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * This class responsible for parse the sql and generate the query plan 
fragment for a (only one) table{@see OlapTable}
+ * the related tablet maybe pruned by query planer according the `where` 
predicate.
+ */
+public class RestQueryPlanAction extends RestBaseAction {
+
+    public RestQueryPlanAction(ActionController controller) {
+        super(controller);
+    }
+
+    public static void registerAction(ActionController controller) throws 
IllegalArgException {
+        controller.registerHandler(HttpMethod.POST,
+                "/api/{cluster}/{database}/{table}/_query_plan", new 
RestQueryPlanAction(controller));
+        controller.registerHandler(HttpMethod.GET,
+                "/api/{cluster}/{database}/{table}/_query_plan", new 
RestQueryPlanAction(controller));
+    }
+
+    @Override
+    protected void executeWithoutPassword(ActionAuthorizationInfo authInfo, 
BaseRequest request, BaseResponse response) throws DdlException {
+        // just allocate 2 slot for top holder map
+        Map<String, Object> resultMap = new HashMap<>(4);
+        String clusterName = request.getSingleParameter("cluster");
+        String dbName = request.getSingleParameter("database");
+        String tableName = request.getSingleParameter("table");
+        String postContent = request.getContent();
+        try {
+            // may be these common validate logic should be moved to one base 
class
+            if (Strings.isNullOrEmpty(clusterName)
+                    || Strings.isNullOrEmpty(dbName)
+                    || Strings.isNullOrEmpty(tableName)) {
+                throw new DorisHttpException(HttpResponseStatus.BAD_REQUEST, 
"{cluster}/{database}/{table} must be selected");
+            }
+            String sql;
+            if (Strings.isNullOrEmpty(postContent)) {
+                throw new DorisHttpException(HttpResponseStatus.BAD_REQUEST, 
"POST body must contains [sql] root object");
+            } else {
+                JSONObject jsonObject;
+                try {
+                    jsonObject = new JSONObject(postContent);
+                } catch (JSONException e) {
+                    throw new 
DorisHttpException(HttpResponseStatus.BAD_REQUEST, "malformed json [ " + 
postContent + " ]");
+                }
+                sql = String.valueOf(jsonObject.opt("sql"));
+                if (Strings.isNullOrEmpty(sql)) {
+                    throw new 
DorisHttpException(HttpResponseStatus.BAD_REQUEST, "POST body must contains 
[sql] root object");
+                }
+            }
+            String fullDbName = ClusterNamespace.getFullName(authInfo.cluster, 
dbName);
+            // check privilege for select, otherwise return HTTP 401
+            checkTblAuth(authInfo, fullDbName, tableName, 
PrivPredicate.SELECT);
+            Database db = Catalog.getCurrentCatalog().getDb(fullDbName);
+            if (db == null) {
+                throw new DorisHttpException(HttpResponseStatus.NOT_FOUND, 
"Database [" + dbName + "] " + "does not exists");
+            } else {
+                // may be should acquire writeLock
+                db.readLock();
+                try {
+                    Table table = db.getTable(tableName);
 
 Review comment:
   I think it's not a good way to nest "else" to throw so many exceptions.

----------------------------------------------------------------
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: dev-unsubscr...@doris.apache.org
For additional commands, e-mail: dev-h...@doris.apache.org

Reply via email to