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

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


The following commit(s) were added to refs/heads/TableModelIngestion by this 
push:
     new 09fed677cb5 finish analyze insert tablet
09fed677cb5 is described below

commit 09fed677cb50ddd1109628ec8b2bf836db940a8c
Author: jt2594838 <[email protected]>
AuthorDate: Tue Jun 18 16:06:46 2024 +0800

    finish analyze insert tablet
---
 .../db/queryengine/plan/analyze/AnalyzeUtils.java  | 155 ++++++++++++---------
 .../queryengine/plan/analyze/AnalyzeVisitor.java   |  24 ++--
 .../plan/analyze/schema/SchemaValidator.java       |  38 ++++-
 .../relational/analyzer/StatementAnalyzer.java     |   1 +
 .../plan/relational/sql/ast/InsertTablet.java      |  98 ++++++-------
 .../relational/sql/ast/WrappedInsertStatement.java |   4 +-
 .../plan/statement/crud/InsertTabletStatement.java |   4 +
 7 files changed, 182 insertions(+), 142 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
index 0728af062db..2fb1089d2a3 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
@@ -26,6 +26,7 @@ import 
org.apache.iotdb.commons.partition.DataPartitionQueryParam;
 import org.apache.iotdb.commons.service.metric.PerformanceOverviewMetrics;
 import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
+import 
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.WrappedInsertStatement;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertBaseStatement;
 import 
org.apache.iotdb.db.queryengine.plan.statement.crud.InsertMultiTabletsStatement;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowStatement;
@@ -34,6 +35,7 @@ import 
org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement
 import org.apache.iotdb.rpc.RpcUtils;
 import org.apache.iotdb.rpc.TSStatusCode;
 
