You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/07/27 08:14:59 UTC

[GitHub] [iotdb] qiaojialin commented on a change in pull request #3614: [IOTDB-1524] Support SELECT ... INTO ... clause

qiaojialin commented on a change in pull request #3614:
URL: https://github.com/apache/iotdb/pull/3614#discussion_r677198261



##########
File path: server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
##########
@@ -1127,41 +1181,47 @@ public TSExecuteStatementResp executeUpdateStatement(TSExecuteStatementReq req)
     }
 
     try {
-      return executeUpdateStatement(req.getStatement(), req.getSessionId());
+      PhysicalPlan physicalPlan =
+          processor.parseSQLToPhysicalPlan(req.statement, sessionManager.getZoneId(req.sessionId));
+      return physicalPlan.isQuery()
+          ? RpcUtils.getTSExecuteStatementResp(
+              TSStatusCode.EXECUTE_STATEMENT_ERROR, "Statement is a query statement.")
+          : executeUpdateStatement(
+              req.statement,
+              req.statementId,
+              physicalPlan,
+              req.fetchSize,
+              req.timeout,
+              req.getSessionId());
+    } catch (InterruptedException e) {
+      LOGGER.error(INFO_INTERRUPT_ERROR, req, e);
+      Thread.currentThread().interrupt();
+      return RpcUtils.getTSExecuteStatementResp(onQueryException(e, "executing update statement"));
     } catch (Exception e) {
       return RpcUtils.getTSExecuteStatementResp(onQueryException(e, "executing update statement"));
     }
   }
 
-  private TSExecuteStatementResp executeUpdateStatement(PhysicalPlan plan, long sessionId) {
-    TSStatus status = checkAuthority(plan, sessionId);
-    if (status != null) {
-      return new TSExecuteStatementResp(status);
-    }
-
-    status = executeNonQueryPlan(plan);
-    TSExecuteStatementResp resp = RpcUtils.getTSExecuteStatementResp(status);
-    long queryId = sessionManager.requestQueryId(false);
-    return resp.setQueryId(queryId);
-  }
-
-  private boolean executeNonQuery(PhysicalPlan plan)
-      throws QueryProcessException, StorageGroupNotSetException, StorageEngineException {
-    if (IoTDBDescriptor.getInstance().getConfig().isReadOnly()) {
-      throw new QueryProcessException(
-          "Current system mode is read-only, does not support non-query operation");
-    }
-    return executor.processNonQuery(plan);
+  private TSExecuteStatementResp executeUpdateStatement(

Review comment:
       add javadoc 

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/selectinto/InsertTabletPlanGenerator.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.iotdb.db.engine.selectinto;
+
+import org.apache.iotdb.db.exception.metadata.IllegalPathException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.physical.crud.InsertTabletPlan;
+import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Field;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.utils.BitMap;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/** internallyConstructNewPlan -> collectRowRecord * N -> generateInsertTabletPlan */
+public class InsertTabletPlanGenerator {
+
+  private final String targetDevice;
+  // the index of column in InsertTabletPlan -> the index of output column of query data set
+  private final List<Integer> queryDataSetIndexes;
+  // the index of column in InsertTabletPlan -> the measurement id of the column
+  private final List<String> targetMeasurementIds;
+
+  private final int fetchSize;
+
+  // the following fields are used to construct plan
+  private int rowCount;
+  private long[] times;
+  private Object[] columns;
+  private BitMap[] bitMaps;
+  private TSDataType[] dataTypes;
+
+  private int numberOfInitializedColumns;
+
+  public InsertTabletPlanGenerator(String targetDevice, int fetchSize) {
+    this.targetDevice = targetDevice;
+    queryDataSetIndexes = new ArrayList<>();
+    targetMeasurementIds = new ArrayList<>();
+
+    this.fetchSize = fetchSize;
+  }
+
+  public void collectTargetPathInformation(String targetMeasurementId, int queryDataSetIndex) {
+    targetMeasurementIds.add(targetMeasurementId);
+    queryDataSetIndexes.add(queryDataSetIndex);
+  }
+
+  public void internallyConstructNewPlan() {
+    rowCount = 0;
+    times = new long[fetchSize];

Review comment:
       add a parameter in config file




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

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org