You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by yu...@apache.org on 2020/07/09 16:04:06 UTC

[incubator-iotdb] branch kyy updated: transform failed plan

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

yuyuankang pushed a commit to branch kyy
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/kyy by this push:
     new d865931  transform failed plan
d865931 is described below

commit d86593187fddb9c7e078bce6d755f6604211ddf1
Author: Ring-k <yu...@hotmail.com>
AuthorDate: Fri Jul 10 00:03:39 2020 +0800

    transform failed plan
---
 .../iotdb/db/qp/physical/crud/InsertPlan.java      | 51 +++++++++++++++++++---
 .../iotdb/db/qp/physical/crud/InsertRowPlan.java   | 18 ++++++++
 .../db/qp/physical/crud/InsertTabletPlan.java      | 18 ++++++++
 3 files changed, 81 insertions(+), 6 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java
index 0d615fa..dc394aa 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java
@@ -19,8 +19,9 @@
 
 package org.apache.iotdb.db.qp.physical.crud;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iotdb.db.cost.statistic.Measurement;
 import org.apache.iotdb.db.qp.logical.Operator;
 import org.apache.iotdb.db.qp.physical.PhysicalPlan;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -35,7 +36,11 @@ public abstract class InsertPlan extends PhysicalPlan {
 
 
   // record the failed measurements
-  Map<String, Exception> failedMeasurements;
+  List<String> failedMeasurements;
+  List<TSDataType> failedDataTypes;
+  List<Exception> failedExceptions;
+  List<Integer> failedIndices;
+//  Map<String, Exception> failedMeasurements;
 
   public InsertPlan(Operator.OperatorType operatorType) {
     super(false, operatorType);
@@ -74,10 +79,14 @@ public abstract class InsertPlan extends PhysicalPlan {
     this.schemas = schemas;
   }
 
-  public Map<String, Exception> getFailedMeasurements() {
+  public List<String> getFailedMeasurements() {
     return failedMeasurements;
   }
 
+  public List<Exception> getFailedExceptions() {
+    return failedExceptions;
+  }
+
   public int getFailedMeasurementNumber() {
     return failedMeasurements == null ? 0 : failedMeasurements.size();
   }
@@ -88,10 +97,40 @@ public abstract class InsertPlan extends PhysicalPlan {
    */
   public void markFailedMeasurementInsertion(int index, Exception e) {
     if (failedMeasurements == null) {
-      failedMeasurements = new HashMap<>();
+      failedMeasurements = new ArrayList<>();
+      failedExceptions = new ArrayList<>();
+      failedIndices = new ArrayList<>();
+      failedDataTypes = new ArrayList<>();
     }
-    failedMeasurements.put(measurements[index], e);
+    failedMeasurements.add(measurements[index]);
+    failedDataTypes.add(dataTypes[index]);
+    failedExceptions.add(e);
+    failedIndices.add(index);
     measurements[index] = null;
     dataTypes[index] = null;
   }
+
+  public InsertPlan transformFailedPlan() {
+    if (failedMeasurements == null) {
+      return null;
+    }
+    measurements = new String[failedMeasurements.size()];
+    dataTypes = new TSDataType[failedMeasurements.size()];
+    for (int i = 0; i < measurements.length; i++) {
+      measurements[i] = failedMeasurements.get(i);
+      dataTypes[i] = failedDataTypes.get(i);
+    }
+    if (schemas != null) {
+      MeasurementSchema[] tempSchemas = schemas.clone();
+      schemas = new MeasurementSchema[measurements.length];
+      for (int i = 0; i < measurements.length; i++) {
+        schemas[i] = tempSchemas[failedIndices.get(i)];
+      }
+    }
+    failedMeasurements = null;
+    failedDataTypes = null;
+    failedExceptions = null;
+    failedIndices = null;
+    return this;
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java
index 4b49d71..24ae826 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java
@@ -57,6 +57,8 @@ public class InsertRowPlan extends InsertPlan {
   // if values is object[], we could use the raw type of them, and we should set this to false
   private boolean isNeedInferType = false;
 
+  private List<Object> failedValues;
+
   public InsertRowPlan() {
     super(OperatorType.INSERT);
   }
@@ -190,6 +192,10 @@ public class InsertRowPlan extends InsertPlan {
   @Override
   public void markFailedMeasurementInsertion(int index, Exception e) {
     super.markFailedMeasurementInsertion(index, e);
+    if (failedValues == null) {
+      failedValues = new ArrayList<>();
+    }
+    failedValues.add(values[index]);
     values[index] = null;
   }
 
@@ -431,4 +437,16 @@ public class InsertRowPlan extends InsertPlan {
     return new TimeValuePair(time,
         TsPrimitiveType.getByType(schemas[measurementIndex].getType(), value));
   }
+
+
+  @Override
+  public InsertPlan transformFailedPlan() {
+    super.transformFailedPlan();
+    values = new Object[failedValues.size()];
+    for (int i = 0; i < values.length; i++) {
+      values[i] = failedValues.get(i);
+    }
+    failedValues = null;
+    return this;
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertTabletPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertTabletPlan.java
index 7382040..8d19df5 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertTabletPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertTabletPlan.java
@@ -59,6 +59,8 @@ public class InsertTabletPlan extends InsertPlan {
   private int end;
   private List<Integer> range;
 
+  private List<Object> failedColumns;
+
 
   public InsertTabletPlan() {
     super(OperatorType.BATCHINSERT);
@@ -479,6 +481,22 @@ public class InsertTabletPlan extends InsertPlan {
 
   public void markFailedMeasurementInsertion(int index, Exception e) {
     super.markFailedMeasurementInsertion(index, e);
+    if (failedColumns == null) {
+      failedColumns = new ArrayList<>();
+    }
+    failedColumns.add(columns[index]);
     columns[index] = null;
   }
+
+  @Override
+  public InsertPlan transformFailedPlan() {
+    super.transformFailedPlan();
+    this.columns = new Object[failedColumns.size()];
+    for (int i = 0; i < failedColumns.size(); i++) {
+      columns[i] = failedColumns.get(i);
+    }
+    failedColumns = null;
+    // TODO is there any else attributes to replace ??
+    return this;
+  }
 }