+import org.apache.tsfile.file.metadata.IDeviceID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -60,6 +62,7 @@ public class AnalyzeUtils {
       InsertBaseStatement insertBaseStatement,
       Runnable schemaValidation,
       DataPartitionQueryFunc partitionFetcher,
+      DataPartitionQueryParamComputation partitionQueryParamComputation,
       IAnalysis analysis,
       boolean removeLogicalView) {
     context.setQueryType(QueryType.WRITE);
@@ -73,27 +76,84 @@ public class AnalyzeUtils {
     }
     analysis.setRealStatement(realStatement);
 
-    if (realStatement instanceof InsertTabletStatement) {
-      InsertTabletStatement realInsertTabletStatement = 
(InsertTabletStatement) realStatement;
+    analyzeDataPartition(
+        analysis,
+        partitionQueryParamComputation.compute(realStatement),
+        context.getSession().getUserName(),
+        partitionFetcher);
+    return realStatement;
+  }
+
+  public static List<DataPartitionQueryParam> 
computeTableDataPartitionParams(InsertBaseStatement statement) {
+    if (statement instanceof InsertTabletStatement) {
+      InsertTabletStatement insertTabletStatement = (InsertTabletStatement) 
statement;
+      Map<IDeviceID, Set<TTimePartitionSlot>> timePartitionSlotMap = new 
HashMap<>();
+      for (int i = 0; i < insertTabletStatement.getRowCount(); i++) {
+        
timePartitionSlotMap.computeIfAbsent(insertTabletStatement.getTableDeviceID(i),
+            id -> new 
HashSet<>()).add(insertTabletStatement.getTimePartitionSlot(i));
+      }
+      return computeDataPartitionParams(timePartitionSlotMap);
+    } else if (statement instanceof InsertMultiTabletsStatement) {
+      InsertMultiTabletsStatement insertMultiTabletsStatement = 
(InsertMultiTabletsStatement) statement;
+      Map<IDeviceID, Set<TTimePartitionSlot>> timePartitionSlotMap = new 
HashMap<>();
+      for (InsertTabletStatement insertTabletStatement :
+          insertMultiTabletsStatement.getInsertTabletStatementList()) {
+        for (int i = 0; i < insertTabletStatement.getRowCount(); i++) {
+          
timePartitionSlotMap.computeIfAbsent(insertTabletStatement.getTableDeviceID(i),
+              id -> new 
HashSet<>()).add(insertTabletStatement.getTimePartitionSlot(i));
+        }
+      }
+      return computeDataPartitionParams(timePartitionSlotMap);
+    }
+    throw new UnsupportedOperationException("computeDataPartitionParams for " 
+ statement);
+  }
+
+
+  public static List<DataPartitionQueryParam> 
computeTreeDataPartitionParams(InsertBaseStatement statement) {
+    if (statement instanceof InsertTabletStatement) {
+      InsertTabletStatement insertTabletStatement = (InsertTabletStatement) 
statement;
       DataPartitionQueryParam dataPartitionQueryParam = new 
DataPartitionQueryParam();
-      dataPartitionQueryParam.setDevicePath(
-          realInsertTabletStatement.getDevicePath().getFullPath());
+      dataPartitionQueryParam.setDeviceID(
+          insertTabletStatement.getDevicePath().getIDeviceIDAsFullDevice());
       dataPartitionQueryParam.setTimePartitionSlotList(
-          realInsertTabletStatement.getTimePartitionSlots());
-
-      getAnalysisForWriting(
-          analysis,
-          Collections.singletonList(dataPartitionQueryParam),
-          context.getSession().getUserName(),
-          partitionFetcher);
-    } else {
-      computeAnalysisForMultiTablets(
-          analysis,
-          (InsertMultiTabletsStatement) realStatement,
-          context.getSession().getUserName(),
-          partitionFetcher);
+          insertTabletStatement.getTimePartitionSlots());
+      return Collections.singletonList(dataPartitionQueryParam);
+    } else if (statement instanceof InsertMultiTabletsStatement) {
+      InsertMultiTabletsStatement insertMultiTabletsStatement = 
(InsertMultiTabletsStatement) statement;
+      Map<IDeviceID, Set<TTimePartitionSlot>> dataPartitionQueryParamMap = new 
HashMap<>();
+      for (InsertTabletStatement insertTabletStatement :
+          insertMultiTabletsStatement.getInsertTabletStatementList()) {
+        Set<TTimePartitionSlot> timePartitionSlotSet =
+            dataPartitionQueryParamMap.computeIfAbsent(
+                
insertTabletStatement.getDevicePath().getIDeviceIDAsFullDevice(),
+                k -> new HashSet<>());
+        
timePartitionSlotSet.addAll(insertTabletStatement.getTimePartitionSlots());
+      }
+      return computeDataPartitionParams(dataPartitionQueryParamMap);
+    } else if (statement instanceof InsertRowsStatement) {
+      final InsertRowsStatement insertRowsStatement = (InsertRowsStatement) 
statement;
+      Map<IDeviceID, Set<TTimePartitionSlot>> dataPartitionQueryParamMap = new 
HashMap<>();
+      for (InsertRowStatement insertRowStatement : 
insertRowsStatement.getInsertRowStatementList()) {
+        Set<TTimePartitionSlot> timePartitionSlotSet =
+            dataPartitionQueryParamMap.computeIfAbsent(
+                insertRowStatement.getDevicePath().getIDeviceIDAsFullDevice(), 
k -> new HashSet<>());
+        timePartitionSlotSet.add(insertRowStatement.getTimePartitionSlot());
+      }
+      return computeDataPartitionParams(dataPartitionQueryParamMap);
     }
-    return realStatement;
+    throw new UnsupportedOperationException("computeDataPartitionParams for " 
+ statement);
+  }
+
+  public static List<DataPartitionQueryParam> 
computeDataPartitionParams(Map<IDeviceID, Set<TTimePartitionSlot>> 
dataPartitionQueryParamMap) {
+    List<DataPartitionQueryParam> dataPartitionQueryParams = new ArrayList<>();
+    for (Map.Entry<IDeviceID
+        , Set<TTimePartitionSlot>> entry : 
dataPartitionQueryParamMap.entrySet()) {
+      DataPartitionQueryParam dataPartitionQueryParam = new 
DataPartitionQueryParam();
+      dataPartitionQueryParam.setDeviceID(entry.getKey());
+      dataPartitionQueryParam.setTimePartitionSlotList(new 
ArrayList<>(entry.getValue()));
+      dataPartitionQueryParams.add(dataPartitionQueryParam);
+    }
+    return dataPartitionQueryParams;
   }
 
   public static void validateSchema(
@@ -143,8 +203,10 @@ public class AnalyzeUtils {
     }
   }
 
