You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ge...@apache.org on 2020/12/02 10:01:51 UTC

[iotdb] branch remove_duplicate_header created (now 9aae15d)

This is an automated email from the ASF dual-hosted git repository.

geniuspig pushed a change to branch remove_duplicate_header
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 9aae15d  remove static resps

This branch includes the following new commits:

     new 9aae15d  remove static resps

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/01: remove static resps

Posted by ge...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

geniuspig pushed a commit to branch remove_duplicate_header
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 9aae15d92f538a4ce731895eb7bf0ce995241a33
Author: Boris <96...@qq.com>
AuthorDate: Wed Dec 2 18:01:24 2020 +0800

    remove static resps
---
 .../org/apache/iotdb/db/service/StaticResps.java   |  98 +------------------
 .../org/apache/iotdb/db/service/TSServiceImpl.java | 107 ++++++---------------
 2 files changed, 28 insertions(+), 177 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java b/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java
index ac45067..f261469 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java
@@ -19,30 +19,10 @@
 
 package org.apache.iotdb.db.service;
 
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_CANCELLED;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_CHILD_PATHS;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_COLUMN;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_COUNT;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_CREATED_TIME;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_DEVICES;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_DONE;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_ITEM;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_PRIVILEGE;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_PROGRESS;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_ROLE;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_STORAGE_GROUP;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TASK_NAME;
 import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES_COMPRESSION;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES_DATATYPE;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES_ENCODING;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TTL;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_USER;
 import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE;
-import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VERSION;
 
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import org.apache.iotdb.rpc.RpcUtils;
 import org.apache.iotdb.rpc.TSStatusCode;
@@ -58,88 +38,12 @@ class StaticResps {
     // enum-like class
   }
 
-  static final TSExecuteStatementResp TTL_RESP = getNoTimeExecuteResp(
-      Arrays.asList(COLUMN_STORAGE_GROUP, COLUMN_TTL),
-      Arrays.asList(TSDataType.TEXT.toString(), TSDataType.INT64.toString()));
-
-  static final TSExecuteStatementResp FLUSH_INFO_RESP = getNoTimeExecuteResp(
-      Arrays.asList(COLUMN_ITEM, COLUMN_VALUE),
-      Arrays.asList(TSDataType.TEXT.toString(), TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp SHOW_VERSION_RESP = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_VERSION),
-      Collections.singletonList(TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp SHOW_TIMESERIES_RESP = getNoTimeExecuteResp(
-      Arrays.asList(COLUMN_TIMESERIES, COLUMN_STORAGE_GROUP, COLUMN_TIMESERIES_DATATYPE,
-          COLUMN_TIMESERIES_ENCODING, COLUMN_TIMESERIES_COMPRESSION),
-      Arrays.asList(TSDataType.TEXT.toString(),
-          TSDataType.TEXT.toString(),
-          TSDataType.TEXT.toString(),
-          TSDataType.TEXT.toString(),
-          TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp SHOW_DEVICES = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_DEVICES),
-      Collections.singletonList(TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp SHOW_STORAGE_GROUP = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_STORAGE_GROUP),
-      Collections.singletonList(TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp SHOW_CHILD_PATHS = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_CHILD_PATHS),
-      Collections.singletonList(TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp COUNT_TIMESERIES = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_COUNT),
-      Collections.singletonList(TSDataType.INT32.toString()));
-
-  static final TSExecuteStatementResp COUNT_NODE_TIMESERIES = getNoTimeExecuteResp(
-      Arrays.asList(COLUMN_COLUMN, COLUMN_COUNT),
-      Arrays.asList(TSDataType.TEXT.toString(), TSDataType.INT32.toString()));
-
-  static final TSExecuteStatementResp COUNT_DEVICES = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_COUNT),
-      Collections.singletonList(TSDataType.INT32.toString()));
-
-  static final TSExecuteStatementResp COUNT_STORAGE_GROUP = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_COUNT),
-      Collections.singletonList(TSDataType.INT32.toString()));
-
-  static final TSExecuteStatementResp COUNT_NODES = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_COUNT),
-      Collections.singletonList(TSDataType.INT32.toString()));
-
-  static final TSExecuteStatementResp LIST_ROLE_RESP = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_ROLE),
-      Collections.singletonList(TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp LIST_USER_RESP = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_USER),
-      Collections.singletonList(TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp LIST_USER_PRIVILEGE_RESP = getNoTimeExecuteResp(
-      Arrays.asList(COLUMN_ROLE, COLUMN_PRIVILEGE),
-      Arrays.asList(TSDataType.TEXT.toString(), TSDataType.TEXT.toString()));
-
-  static final TSExecuteStatementResp LIST_ROLE_PRIVILEGE_RESP = getNoTimeExecuteResp(
-      Collections.singletonList(COLUMN_PRIVILEGE),
-      Collections.singletonList(TSDataType.TEXT.toString()));
-
   static final TSExecuteStatementResp LAST_RESP = getExecuteResp(
       Arrays.asList(COLUMN_TIMESERIES, COLUMN_VALUE),
       Arrays.asList(TSDataType.TEXT.toString(), TSDataType.TEXT.toString()), false
   );
 
-  static final TSExecuteStatementResp MERGE_STATUS_RESP = getNoTimeExecuteResp(
-      Arrays.asList(COLUMN_STORAGE_GROUP, COLUMN_TASK_NAME, COLUMN_CREATED_TIME, COLUMN_PROGRESS,
-          COLUMN_CANCELLED, COLUMN_DONE),
-      Arrays.asList(TSDataType.TEXT.toString(), TSDataType.TEXT.toString(),
-          TSDataType.TEXT.toString(),
-          TSDataType.TEXT.toString(), TSDataType.BOOLEAN.toString(), TSDataType.BOOLEAN.toString()));
-
-  private static TSExecuteStatementResp getNoTimeExecuteResp(List<String> columns,
+  public static TSExecuteStatementResp getNoTimeExecuteResp(List<String> columns,
       List<String> dataTypes) {
     return getExecuteResp(columns, dataTypes, true);
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 9145e51..bc63108 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -18,8 +18,6 @@
  */
 package org.apache.iotdb.db.service;
 
-import static org.apache.iotdb.db.qp.physical.sys.ShowPlan.ShowContentType.TIMESERIES;
-
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.sql.SQLException;
@@ -650,7 +648,6 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     long startTime = System.currentTimeMillis();
     long queryId = -1;
     try {
-      TSExecuteStatementResp resp = getQueryResp(plan, username); // column headers
 
       // In case users forget to set this field in query, use the default value
       if (fetchSize == 0) {
@@ -678,10 +675,9 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
         }
       }
       if (plan.getOperatorType() == OperatorType.AGGREGATION) {
-        resp.setIgnoreTimeStamp(true);
         // the actual row number of aggregation query is 1
         fetchSize = 1;
-      } // else default ignoreTimeStamp is false
+      }
 
       if (plan instanceof GroupByTimePlan) {
         GroupByTimePlan groupByTimePlan = (GroupByTimePlan) plan;
@@ -691,8 +687,6 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
                 .getInterval()), fetchSize);
       }
 
