You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2022/08/24 11:27:04 UTC

[iotdb] branch rel/0.13 updated: REST API nonQuery support select into (#6932)

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

qiaojialin pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.13 by this push:
     new bd0440a217 REST API nonQuery support select into (#6932)
bd0440a217 is described below

commit bd0440a2177ea44d99adae24512c212c42ac32a7
Author: CloudWise-Lukemiao <76...@users.noreply.github.com>
AuthorDate: Wed Aug 24 19:26:59 2022 +0800

    REST API nonQuery support select into (#6932)
---
 .../protocol/rest/handler/PhysicalPlanHandler.java | 41 ++++++++++++++++++++
 .../db/protocol/rest/impl/RestApiServiceImpl.java  | 44 ++++++++++++++++++++++
 2 files changed, 85 insertions(+)

diff --git a/server/src/main/java/org/apache/iotdb/db/protocol/rest/handler/PhysicalPlanHandler.java b/server/src/main/java/org/apache/iotdb/db/protocol/rest/handler/PhysicalPlanHandler.java
new file mode 100644
index 0000000000..3419ebb443
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/protocol/rest/handler/PhysicalPlanHandler.java
@@ -0,0 +1,41 @@
+/*
+ * 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.protocol.rest.handler;
+
+import org.apache.iotdb.db.qp.physical.crud.InsertMultiTabletPlan;
+import org.apache.iotdb.db.qp.physical.crud.InsertTabletPlan;
+
+import javax.ws.rs.core.SecurityContext;
+
+import java.util.List;
+
+public class PhysicalPlanHandler {
+  public static InsertMultiTabletPlan insertTabletsInternally(
+      AuthorizationHandler authorizationHandler,
+      SecurityContext securityContext,
+      List<InsertTabletPlan> insertTabletPlans) {
+    InsertMultiTabletPlan insertMultiTabletsPlan = new InsertMultiTabletPlan();
+    for (int i = 0; i < insertTabletPlans.size(); i++) {
+      InsertTabletPlan insertTabletPlan = insertTabletPlans.get(i);
+      authorizationHandler.checkAuthority(securityContext, insertTabletPlan);
+    }
+    insertMultiTabletsPlan.setInsertTabletPlanList(insertTabletPlans);
+
+    return insertMultiTabletsPlan;
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/protocol/rest/impl/RestApiServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/protocol/rest/impl/RestApiServiceImpl.java
index 98dd6e070f..80cc36b4d3 100644
--- a/server/src/main/java/org/apache/iotdb/db/protocol/rest/impl/RestApiServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/protocol/rest/impl/RestApiServiceImpl.java
@@ -19,11 +19,13 @@ package org.apache.iotdb.db.protocol.rest.impl;
 
 import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor;
+import org.apache.iotdb.db.engine.selectinto.InsertTabletPlansIterator;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.protocol.rest.RestApiService;
 import org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler;
 import org.apache.iotdb.db.protocol.rest.handler.ExceptionHandler;
 import org.apache.iotdb.db.protocol.rest.handler.PhysicalPlanConstructionHandler;
+import org.apache.iotdb.db.protocol.rest.handler.PhysicalPlanHandler;
 import org.apache.iotdb.db.protocol.rest.handler.QueryDataSetHandler;
 import org.apache.iotdb.db.protocol.rest.handler.RequestValidationHandler;
 import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus;
@@ -31,8 +33,10 @@ import org.apache.iotdb.db.protocol.rest.model.InsertTabletRequest;
 import org.apache.iotdb.db.protocol.rest.model.SQL;
 import org.apache.iotdb.db.qp.Planner;
 import org.apache.iotdb.db.qp.physical.PhysicalPlan;
+import org.apache.iotdb.db.qp.physical.crud.InsertMultiTabletPlan;
 import org.apache.iotdb.db.qp.physical.crud.InsertTabletPlan;
 import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
+import org.apache.iotdb.db.qp.physical.crud.SelectIntoPlan;
 import org.apache.iotdb.db.qp.physical.sys.AuthorPlan;
 import org.apache.iotdb.db.qp.physical.sys.ShowPlan;
 import org.apache.iotdb.db.query.context.QueryContext;
@@ -45,6 +49,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.SecurityContext;
 
 import java.time.ZoneId;
+import java.util.List;
 
 public class RestApiServiceImpl extends RestApiService {
 
@@ -74,6 +79,45 @@ public class RestApiServiceImpl extends RestApiService {
         return response;
       }
 
+      if (physicalPlan instanceof SelectIntoPlan) {
+        final long queryId = ServiceProvider.SESSION_MANAGER.requestQueryId(true);
+        QueryContext context =
+            serviceProvider.genQueryContext(
+                queryId,
+                physicalPlan.isDebug(),
+                System.currentTimeMillis(),
+                sql.getSql(),
+                IoTDBConstant.DEFAULT_CONNECTION_TIMEOUT_MS);
+        final SelectIntoPlan selectIntoPlan = (SelectIntoPlan) physicalPlan;
+        final QueryPlan queryPlan = selectIntoPlan.getQueryPlan();
+
+        InsertTabletPlansIterator insertTabletPlansIterator =
+            new InsertTabletPlansIterator(
+                queryPlan,
+                serviceProvider.createQueryDataSet(
+                    context, queryPlan, IoTDBConstant.DEFAULT_FETCH_SIZE),
+                selectIntoPlan.getFromPath(),
+                selectIntoPlan.getIntoPaths(),
+                selectIntoPlan.isIntoPathsAligned());
+        while (insertTabletPlansIterator.hasNext()) {
+          List<InsertTabletPlan> insertTabletPlans = insertTabletPlansIterator.next();
+          if (insertTabletPlans.isEmpty()) {
+            continue;
+          }
+
+          InsertMultiTabletPlan insertMultiTabletsPlan =
+              PhysicalPlanHandler.insertTabletsInternally(
+                  authorizationHandler, securityContext, insertTabletPlans);
+          serviceProvider.executeNonQuery(insertMultiTabletsPlan);
+        }
+        return Response.ok()
+            .entity(
+                new ExecutionStatus()
+                    .code(TSStatusCode.SUCCESS_STATUS.getStatusCode())
+                    .message(TSStatusCode.SUCCESS_STATUS.name()))
+            .build();
+      }
+
       return Response.ok()
           .entity(
               serviceProvider.executeNonQuery(physicalPlan)