-  /** get analysis according to statement and params */
-  public static void getAnalysisForWriting(
+  /**
+   * get analysis according to statement and params
+   */
+  public static void analyzeDataPartition(
       IAnalysis analysis,
       List<DataPartitionQueryParam> dataPartitionQueryParams,
       String userName,
@@ -163,58 +225,13 @@ public class AnalyzeUtils {
     analysis.setDataPartitionInfo(dataPartition);
   }
 
-  public static void computeAnalysisForInsertRows(
-      IAnalysis analysis,
-      InsertRowsStatement insertRowsStatement,
-      String userName,
-      DataPartitionQueryFunc partitionFetcher) {
-    Map<String, Set<TTimePartitionSlot>> dataPartitionQueryParamMap = new 
HashMap<>();
-    for (InsertRowStatement insertRowStatement : 
insertRowsStatement.getInsertRowStatementList()) {
-      Set<TTimePartitionSlot> timePartitionSlotSet =
-          dataPartitionQueryParamMap.computeIfAbsent(
-              insertRowStatement.getDevicePath().getFullPath(), k -> new 
HashSet<>());
-      timePartitionSlotSet.add(insertRowStatement.getTimePartitionSlot());
-    }
-
-    List<DataPartitionQueryParam> dataPartitionQueryParams = new ArrayList<>();
-    for (Map.Entry<String, Set<TTimePartitionSlot>> entry : 
dataPartitionQueryParamMap.entrySet()) {
-      DataPartitionQueryParam dataPartitionQueryParam = new 
DataPartitionQueryParam();
-      dataPartitionQueryParam.setDevicePath(entry.getKey());
-      dataPartitionQueryParam.setTimePartitionSlotList(new 
ArrayList<>(entry.getValue()));
-      dataPartitionQueryParams.add(dataPartitionQueryParam);
-    }
-
-    getAnalysisForWriting(analysis, dataPartitionQueryParams, userName, 
partitionFetcher);
-  }
-
-  public static void computeAnalysisForMultiTablets(
-      IAnalysis analysis,
-      InsertMultiTabletsStatement insertMultiTabletsStatement,
-      String userName,
-      DataPartitionQueryFunc partitionFetcher) {
-    Map<String, Set<TTimePartitionSlot>> dataPartitionQueryParamMap = new 
HashMap<>();
-    for (InsertTabletStatement insertTabletStatement :
-        insertMultiTabletsStatement.getInsertTabletStatementList()) {
-      Set<TTimePartitionSlot> timePartitionSlotSet =
-          dataPartitionQueryParamMap.computeIfAbsent(
-              insertTabletStatement.getDevicePath().getFullPath(), k -> new 
HashSet<>());
-      
timePartitionSlotSet.addAll(insertTabletStatement.getTimePartitionSlots());
-    }
-
-    List<DataPartitionQueryParam> dataPartitionQueryParams = new ArrayList<>();
-    for (Map.Entry<String, Set<TTimePartitionSlot>> entry : 
dataPartitionQueryParamMap.entrySet()) {
-      DataPartitionQueryParam dataPartitionQueryParam = new 
DataPartitionQueryParam();
-      dataPartitionQueryParam.setDevicePath(entry.getKey());
-      dataPartitionQueryParam.setTimePartitionSlotList(new 
ArrayList<>(entry.getValue()));
-      dataPartitionQueryParams.add(dataPartitionQueryParam);
-    }
-
-    getAnalysisForWriting(analysis, dataPartitionQueryParams, userName, 
partitionFetcher);
-  }
-
   public interface DataPartitionQueryFunc {
 
     DataPartition queryDataPartition(
         List<DataPartitionQueryParam> dataPartitionQueryParams, String 
userName);
   }
+
+  public interface DataPartitionQueryParamComputation {
+    List<DataPartitionQueryParam> compute(InsertBaseStatement statement);
+  }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
index f33266ae0c6..533a50d8482 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
@@ -186,9 +186,6 @@ import static 
org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant
 import static 
org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant.ENDTIME;
 import static 
org.apache.iotdb.db.queryengine.metric.QueryPlanCostMetricSet.PARTITION_FETCHER;
 import static 
org.apache.iotdb.db.queryengine.metric.QueryPlanCostMetricSet.SCHEMA_FETCHER;
-import static 
org.apache.iotdb.db.queryengine.plan.analyze.AnalyzeUtils.computeAnalysisForInsertRows;
-import static 
org.apache.iotdb.db.queryengine.plan.analyze.AnalyzeUtils.computeAnalysisForMultiTablets;
-import static 
org.apache.iotdb.db.queryengine.plan.analyze.AnalyzeUtils.getAnalysisForWriting;
 import static 
org.apache.iotdb.db.queryengine.plan.analyze.AnalyzeUtils.removeLogicalView;
 import static 
org.apache.iotdb.db.queryengine.plan.analyze.AnalyzeUtils.validateSchema;
 import static 
org.apache.iotdb.db.queryengine.plan.analyze.ExpressionAnalyzer.bindSchemaForExpression;
@@ -2633,6 +2630,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
         insertTabletStatement,
         () -> SchemaValidator.validate(schemaFetcher, insertTabletStatement, 
context),
         partitionFetcher::getOrCreateDataPartition,
+        AnalyzeUtils::computeTreeDataPartitionParams,
         analysis,
         true);
     return analysis;
@@ -2661,15 +2659,15 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
       dataPartitionQueryParam.setTimePartitionSlotList(
           
Collections.singletonList(realInsertRowStatement.getTimePartitionSlot()));
 
-      getAnalysisForWriting(
+      AnalyzeUtils.analyzeDataPartition(
           analysis,
           Collections.singletonList(dataPartitionQueryParam),
           context.getSession().getUserName(),
           partitionFetcher::getOrCreateDataPartition);
     } else {
-      computeAnalysisForInsertRows(
+      AnalyzeUtils.analyzeDataPartition(
           analysis,
-          (InsertRowsStatement) realInsertStatement,
+          AnalyzeUtils.computeTreeDataPartitionParams(realInsertStatement),
           context.getSession().getUserName(),
           partitionFetcher::getOrCreateDataPartition);
     }
@@ -2693,9 +2691,9 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
     }
     analysis.setRealStatement(realInsertRowsStatement);
 
-    computeAnalysisForInsertRows(
+    AnalyzeUtils.analyzeDataPartition(
         analysis,
-        realInsertRowsStatement,
+        AnalyzeUtils.computeTreeDataPartitionParams(realInsertRowsStatement),
         context.getSession().getUserName(),
         partitionFetcher::getOrCreateDataPartition);
     return analysis;
@@ -2718,9 +2716,9 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
     }
     analysis.setRealStatement(realStatement);
 
-    computeAnalysisForMultiTablets(
+    AnalyzeUtils.analyzeDataPartition(
         analysis,
-        realStatement,
+        AnalyzeUtils.computeTreeDataPartitionParams(realStatement),
         context.getSession().getUserName(),
         partitionFetcher::getOrCreateDataPartition);
     return analysis;
@@ -2750,15 +2748,15 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
       
dataPartitionQueryParam.setDeviceID(realStatement.getDevicePath().getIDeviceIDAsFullDevice());
       
dataPartitionQueryParam.setTimePartitionSlotList(realStatement.getTimePartitionSlots());
 
-      getAnalysisForWriting(
+      AnalyzeUtils.analyzeDataPartition(
           analysis,
           Collections.singletonList(dataPartitionQueryParam),
           context.getSession().getUserName(),
           partitionFetcher::getOrCreateDataPartition);
     } else {
-      computeAnalysisForInsertRows(
+      AnalyzeUtils.analyzeDataPartition(
           analysis,
-          (InsertRowsStatement) realInsertStatement,
+          AnalyzeUtils.computeTreeDataPartitionParams(realInsertStatement),
           context.getSession().getUserName(),
           partitionFetcher::getOrCreateDataPartition);
     }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/SchemaValidator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/SchemaValidator.java
index 96c55a05b0e..71dc2afbe4b 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/SchemaValidator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/SchemaValidator.java
@@ -19,12 +19,16 @@
 
 package org.apache.iotdb.db.queryengine.plan.analyze.schema;
 
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
 import org.apache.iotdb.db.queryengine.common.schematree.ISchemaTree;
+import org.apache.iotdb.db.queryengine.plan.relational.metadata.ColumnSchema;
 import org.apache.iotdb.db.queryengine.plan.relational.metadata.Metadata;
+import org.apache.iotdb.db.queryengine.plan.relational.metadata.TableSchema;
 import 
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.WrappedInsertStatement;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertBaseStatement;
 import 
org.apache.iotdb.db.queryengine.plan.statement.crud.InsertMultiTabletsStatement;
@@ -61,15 +65,43 @@ public class SchemaValidator {
       Metadata metadata, WrappedInsertStatement insertStatement, 
MPPQueryContext context) {
     try {
       String databaseName = context.getSession().getDatabaseName().get();
-      //      metadata.validateTableHeaderSchema(databaseName);
-      //      metadata.fetchAndComputeSchemaWithAutoCreate(
-      //          insertStatement.getSchemaValidationList(), context);
+      final TableSchema incomingSchema = insertStatement.getTableSchema();
+      final TableSchema realSchema = 
metadata.validateTableHeaderSchema(databaseName,
+          incomingSchema, context);
+      validate(incomingSchema, realSchema);
+      metadata.validateDeviceSchema(insertStatement, context);
       insertStatement.updateAfterSchemaValidation(context);
     } catch (QueryProcessException e) {
       throw new SemanticException(e.getMessage());
     }
   }
 
+  public static void validate(TableSchema incomingSchema, TableSchema 
realSchema) {
+    final List<ColumnSchema> incomingSchemaColumns = 
incomingSchema.getColumns();
+    Map<String, ColumnSchema> realSchemaMap = new HashMap<>();
+    realSchema.getColumns().forEach(c -> realSchemaMap.put(c.getName(), c));
+
+    for (ColumnSchema incomingSchemaColumn : incomingSchemaColumns) {
+      final ColumnSchema realSchemaColumn = 
realSchemaMap.get(incomingSchemaColumn.getName());
+      validate(incomingSchemaColumn, realSchemaColumn);
+    }
+  }
+
+  public static void validate(ColumnSchema incoming, ColumnSchema real) {
+    if (real == null) {
+      throw new SemanticException("Column " + incoming.getName() + " does not 
exists or fails to be "
+          + "created");
+    }
+    if (!incoming.getType().equals(real.getType())) {
+      throw new SemanticException(String.format("Inconsistent data type of 
column %s: %s/%s",
+          incoming.getName(), incoming.getType(), real.getType()));
+    }
+    if (!incoming.getColumnCategory().equals(real.getColumnCategory())) {
+      throw new SemanticException(String.format("Inconsistent column category 
of column %s: %s/%s",
+          incoming.getName(), incoming.getColumnCategory(), 
real.getColumnCategory()));
+    }
+  }
+
   public static ISchemaTree validate(
       ISchemaFetcher schemaFetcher,
       List<PartialPath> devicePaths,
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
index ad7fbb62156..bac41d785a7 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
@@ -370,6 +370,7 @@ public class StatementAnalyzer {
               insertTabletStatement,
               () -> SchemaValidator.validate(metadata, insert, context),
               metadata::getOrCreateDataPartition,
+              AnalyzeUtils::computeTableDataPartitionParams,
               analysis,
               false);
       insert.setInnerTreeStatement(insertTabletStatement);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/InsertTablet.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/InsertTablet.java
index de0f00a73a9..007a2b8ff01 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/InsertTablet.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/InsertTablet.java
@@ -19,20 +19,14 @@
 
 package org.apache.iotdb.db.queryengine.plan.relational.sql.ast;
 
-import org.apache.iotdb.commons.schema.view.LogicalViewSchema;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
-import 
org.apache.iotdb.db.queryengine.common.schematree.IMeasurementSchemaInfo;
-import 
org.apache.iotdb.db.queryengine.plan.analyze.schema.ISchemaComputationWithAutoCreation;
 import 
org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
-
+import org.apache.iotdb.udf.api.type.Binary;
 import org.apache.tsfile.file.metadata.IDeviceID;
-import org.apache.tsfile.utils.Pair;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 
 public class InsertTablet extends WrappedInsertStatement {
 
@@ -50,66 +44,58 @@ public class InsertTablet extends WrappedInsertStatement {
     return ((InsertTabletStatement) super.getInnerTreeStatement());
   }
 
-  @Override
-  public List<ISchemaComputationWithAutoCreation> getSchemaValidationList() {
-    InsertTabletStatement insertTabletStatement = getInnerTreeStatement();
-    Map<IDeviceID, ISchemaComputationWithAutoCreation> map = new HashMap<>();
-    for (int i = 0; i < insertTabletStatement.getRowCount(); i++) {
-      map.computeIfAbsent(insertTabletStatement.getTableDeviceID(i), 
this::getSchemaComputation);
-    }
-    return new ArrayList<>(map.values());
-  }
-
   @Override
   public void updateAfterSchemaValidation(MPPQueryContext context) throws 
QueryProcessException {
     getInnerTreeStatement().updateAfterSchemaValidation(context);
   }
 
   @Override
-  public ISchemaComputationWithAutoCreation getSchemaComputation(IDeviceID 
deviceID) {
-    return new SchemaExecutions(deviceID);
+  public String getDatabase() {
+    return context.getSession().getDatabaseName().get();
   }
 
-  public class SchemaExecutions extends BasicSchemaExecutions {
-
-    public SchemaExecutions(IDeviceID deviceID) {
-      super(deviceID);
-    }
-
-    @Override
-    public void computeMeasurement(int index, IMeasurementSchemaInfo 
measurementSchemaInfo) {
-      getInnerTreeStatement().computeMeasurement(index, measurementSchemaInfo);
-    }
-
-    @Override
-    public boolean hasLogicalViewNeedProcess() {
-      return getInnerTreeStatement().hasLogicalViewNeedProcess();
-    }
-
-    @Override
-    public List<LogicalViewSchema> getLogicalViewSchemaList() {
-      return getInnerTreeStatement().getLogicalViewSchemaList();
-    }
+  @Override
+  public String getTableName() {
+    return getInnerTreeStatement().getDevicePath().getFullPath();
+  }
 
-    @Override
-    public List<Integer> getIndexListOfLogicalViewPaths() {
-      return getInnerTreeStatement().getIndexListOfLogicalViewPaths();
+  @Override
+  public List<Object[]> getDeviceIdList() {
+    List<Object[]> deviceIdList = new ArrayList<>();
+    final InsertTabletStatement insertTabletStatement = 
getInnerTreeStatement();
+    for (int i = 0; i < insertTabletStatement.getRowCount(); i++) {
+      IDeviceID deviceID = insertTabletStatement.getTableDeviceID(i);
+      Object[] deviceIdSegments = new Object[deviceID.segmentNum()];
+      for (int j = 0; j < deviceIdSegments.length; j++) {
+        deviceIdSegments[j] = deviceID.segment(j);
+      }
+      deviceIdList.add(deviceIdSegments);
     }
+    return deviceIdList;
+  }
 
-    @Override
-    public void recordRangeOfLogicalViewSchemaListNow() {
-      getInnerTreeStatement().recordRangeOfLogicalViewSchemaListNow();
+  @Override
+  public List<String> getAttributeColumnNameList() {
+    final InsertTabletStatement insertTabletStatement = 
getInnerTreeStatement();
+    List<String> result = new ArrayList<>();
+    for (int i = 0; i < insertTabletStatement.getColumnCategories().length; 
i++) {
+      if (insertTabletStatement.getColumnCategories()[i] == 
TsTableColumnCategory.ATTRIBUTE) {
+        result.add(insertTabletStatement.getMeasurements()[i]);
+      }
     }
+    return result;
+  }
 
-    @Override
-    public Pair<Integer, Integer> getRangeOfLogicalViewSchemaListRecorded() {
-      return getInnerTreeStatement().getRangeOfLogicalViewSchemaListRecorded();
+  @Override
+  public List<Object[]> getAttributeValueList() {
+    final InsertTabletStatement insertTabletStatement = 
getInnerTreeStatement();
+    List<Object[]> result = new ArrayList<>();
+    for (int i = 0; i < insertTabletStatement.getColumnCategories().length; 
i++) {
+      if (insertTabletStatement.getColumnCategories()[i] == 
TsTableColumnCategory.ATTRIBUTE) {
+        result.add(((Object[]) insertTabletStatement.getColumns()[i]));
+      }
     }
 
-    @Override
-    public void computeMeasurementOfView(
-        int index, IMeasurementSchemaInfo measurementSchemaInfo, boolean 
isAligned) {
-      getInnerTreeStatement().computeMeasurementOfView(index, 
measurementSchemaInfo, isAligned);
-    }
+    return result;
   }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/WrappedInsertStatement.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/WrappedInsertStatement.java
index 7d91727f571..6aa4568a6ff 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/WrappedInsertStatement.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/WrappedInsertStatement.java
@@ -3,6 +3,7 @@ package org.apache.iotdb.db.queryengine.plan.relational.sql.ast;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
 import org.apache.iotdb.db.queryengine.plan.relational.metadata.ColumnSchema;
+import 
org.apache.iotdb.db.queryengine.plan.relational.metadata.ITableDeviceSchemaValidation;
 import org.apache.iotdb.db.queryengine.plan.relational.metadata.TableSchema;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertBaseStatement;
 
@@ -11,7 +12,8 @@ import org.apache.tsfile.read.common.type.TypeFactory;
 import java.util.ArrayList;
 import java.util.List;
 
-public abstract class WrappedInsertStatement extends WrappedStatement {
+public abstract class WrappedInsertStatement extends WrappedStatement 
implements
+    ITableDeviceSchemaValidation {
 
   protected TableSchema tableSchema;
 
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertTabletStatement.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertTabletStatement.java
index fa9e8959c01..45b77109425 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertTabletStatement.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertTabletStatement.java
@@ -140,6 +140,10 @@ public class InsertTabletStatement extends 
InsertBaseStatement implements ISchem
     return result;
   }
 
+  public TTimePartitionSlot getTimePartitionSlot(int i) {
+    return TimePartitionUtils.getTimePartitionSlot(times[i]);
+  }
+
   @Override
   public <R, C> R accept(StatementVisitor<R, C> visitor, C context) {
     return visitor.visitInsertTablet(this, context);

Reply via email to