-      resp.setOperationType(plan.getOperatorType().toString());
-
       // get deduplicated path num
       int deduplicatedPathNum = -1;
       if (plan instanceof AlignByDevicePlan) {
@@ -725,19 +719,30 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       if (plan instanceof AuthorPlan) {
         plan.setLoginUserName(username);
       }
+
+      TSExecuteStatementResp resp = null;
+
+      if (plan instanceof QueryPlan) {
+        resp = getQueryColumnHeaders(plan, username);
+      }
       // create and cache dataset
       QueryDataSet newDataSet = createQueryDataSet(queryId, plan);
+
+      if (plan instanceof ShowPlan || plan instanceof AuthorPlan) {
+        resp = getListDataResp(newDataSet);
+      }
+
+      resp.setOperationType(plan.getOperatorType().toString());
+
+      if (plan.getOperatorType() == OperatorType.AGGREGATION) {
+        resp.setIgnoreTimeStamp(true);
+      } // else default ignoreTimeStamp is false
+
       if (plan instanceof QueryPlan && !((QueryPlan) plan).isAlignByTime()
           && newDataSet instanceof NonAlignEngineDataSet) {
         TSQueryNonAlignDataSet result = fillRpcNonAlignReturnData(fetchSize, newDataSet, username);
         resp.setNonAlignQueryDataSet(result);
       } else {
-        if (plan instanceof ShowPlan && ((ShowPlan) plan).getShowContentType() == TIMESERIES) {
-          resp.setColumns(
-              newDataSet.getPaths().stream().map(Path::getFullPath).collect(Collectors.toList()));
-          resp.setDataTypeList(
-              newDataSet.getDataTypes().stream().map(Enum::toString).collect(Collectors.toList()));
-        }
         TSQueryDataSet result = fillRpcReturnData(fetchSize, newDataSet, username);
         resp.setQueryDataSet(result);
       }
@@ -791,71 +796,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     }
   }
 
