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_r306287336
 
 

 ##########
 File path: 
fe/src/main/java/org/apache/doris/http/rest/RestTableSchemaAction.java
 ##########
 @@ -0,0 +1,131 @@
+// 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.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.OlapTable;
+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.codehaus.jackson.map.ObjectMapper;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Get table schema for specified cluster.database.table with privilege 
checking
+ */
+public class RestTableSchemaAction extends RestBaseAction {
+
+    public RestTableSchemaAction(ActionController controller) {
+        super(controller);
+    }
+
+    public static void registerAction(ActionController controller) throws 
IllegalArgException {
+        // the extra `/api` path is so disgusting
+        controller.registerHandler(HttpMethod.GET,
+                "/api/{cluster}/{database}/{table}/_schema", new 
RestTableSchemaAction(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<>(2);
+        String clusterName = request.getSingleParameter("cluster");
+        String dbName = request.getSingleParameter("database");
+        String tableName = request.getSingleParameter("table");
+        try {
+            if (Strings.isNullOrEmpty(clusterName)
+                    || Strings.isNullOrEmpty(dbName)
+                    || Strings.isNullOrEmpty(tableName)) {
+                throw new DorisHttpException(HttpResponseStatus.BAD_REQUEST, 
"No cluster or database or table selected.");
+            }
+            String fullDbName = ClusterNamespace.getFullName(authInfo.cluster, 
dbName);
+            // check privilege for select, otherwise return 401 HTTP status
+            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 {
+                db.readLock();
+                try {
+                    Table table = db.getTable(tableName);
+                    if (table == null) {
+                        throw new 
DorisHttpException(HttpResponseStatus.NOT_FOUND, "Table [" + tableName + "] " + 
"does not exists");
+                    } else {
+                        // just only support OlapTable, ignore others such as 
ESTable, KuduTable
+                        if (!(table instanceof OlapTable)) {
+                            // Forbidden
+                            throw new 
DorisHttpException(HttpResponseStatus.FORBIDDEN, "Table [" + tableName + "] "
+                                    + "is not a OlapTable, only support 
OlapTable currently");
+                        } else {
+                            try {
+                                List<Column> columns = table.getBaseSchema();
+                                Map<String, Map<String, String>> propMap = new 
HashMap<>(columns.size());
+                                for (Column column : columns) {
+                                    Map<String, String> baseInfo = new 
HashMap<>(2);
+                                    baseInfo.put("type", 
column.getType().getPrimitiveType().toString());
+                                    baseInfo.put("comment", 
column.getComment());
 
 Review comment:
   Do you have considered Decimal type? because it's PrimitiveType does't 
include it's scalar and precision.

----------------------------------------------------------------
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]

Reply via email to