-  private TSExecuteStatementResp getQueryResp(PhysicalPlan plan, String username)
-      throws QueryProcessException, AuthException, TException, MetadataException {
-    if (plan instanceof AuthorPlan) {
-      return getAuthQueryColumnHeaders(plan);
-    } else if (plan instanceof ShowPlan) {
-      return getShowQueryColumnHeaders((ShowPlan) plan);
-    } else {
-      return getQueryColumnHeaders(plan, username);
-    }
-  }
-
-  private TSExecuteStatementResp getShowQueryColumnHeaders(ShowPlan showPlan)
-      throws QueryProcessException {
-    switch (showPlan.getShowContentType()) {
-      case TTL:
-        return StaticResps.TTL_RESP;
-      case FLUSH_TASK_INFO:
-        return StaticResps.FLUSH_INFO_RESP;
-      case VERSION:
-        return StaticResps.SHOW_VERSION_RESP;
-      case TIMESERIES:
-        return StaticResps.SHOW_TIMESERIES_RESP;
-      case STORAGE_GROUP:
-        return StaticResps.SHOW_STORAGE_GROUP;
-      case CHILD_PATH:
-        return StaticResps.SHOW_CHILD_PATHS;
-      case DEVICES:
-        return StaticResps.SHOW_DEVICES;
-      case COUNT_NODE_TIMESERIES:
-        return StaticResps.COUNT_NODE_TIMESERIES;
-      case COUNT_NODES:
-        return StaticResps.COUNT_NODES;
-      case COUNT_TIMESERIES:
-        return StaticResps.COUNT_TIMESERIES;
-      case COUNT_DEVICES:
-        return StaticResps.COUNT_DEVICES;
-      case COUNT_STORAGE_GROUP:
-        return StaticResps.COUNT_STORAGE_GROUP;
-      case MERGE_STATUS:
-        return StaticResps.MERGE_STATUS_RESP;
-      default:
-        logger.warn("Unsupported show content type: {}", showPlan.getShowContentType());
-        throw new QueryProcessException(
-            "Unsupported show content type:" + showPlan.getShowContentType());
-    }
-  }
-
-  private TSExecuteStatementResp getAuthQueryColumnHeaders(PhysicalPlan plan) {
-    AuthorPlan authorPlan = (AuthorPlan) plan;
-    switch (authorPlan.getAuthorType()) {
-      case LIST_ROLE:
-      case LIST_USER_ROLES:
-        return StaticResps.LIST_ROLE_RESP;
-      case LIST_USER:
-      case LIST_ROLE_USERS:
-        return StaticResps.LIST_USER_RESP;
-      case LIST_ROLE_PRIVILEGE:
-        return StaticResps.LIST_ROLE_PRIVILEGE_RESP;
-      case LIST_USER_PRIVILEGE:
-        return StaticResps.LIST_USER_PRIVILEGE_RESP;
-      default:
-        return RpcUtils.getTSExecuteStatementResp(
-            RpcUtils.getStatus(TSStatusCode.SQL_PARSE_ERROR,
-                String.format("%s is not an auth query", authorPlan.getAuthorType())));
-    }
+  private TSExecuteStatementResp getListDataResp(QueryDataSet dataSet) {
+    return StaticResps
+        .getNoTimeExecuteResp(dataSet.getPaths().stream().map(Path::getFullPath).collect(
+            Collectors.toList()), dataSet.getDataTypes().stream().map(Enum::toString).collect(
+            Collectors.toList()));
   }
 
   /**
@@ -887,9 +832,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       return StaticResps.LAST_RESP.deepCopy();
     } else if (plan instanceof AggregationPlan && ((AggregationPlan) plan).getLevel() >= 0) {
       Map<Integer, String> pathIndex = new HashMap<>();
-      Map<String, AggregateResult> finalPaths = FilePathUtils.getPathByLevel((AggregationPlan) plan, pathIndex);
+      Map<String, AggregateResult> finalPaths = FilePathUtils
+          .getPathByLevel((AggregationPlan) plan, pathIndex);
       for (Map.Entry<String, AggregateResult> entry : finalPaths.entrySet()) {
-        respColumns.add(entry.getValue().getAggregationType().toString() + "(" + entry.getKey() + ")");
+        respColumns
+            .add(entry.getValue().getAggregationType().toString() + "(" + entry.getKey() + ")");
         columnsTypes.add(entry.getValue().getResultDataType().toString());
       }
     } else {